|
45 | 45 | RealtimeModelTurnEndedEvent,
|
46 | 46 | RealtimeModelTurnStartedEvent,
|
47 | 47 | )
|
| 48 | +from agents.realtime.model_inputs import RealtimeModelSendSessionUpdate |
48 | 49 | from agents.realtime.session import RealtimeSession
|
49 | 50 | from agents.tool import FunctionTool
|
50 | 51 | from agents.tool_context import ToolContext
|
@@ -1488,3 +1489,24 @@ async def mock_get_handoffs(cls, agent, context_wrapper):
|
1488 | 1489 | assert model_settings["voice"] == "model_config_only_voice"
|
1489 | 1490 | assert model_settings["tool_choice"] == "required"
|
1490 | 1491 | assert model_settings["output_audio_format"] == "g711_ulaw"
|
| 1492 | + |
| 1493 | + |
| 1494 | +class TestUpdateAgentFunctionality: |
| 1495 | + """Tests for update agent functionality in RealtimeSession""" |
| 1496 | + |
| 1497 | + @pytest.mark.asyncio |
| 1498 | + async def test_update_agent_creates_handoff_and_session_update_event(self, mock_model): |
| 1499 | + first_agent = RealtimeAgent(name="first", instructions="first", tools=[], handoffs=[]) |
| 1500 | + second_agent = RealtimeAgent(name="second", instructions="second", tools=[], handoffs=[]) |
| 1501 | + |
| 1502 | + session = RealtimeSession(mock_model, first_agent, None) |
| 1503 | + |
| 1504 | + await session.update_agent(second_agent) |
| 1505 | + |
| 1506 | + # Should have sent session update |
| 1507 | + session_update_event = mock_model.sent_events[0] |
| 1508 | + assert isinstance(session_update_event, RealtimeModelSendSessionUpdate) |
| 1509 | + assert session_update_event.session_settings["instructions"] == "second" |
| 1510 | + |
| 1511 | + # Check that the current agent and session settings are updated |
| 1512 | + assert session._current_agent == second_agent |
0 commit comments