diff --git a/src/pipecat/services/llm_service.py b/src/pipecat/services/llm_service.py index fc4c6ce89..1f98c1603 100644 --- a/src/pipecat/services/llm_service.py +++ b/src/pipecat/services/llm_service.py @@ -792,7 +792,7 @@ class LLMService(UserTurnCompletionLLMServiceMixin, AIService): item = self._functions[runner_item.function_name] elif None in self._functions.keys(): item = self._functions[None] - elif runner_item.registry_item.handler is self._missing_function_call_handler: + elif runner_item.registry_item.handler == self._missing_function_call_handler: item = runner_item.registry_item else: logger.warning( diff --git a/tests/test_llm_service.py b/tests/test_llm_service.py index 057fafb1e..c7018d9f0 100644 --- a/tests/test_llm_service.py +++ b/tests/test_llm_service.py @@ -5,7 +5,7 @@ # import unittest -from unittest.mock import AsyncMock +from unittest.mock import AsyncMock, patch from pipecat.frames.frames import ( FunctionCallFromLLM, @@ -60,16 +60,17 @@ class TestLLMService(unittest.IsolatedAsyncioTestCase): service.broadcast_frame = mock_broadcast_frame - await service.run_function_calls( - [ - FunctionCallFromLLM( - function_name="missing_tool", - tool_call_id="call_1", - arguments={"query": "weather"}, - context=LLMContext(), - ) - ] - ) + with patch("pipecat.services.llm_service.logger") as mock_logger: + await service.run_function_calls( + [ + FunctionCallFromLLM( + function_name="missing_tool", + tool_call_id="call_1", + arguments={"query": "weather"}, + context=LLMContext(), + ) + ] + ) self.assertEqual( [type(frame) for frame in recorded_frames], @@ -85,6 +86,12 @@ class TestLLMService(unittest.IsolatedAsyncioTestCase): "Error: function 'missing_tool' is not registered.", ) + # Only the queue-time warning should fire; the execution-time + # "just unregistered" warning must not double-log. + warnings = [c.args[0] for c in mock_logger.warning.call_args_list] + self.assertTrue(any("not registered" in w for w in warnings)) + self.assertFalse(any("just unregistered" in w for w in warnings)) + async def test_function_unregistered_between_queue_and_execute(self): """Function unregistered between queuing and execution still terminates.""" service = MockLLMService()