Skip to content

unregister_function leaves ghost schemas in LLMContext (manual registration) #3306

@omChauhanDev

Description

@omChauhanDev

pipecat version

0.0.98

Python version

3.12.3

Operating System

macOs

Issue description

I ran into a runtime error when trying to unregister a tool that I registered manually (using register_function + ToolsSchema).

It looks like unregister_function correctly removes the Python handler from the execution list, but it doesn't remove the JSON schema from the LLMContext. This leaves the LLM thinking the tool is still available. If the LLM tries to call it later in the conversation, Pipecat crashes (or errors out) because the handler is gone.

This is inconsistent with unregister_direct_function, which seems to clean up both the handler and the schema automatically.

Reproduction steps

  1. Register a function manually: llm.register_function("get_weather", weather_handler).
  2. Add the schema to the context: context = LLMContext(..., tools=[weather_schema]).
  3. Start the bot.
  4. In the middle of the flow, call llm.unregister_function("get_weather").
  5. Ask the bot a question that triggers that tool.

Expected behavior

I expected unregister_function to either:

  1. Automatically remove the schema from the context (like the direct method does).
  2. Or at least warn me that I need to manually clean up the schema myself.

Actual behavior

The function handler is removed silently. The LLM still sees the tool in its system prompt, attempts to call it, and the bot fails because no handler exists for "get_weather".

Logs

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions