Quick Start
#[tool] Macro
The#[tool] macro automatically:
- Generates tool schema from function signature
- Handles JSON serialization/deserialization
- Registers tool with the agent
Parameter Types
Supported types in tool functions:| Type | JSON Type | Example |
|---|---|---|
String | string | "hello" |
i32, i64 | integer | 42 |
f32, f64 | number | 3.14 |
bool | boolean | true |
Examples
Calculator Tool
Web Request Tool
File Tool
Manual Tool Implementation
For advanced control, implement theTool trait directly:
Best Practices
Clear descriptions
Clear descriptions
Write descriptions that help the LLM understand when to use the tool.
Handle errors gracefully
Handle errors gracefully
Return error messages as strings rather than panicking.
Keep tools focused
Keep tools focused
Each tool should do one thing well.

