Tool System API

Tool System API

API reference for the tool system in LeafMesh.

Registering Custom Tools

@global_tool Decorator

The way to register a custom tool that agents can use:

from leafmesh.tools import global_tool @global_tool( name="lookup_account", description="Look up account details by ID", category="database" ) async def lookup_account(account_id: str) -> dict: return {"tier": "enterprise", "status": "active"}

The function remains callable as normal Python and is automatically available to any agent that lists it in their YAML tools array.

Decorator Parameters

ParameterTypeDescription
namestrTool name (used in YAML tools array)
descriptionstrDescription shown to the LLM for tool selection
categorystrTool category for tool_categories YAML config

Built-in Tools (12 tools)

ToolCategoryDescription
calculatormathSafe AST-based math evaluation
random_numbermathRandom number generation (max 1000)
current_timetimeCurrent date/time in any timezone
time_differencetimeCalculate time between timestamps
text_analyzertextText statistics (words, sentences, etc.)
text_formattertextFormat text (uppercase, title, wrap, etc.)
web_requestwebHTTP requests (GET/POST/PUT/DELETE), SSRF-protected
json_formatterdataFormat and validate JSON
data_converterdataConvert between data formats
chain_of_thoughtreasoningStep-by-step reasoning framework
metacognitive_reflectionreasoningEvaluate reasoning quality
system_infosystemPlatform and system information

Agent Tool Configuration

Grant tools to agents in your YAML configuration:

agents: my_agent: name: "my_agent" tools: ["calculator", "web_request", "lookup_account"] tool_choice: "auto" # "auto" | "none" | specific tool name max_tool_calls_per_message: 5 # Range: 0-20 tool_call_timeout: 30.0 # Range: 0.1-300 seconds allow_parallel_tool_calls: true # Default: true tool_categories: ["math", "web"] # Grant all tools in a category

Tool Choice Modes

ModeBehavior
"auto"LLM decides whether to call tools
"none"Tool calling disabled
"tool_name"Force a specific tool

Permission Enforcement

Tools are only available to agents that declare them in their YAML tools array or tool_categories. If an LLM generates a call for an unauthorized tool, the call is rejected before any tool code runs.

Next Steps


LeafMesh — Tool system API reference

Last updated: 11/10/2026