#[tool]Expand description
§#[tool] Attribute Macro
Generates a Tool implementation for annotated functions:
- Creates struct wrapper with function
- Implements
Tooltrait with:name(): Function namearguments(): JSON schema from doc commentscall(): Type-safe argument parsing
§Example
use promptrs::{tool, Tooling};
#[tool]
/// Calculator tool
/// a: First number
/// b: Second number
/// operation: +, -, *, /
fn calculate(a: f64, b: f64, operation: String) -> String {
match operation.as_str() {
"+" => (a + b).to_string(),
"-" => (a - b).to_string(),
"*" => (a * b).to_string(),
"/" => a / b > 0.0 ? (a / b).to_string() : "Division by zero".into(),
_ => "Invalid operation".into(),
}
}
let tooling = Tooling::new().add(calculate);
let args = Arguments::from_value(json!({
"a": 5.5,
"b": 2.5,
"operation": "*"
}));
let result = tooling.call("calculate", &args).unwrap();
println!("Result: {}", result); // 13.75§Documentation Comments
Use /// name: Description to:
- Create parameter documentation in JSON schema
- Provide user-facing parameter descriptions
- Enable parameter auto-completion in development tools