|
6 | 6 | from openai.types.realtime.realtime_session_create_request import ( |
7 | 7 | RealtimeSessionCreateRequest, |
8 | 8 | ) |
| 9 | +from openai.types.realtime.session_update_event import SessionUpdateEvent |
9 | 10 |
|
10 | 11 | from agents.handoffs import Handoff |
11 | 12 | from agents.realtime.agent import RealtimeAgent |
|
14 | 15 | from agents.realtime.model import RealtimeModelConfig |
15 | 16 | from agents.realtime.openai_realtime import ( |
16 | 17 | OpenAIRealtimeSIPModel, |
| 18 | + OpenAIRealtimeWebSocketModel, |
17 | 19 | _build_model_settings_from_agent, |
18 | 20 | _collect_enabled_handoffs, |
19 | 21 | ) |
@@ -129,3 +131,36 @@ def ping() -> str: |
129 | 131 | tool_names.add(name) |
130 | 132 | assert ping.name in tool_names |
131 | 133 | assert f"transfer_to_{child_agent.name}" in tool_names |
| 134 | + |
| 135 | + |
| 136 | +def test_call_id_session_update_omits_null_audio_formats() -> None: |
| 137 | + model = OpenAIRealtimeWebSocketModel() |
| 138 | + model._call_id = "call_123" |
| 139 | + |
| 140 | + session_config = model._get_session_config({}) |
| 141 | + payload = SessionUpdateEvent(type="session.update", session=session_config).model_dump( |
| 142 | + exclude_unset=True |
| 143 | + ) |
| 144 | + |
| 145 | + audio = payload["session"]["audio"] |
| 146 | + assert "format" not in audio["input"] |
| 147 | + assert "format" not in audio["output"] |
| 148 | + |
| 149 | + |
| 150 | +def test_call_id_session_update_includes_explicit_audio_formats() -> None: |
| 151 | + model = OpenAIRealtimeWebSocketModel() |
| 152 | + model._call_id = "call_123" |
| 153 | + |
| 154 | + session_config = model._get_session_config( |
| 155 | + { |
| 156 | + "input_audio_format": "g711_ulaw", |
| 157 | + "output_audio_format": "g711_ulaw", |
| 158 | + } |
| 159 | + ) |
| 160 | + payload = SessionUpdateEvent(type="session.update", session=session_config).model_dump( |
| 161 | + exclude_unset=True |
| 162 | + ) |
| 163 | + |
| 164 | + audio = payload["session"]["audio"] |
| 165 | + assert audio["input"]["format"]["type"] == "audio/pcmu" |
| 166 | + assert audio["output"]["format"]["type"] == "audio/pcmu" |
0 commit comments