AgentsLiveWire

function_tool

View as MarkdownOpen in Claude

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
Optional[Callable]Defaults to None

The function to decorate. When @function_tool is used without parentheses, the decorated function is passed here directly.

name
Optional[str]Defaults to None

Override the tool name. Defaults to the function’s __name__.

description
Optional[str]Defaults to None

Override the tool description. Defaults to the function’s docstring.

Returns

Callable — The original function with metadata attributes attached:

  • _livewire_tool (bool) — Always True.
  • _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:

Python typeJSON Schema type
str"string"
int"integer"
float"number"
bool"boolean"
(other / missing)"string"

Parameters without a default value are marked as required in the schema.

Examples

1from signalwire.livewire import function_tool
2
3@function_tool
4def get_weather(city: str) -> str:
5 """Get the current weather for a city."""
6 return f"Sunny in {city}."