pipecat icon indicating copy to clipboard operation
pipecat copied to clipboard

KeyError in LLMService.unregister_function for functions without a start_callback

Open larry-cmz opened this issue 1 month ago • 0 comments

pipecat version

0.0.90

Python version

3.12.9

Operating System

macos 15.6.1

Issue description

When calling LLMService.unregister_function, it will properly remove the function_name from _functions. It will then check if the function is registered in _start_callbacks which throws a KeyError if the function_name is not in the dictionary.

If the key isn't in _functions, that would also throw a KeyError.

Reproduction steps

  1. Call LLMService.register_function to register a function. Do not provide an argument for start_callback.
  2. Call LLMService.unregister_function with that function's name.

Expected behavior

I would expect unregister_function to function without error if my function name is registered as a function but is not registered as a start_callback.

If my function was not registered in the first place, I might expect this to also function without error. This case is more reasonable to throw a KeyError, though I might still expect it be ignored as a no-op. That is more of a style choice.

Actual behavior

A KeyError is thrown from unregister_function.

Logs

.venv/lib/python3.12/site-packages/pipecat/services/llm_service.py", line 395, in unregister_function
    if self._start_callbacks[function_name]:
       ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: MyFunctionName

larry-cmz avatar Oct 31 '25 01:10 larry-cmz