Skip to main content

Crate lc_tools_derive

Crate lc_tools_derive 

Source
Expand description

Procedural macro for deriving BaseTool implementations from functions.

§Example

use lc_tools::{tool, BaseTool, Tool, ToolError};

#[tool(description = "Useful for arithmetic calculations")]
fn calculator(
    #[param(desc = "The mathematical expression to evaluate")]
    expression: String,
) -> Result<f64, ToolError> {
    expression
        .parse::<f64>()
        .map_err(|e| ToolError::ExecutionFailed(e.to_string()))
}

This expands to:

  • CalculatorTool struct
  • CalculatorInput struct with Deserialize + JsonSchema
  • impl BaseTool for CalculatorTool
  • impl Tool for CalculatorTool
  • The original calculator function is preserved

Attribute Macros§

tool
The #[tool] procedural macro.