tool

Attribute Macro tool 

Source
#[tool]
Expand description

The #[tool] attribute macro for easy tool definition

§Usage on Functions

#[tool(description = "Adds two numbers")]
fn add_numbers(params: AddParams) -> Result<AddResult, Error> {
    Ok(AddResult { sum: params.a + params.b })
}

§Usage on Structs

#[tool(
    name = "calculator",
    description = "Performs arithmetic operations"
)]
struct Calculator;

impl Calculator {
    fn execute(&self, params: CalcParams) -> Result<Value, Error> {
        // implementation
    }
}

This automatically:

  • Generates Tool trait implementation
  • Uses SchemaBasedTool for automatic schema generation
  • Handles type conversions
  • Provides error handling