Expand description
§neuron-tool-macros
Procedural macro crate for the neuron tool system. Provides the #[neuron_tool]
attribute macro that generates a full Tool trait implementation from an
annotated async function, eliminating boilerplate for tool definitions.
§Installation
cargo add neuron-tool-macrosOr use it through neuron-tool with the macros feature (enabled by default).
§What It Generates
Given an async function, the macro generates:
- An
Argsstruct (e.g.,CalculateArgs) withDeserializeandJsonSchemaderives - A zero-sized
Toolstruct (e.g.,CalculateTool) - A
Tooltrait implementation with the function body ascall() - A
ToolDefinitionwith the JSON Schema derived from the args struct viaschemars
Field doc comments (///) on function parameters are preserved as schema descriptions.
§Key Attributes
name(required) – the tool name string used in LLM tool callsdescription(required) – human-readable description of what the tool does
§Usage
use neuron_tool_macros::neuron_tool;
use neuron_types::ToolContext;
#[neuron_tool(name = "calculate", description = "Evaluate a math expression")]
async fn calculate(
/// A mathematical expression like "2 + 2"
expression: String,
_ctx: &ToolContext,
) -> Result<CalculateOutput, CalculateError> {
let result = eval(&expression)?;
Ok(CalculateOutput { result })
}
// The macro generates:
// - `CalculateArgs { expression: String }` with Deserialize + JsonSchema
// - `CalculateTool` (zero-sized struct)
// - `impl Tool for CalculateTool` with NAME = "calculate"
//
// Register the generated tool:
// registry.register(CalculateTool);The last parameter must be &ToolContext (or _ctx: &ToolContext if unused).
All preceding parameters become fields on the generated args struct. The return
type must be Result<Output, Error> where both types are concrete.
The struct names are derived from the function name converted to PascalCase:
calculate produces CalculateTool and CalculateArgs, read_file produces
ReadFileTool and ReadFileArgs.
This macro is re-exported from neuron-tool when the macros feature is
enabled: neuron_tool::neuron_tool.
§Part of neuron
This crate is part of neuron, a composable building-blocks library for AI agents in Rust.
§License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Attribute Macros§
- neuron_
tool - Derive a Tool implementation from an async function.