Skip to content

Commit 39d2b04

Browse files
committed
fix: address duplicating session history issue mentioned by @chatgpt-codex-connector
1 parent 9a4d876 commit 39d2b04

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
@@ -1314,15 +1314,19 @@ async def _start_streaming(
13141314
streamed_result._event_queue.put_nowait(AgentUpdatedStreamEvent(new_agent=current_agent))
13151315

13161316
try:
1317-
# Prepare input with session if enabled
1318-
prepared_input = await AgentRunner._prepare_input_with_session(
1319-
starting_input, session, run_config.session_input_callback
1320-
)
1317+
# Prepare input with session if enabled (skip if resuming from state)
1318+
if run_state is None:
1319+
prepared_input = await AgentRunner._prepare_input_with_session(
1320+
starting_input, session, run_config.session_input_callback
1321+
)
13211322

1322-
# Update the streamed result with the prepared input
1323-
streamed_result.input = prepared_input
1323+
# Update the streamed result with the prepared input
1324+
streamed_result.input = prepared_input
13241325

1325-
await AgentRunner._save_result_to_session(session, starting_input, [])
1326+
await AgentRunner._save_result_to_session(session, starting_input, [])
1327+
else:
1328+
# When resuming, starting_input is already prepared from RunState
1329+
prepared_input = starting_input
13261330

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

0 commit comments

Comments
 (0)