Documentation Index
Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt
Use this file to discover all available pages before exploring further.
@register_tool turns a Python function into a tool the agent can invoke. The SDK extracts type hints and the docstring to build a schema and description automatically: there’s no manual schema writing.
calculate_sum is available to every Agents().aget(...) call as a local tool with id "calculate_sum".
Decorator forms
| Parameter | Type | Default | Description |
|---|---|---|---|
add_to_graph | bool | False | When True, the tool is pushed into the agent’s execution graph (so the platform routes calls through it). When False, the tool is only available in-process. |
What it does
- Inspects the function’s parameters and type hints.
- Builds a Pydantic model (
<FunctionName>Args) from the parameters: required if no default, optional otherwise. - Constructs a
Toolwith:id= function namename= function namedescription= function docstringparameters= generated JSON schemafn= the functionis_local = Trueshould_add_to_graph = add_to_graph
- Registers the tool in
ToolsRepository’s class-level_local_toolslist (process-wide singleton). - Returns the original function unchanged:
calculate_sum(2, 3)still works as plain Python.
Examples
Async functions are supported
Optional parameters
Push to the agent graph
add_to_graph=True makes the tool visible in the platform’s graph view for the next agents.aget(...): the SDK sync runs in the background after aget returns.
Use the function directly
Visibility rules
The decorator registers tools at module-import time on a process-wide registry. That means:- Every agent loaded by
Agents().aget(...)in this process inherits the local tools. - Tools defined inside a function body register the first time the function runs, but stay registered for the rest of the process’s lifetime.
- If you
delor rename a function after decoration, the registeredToolkeeps its captured reference (thefnattribute): it doesn’t unregister itself.
Backend.aget_args(tools=[fn]) instead: that adds callables to one specific aget_args call without polluting the global registry.
Schema details
The generated schema uses Pydantic’smodel_json_schema(mode="serialization"). Parameter names, types, and defaults map directly:
Related
Toolclass: what the decorator creates.@on_tool_before/@on_tool_after/@on_tool_error: lifecycle hooks around any tool invocation.

