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
LLMWorkersubclasses, decorated methods are automatically registered with the LLM viaregister_direct_functionand included inbuild_tools().This is the worker-flavored variant of
@tool_options: it attaches the samecancel_on_interruption/timeout_secscall 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
LLMWorkertools.timeout_secs – Optional timeout in seconds for this tool call. Defaults to None (uses the LLM service default). Only applies to
LLMWorkertools.timeout –
Deprecated alias for
timeout_secs.Deprecated since version 1.4.0: Use
timeout_secsinstead. Will be removed in 2.0.0.