Skip to content

Commit 5a5de00

Browse files
committed
fix: save conversation to session before handoff for non-streaming path
1 parent db68d1c commit 5a5de00

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/agents/run.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,15 @@ async def run(
715715

716716
return result
717717
elif isinstance(turn_result.next_step, NextStepHandoff):
718+
# Save the conversation to session if enabled (before handoff)
719+
if session is not None:
720+
if not any(
721+
guardrail_result.output.tripwire_triggered
722+
for guardrail_result in input_guardrail_results
723+
):
724+
await self._save_result_to_session(
725+
session, [], turn_result.new_step_items
726+
)
718727
current_agent = cast(Agent[TContext], turn_result.next_step.new_agent)
719728
current_span.finish(reset_current=True)
720729
current_span = None
@@ -1166,8 +1175,7 @@ async def _start_streaming(
11661175

11671176
if isinstance(turn_result.next_step, NextStepHandoff):
11681177
# Save the conversation to session if enabled (before handoff)
1169-
# Note: Non-streaming path doesn't save handoff turns immediately,
1170-
# but streaming needs to for graceful cancellation support
1178+
# Streaming needs to save for graceful cancellation support
11711179
if session is not None:
11721180
should_skip_session_save = (
11731181
await AgentRunner._input_guardrail_tripwire_triggered_for_stream(

0 commit comments

Comments
 (0)