Skip to main content

Tool

Derive Macro Tool 

Source
#[derive(Tool)]
{
    // Attributes available to this derive:
    #[tool]
}
Expand description

Derive macro for creating Tool implementations

§Example

#[derive(Tool)]
#[tool(name = "search", description = "Search the web")]
struct SearchTool {
    #[tool(param, required, description = "Search query")]
    query: String,

    #[tool(param, description = "Maximum results to return")]
    max_results: Option<u32>,
}

impl SearchTool {
    // You must implement this method
    async fn run(&self, query: String, max_results: Option<u32>) -> Result<serde_json::Value, String> {
        Ok(serde_json::json!({"results": []}))
    }
}