Quick Start
User Interaction Flow
Tool Trait
Define custom tools by implementing theTool trait:
Trait Methods
| Method | Signature | Description |
|---|---|---|
name() | fn name(&self) -> &str | Tool identifier |
description() | fn description(&self) -> &str | Human-readable description |
parameters_schema() | fn parameters_schema(&self) -> Value | JSON Schema for parameters |
execute(args) | async fn execute(&self, Value) -> Result<Value> | Run the tool |
definition() | fn definition(&self) -> ToolDefinition | Get LLM function definition |
ToolRegistry
Manages a collection of tools for an agent.Methods
| Method | Signature | Description |
|---|---|---|
new() | fn new() -> Self | Create empty registry |
register(tool) | fn register(&mut self, impl Tool + 'static) | Add a tool |
get(name) | fn get(&self, &str) -> Option<Arc<dyn Tool>> | Get tool by name |
has(name) | fn has(&self, &str) -> bool | Check if tool exists |
list() | fn list(&self) -> Vec<&str> | List all tool names |
definitions() | fn definitions(&self) -> Vec<ToolDefinition> | Get all definitions |
execute(name, args) | async fn execute(&self, &str, Value) -> Result<ToolResult> | Run tool |
len() | fn len(&self) -> usize | Number of tools |
ToolResult
Result returned from tool execution.Factory Methods
| Method | Signature | Description |
|---|---|---|
success(name, value) | fn success(impl Into<String>, Value) -> Self | Create success result |
failure(name, error) | fn failure(impl Into<String>, impl Into<String>) -> Self | Create error result |
ToolDefinition
Definition sent to LLM for function calling.Creating Tools
Using #[tool] Macro (Recommended)
Using FunctionTool
Implementing Tool Trait
Multiple Tools Example
Best Practices
Use descriptive tool names
Use descriptive tool names
Names should clearly indicate what the tool does:
web_search, calculate_tax, send_email.Write clear descriptions
Write clear descriptions
The LLM uses descriptions to decide when to call tools. Be specific and clear.
Handle errors gracefully
Handle errors gracefully
Return meaningful error messages that help the agent recover.
Keep tools focused
Keep tools focused
Each tool should do one thing well. Compose multiple tools for complex operations.

