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
LLMWorkersubclasses, decorated methods are automatically registered with the LLM viaregister_direct_functionand included inbuild_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
LLMWorkertools.timeout – Optional timeout in seconds for this tool call. Defaults to None (uses the LLM service default).