tool_decorator

Decorator for marking methods as LLM tools.

pipecat.workers.llm.tool_decorator.tool(fn=None, *, cancel_on_interruption=True, timeout_secs=None, 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().

This is the worker-flavored variant of @tool_options: it attaches the same cancel_on_interruption / timeout_secs call options and additionally marks the method (with _pipecat_is_llm_tool) so the worker collects it from the MRO.

Can be used with or without arguments:

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

@tool(cancel_on_interruption=False, timeout_secs=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_secs – Optional timeout in seconds for this tool call. Defaults to None (uses the LLM service default). Only applies to LLMWorker tools.

  • timeout

    Deprecated alias for timeout_secs.

    Deprecated since version 1.4.0: Use timeout_secs instead. Will be removed in 2.0.0.