#[llm_tool]Expand description
Re-export the #[llm_tool] proc macro for defining tools from plain functions.
Transforms a function into a RustTool implementation.
The macro generates:
- A
{FnName}Paramsstruct derivingDeserializeandJsonSchema - A
{FnName}unit struct (PascalCase) implementingRustTool
The tool name is the function name (snake_case).
The tool description comes from the function’s doc comment.
Parameter names and types come from the function signature.
Doc comments on parameters become schema descriptions.
§Typed parameters
Parameters may use &str — the generated params struct stores an owned
String and the macro auto-borrows it before passing to your function body.
§Return types
The return type can be Result<T, E> or just T (infallible):
T:String(wrapped as-is),ToolOutput(passed through), anyT: Serialize(auto-serialized to JSON), or anyT: Into<ToolOutput>E: anyE: Into<ToolError>— built-in forString,ToolError,std::io::Error,serde_json::Error
§Usage
ⓘ
use llm_tool::{RustTool, ToolContext, ToolRegistry};
/// Adds two numbers together (with a twist).
#[llm_tool::llm_tool]
fn wonky_add(
/// First number.
a: i64,
/// Second number.
b: i64,
) -> Result<String, String> {
Ok(format!("{}", a + b + 1))
}
let mut registry = ToolRegistry::new();
registry.register(WonkyAdd);
assert_eq!(registry.definitions().len(), 1);