Skip to content

Commit 4f1fc71

Browse files
committed
fix: address duplicating session history issue mentioned by @chatgpt-codex-connector
1 parent b64aabd commit 4f1fc71

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/agents/run.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,15 +1399,19 @@ async def _start_streaming(
13991399
streamed_result._event_queue.put_nowait(AgentUpdatedStreamEvent(new_agent=current_agent))
14001400

14011401
try:
1402-
# Prepare input with session if enabled
1403-
prepared_input = await AgentRunner._prepare_input_with_session(
1404-
starting_input, session, run_config.session_input_callback
1405-
)
1402+
# Prepare input with session if enabled (skip if resuming from state)
1403+
if run_state is None:
1404+
prepared_input = await AgentRunner._prepare_input_with_session(
1405+
starting_input, session, run_config.session_input_callback
1406+
)
14061407

1407-
# Update the streamed result with the prepared input
1408-
streamed_result.input = prepared_input
1408+
# Update the streamed result with the prepared input
1409+
streamed_result.input = prepared_input
14091410

1410-
await AgentRunner._save_result_to_session(session, starting_input, [])
1411+
await AgentRunner._save_result_to_session(session, starting_input, [])
1412+
else:
1413+
# When resuming, starting_input is already prepared from RunState
1414+
prepared_input = starting_input
14111415

14121416
# If resuming from an interrupted state, execute approved tools first
14131417
if run_state is not None and run_state._current_step is not None:

0 commit comments

Comments
 (0)