function_tool
function_tool
function_tool
function_tool(func=None, name=None, description=None) -> Callable
Wraps a plain Python function so it can be passed into
Agent(tools=[...]). The decorator
extracts parameter information from type hints and builds a JSON-Schema-style
parameter dict. The function’s docstring is used as the tool description unless
description is provided explicitly.
When the underlying SignalWire agent is built, each decorated function is registered
as a SWAIG function via
define_tool().
Parameters annotated with RunContext
are automatically excluded from the generated JSON schema and injected at call time.
Parameters
func
The function to decorate. When @function_tool is used without parentheses, the
decorated function is passed here directly.
name
Override the tool name. Defaults to the function’s __name__.
description
Override the tool description. Defaults to the function’s docstring.
Returns
Callable — The original function with metadata attributes attached:
_livewire_tool(bool) — AlwaysTrue._tool_name(str) — The resolved tool name._tool_description(str) — The resolved description._tool_parameters(dict) — JSON-Schema-style parameter definition._tool_handler(Callable) — Reference to the original function.
Type Mapping
The decorator maps Python type annotations to JSON Schema types:
Parameters without a default value are marked as required in the schema.