Skip to content

Commit 932407d

Browse files
committed
Realtime: send session update before tool response
1 parent bc71e8b commit 932407d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/agents/realtime/session.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,20 @@ async def _handle_tool_call(self, event: RealtimeModelToolCallEvent) -> None:
374374
)
375375
)
376376

377-
# Send tool output to complete the handoff
377+
# First, send the session update so the model receives the new instructions
378+
await self._model.send_event(
379+
RealtimeModelSendSessionUpdate(session_settings=updated_settings)
380+
)
381+
382+
# Then send tool output to complete the handoff (this triggers a new response)
383+
transfer_message = handoff.get_transfer_message(result)
378384
await self._model.send_event(
379385
RealtimeModelSendToolOutput(
380386
tool_call=event,
381-
output=f"Handed off to {self._current_agent.name}",
387+
output=transfer_message,
382388
start_response=True,
383389
)
384390
)
385-
386-
# Send session update to model
387-
await self._model.send_event(
388-
RealtimeModelSendSessionUpdate(session_settings=updated_settings)
389-
)
390391
else:
391392
raise ModelBehaviorError(f"Tool {event.name} not found")
392393

0 commit comments

Comments
 (0)