tool_decorator

Decorator for marking methods as LLM tools.

pipecat.workers.llm.tool_decorator.tool(fn=None, *, cancel_on_interruption=True, timeout=None)[source]

Mark a method as a tool.

On LLMWorker subclasses, decorated methods are automatically registered with the LLM via register_direct_function and included in build_tools().

Can be used with or without arguments:

@tool
async def my_tool(self, params, arg: str):
    ...

@tool(cancel_on_interruption=False, timeout=60)
async def my_tool(self, params, arg: str):
    ...
Parameters:
  • fn – The function to decorate (when used without arguments).

  • cancel_on_interruption – Whether to cancel this tool call when an interruption occurs. Defaults to True. Only applies to LLMWorker tools.

  • timeout – Optional timeout in seconds for this tool call. Defaults to None (uses the LLM service default).