llm-tool-macros
Proc-macro crate for llm-tool.
Provides the #[llm_tool] attribute macro that transforms a plain Rust function
into a strongly-typed
RustTool
implementation. You don't need to depend on this crate directly — use
llm_tool::llm_tool instead.
What the macro generates
Given a function like:
/// Adds two numbers together.
The macro produces:
-
AddParams— a struct derivingDeserializeandJsonSchemawith fieldsa: i64andb: i64. Doc comments on parameters become#[schemars(description = "...")]attributes, so they appear in the JSON Schema sent to the model. -
Add— a unit struct implementingRustTool<Params = AddParams>.NAME="add"(the original function name, snake_case).DESCRIPTION="Adds two numbers together."(from the function's doc comment).call()contains the original function body.
Rules
| Requirement | Detail |
|---|---|
| Doc comment on function | Required — becomes the tool description. |
| Doc comment on every parameter | Required — becomes the JSON Schema field description. |
| Return type | Result<T, E> or bare T (infallible). |
T (Ok type) |
String (auto-wrapped into ToolOutput), ToolOutput (passed through), any T: Serialize (auto-serialized to JSON), or Json<T>. |
E (Err type) |
Any E: Into<ToolError> — built-in for ToolError, String, std::io::Error, serde_json::Error, Box<dyn Error + Send + Sync>. |
async fn |
Supported — the generated call() is always async. |
&str params |
Accepted — the struct stores String, macro auto-borrows. |
Option<T> params |
Auto-annotated with #[serde(default)] → not in required. |
&ToolContext param |
Recognized as execution context, forwarded from registry, excluded from params struct. |
self receiver |
Not allowed — must be a free function. |
License
Dual-licensed under Apache-2.0 OR MIT.