@@ -1067,11 +1067,7 @@ async def test_handoff_tool_handling(self, mock_model):
10671067
10681068 @pytest .mark .asyncio
10691069 async def test_unknown_tool_handling (self , mock_model , mock_agent , mock_function_tool ):
1070- """Test that unknown tools raise an error"""
1071- import pytest
1072-
1073- from agents .exceptions import ModelBehaviorError
1074-
1070+ """Test that unknown tools emit a RealtimeError event"""
10751071 # Set up agent to return different tool than what's called
10761072 mock_function_tool .name = "known_tool"
10771073 mock_agent .get_all_tools .return_value = [mock_function_tool ]
@@ -1083,9 +1079,14 @@ async def test_unknown_tool_handling(self, mock_model, mock_agent, mock_function
10831079 name = "unknown_tool" , call_id = "call_unknown" , arguments = "{}"
10841080 )
10851081
1086- # Should raise an error for unknown tool
1087- with pytest .raises (ModelBehaviorError , match = "Tool unknown_tool not found" ):
1088- await session ._handle_tool_call (tool_call_event )
1082+ # Should emit a RealtimeError event for unknown tool
1083+ await session ._handle_tool_call (tool_call_event )
1084+
1085+ # Should have emitted a RealtimeError event
1086+ assert session ._event_queue .qsize () >= 1
1087+ error_event = await session ._event_queue .get ()
1088+ assert isinstance (error_event , RealtimeError )
1089+ assert "Tool unknown_tool not found" in error_event .error .get ("message" , "" )
10891090
10901091 # Should not have called any tools
10911092 mock_function_tool .on_invoke_tool .assert_not_called ()
0 commit comments