Skip to content

Commit ff03a4d

Browse files
committed
fix(realtime): preserve transport audio formats during agent handoff
During agent handoff in _handle_tool_call, _get_updated_model_settings_from_agent was called with starting_settings=None, causing session.update to reset input_audio_format and output_audio_format back to pcm16 defaults. This overwrote transport-configured audio formats (e.g. g711_ulaw for Twilio), closing the Twilio session and sending noise over the phone. Fix: pass starting_settings=self._model_config.get("initial_model_settings", None) to mirror the behaviour of __aenter__, which correctly preserves audio formats on initial connect. Fixes #1632
1 parent da82b2c commit ff03a4d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/agents/realtime/session.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,11 @@ async def _handle_tool_call(
693693
# Update current agent
694694
self._current_agent = result
695695

696-
# Get updated model settings from new agent
696+
# Get updated model settings from new agent, preserving transport-configured
697+
# settings (e.g. audio format) from initial_model_settings so they are not
698+
# reset to defaults during the handoff session update.
697699
updated_settings = await self._get_updated_model_settings_from_agent(
698-
starting_settings=None,
700+
starting_settings=self._model_config.get("initial_model_settings", None),
699701
agent=self._current_agent,
700702
)
701703

0 commit comments

Comments
 (0)