Skip to content

Realtime: send session update before tool response #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/agents/realtime/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,20 @@ async def _handle_tool_call(self, event: RealtimeModelToolCallEvent) -> None:
)
)

# Send tool output to complete the handoff
# First, send the session update so the model receives the new instructions
await self._model.send_event(
RealtimeModelSendSessionUpdate(session_settings=updated_settings)
)

# Then send tool output to complete the handoff (this triggers a new response)
transfer_message = handoff.get_transfer_message(result)
await self._model.send_event(
RealtimeModelSendToolOutput(
tool_call=event,
output=f"Handed off to {self._current_agent.name}",
output=transfer_message,
start_response=True,
)
)

# Send session update to model
await self._model.send_event(
RealtimeModelSendSessionUpdate(session_settings=updated_settings)
)
else:
raise ModelBehaviorError(f"Tool {event.name} not found")

Expand Down