| Crates.io | derive_agent_tools |
| lib.rs | derive_agent_tools |
| version | 0.1.0 |
| created_at | 2025-09-17 12:21:24.24192+00 |
| updated_at | 2025-09-17 12:21:24.24192+00 |
| description | Derive macros for defining AI tools from structs. |
| homepage | |
| repository | https://github.com/ron-leizrowice/derive-agent-tools |
| max_upload_size | |
| id | 1843192 |
| size | 60,146 |
Derive macros to define AI tools and their parameters directly from Rust structs.
ToolSpecification, a JSON schema helper, and an implementation to parse Bedrock tool inputs into your struct.Status: Bedrock-only today. Additional tool formats will be added over time.
Writing Bedrock tool schemas by hand is repetitive and error‑prone. derive_agent_tools lets you define a tool once as a Rust type and get:
ToolSpecificationTryFrom<&aws_smithy_types::Document> impl to parse tool inputs into your structAdd to your Cargo.toml:
[dependencies]
derive_agent_tools = "0.1"
serde = { version = "1", features = ["derive"] }
derive_agent_tools exposes two optional capabilities controlled by feature
flags. Both of them are enabled by default.
serde-json – builds JSON Schema helpers and requires serde/serde_json
at runtime.bedrock – generates AWS Bedrock ToolSpecification builders and pulls in
the AWS SDK dependencies.If you want to opt out of the AWS SDK dependencies, disable default features and pick the subset you need:
[dependencies]
derive_agent_tools = { version = "0.1", default-features = false, features = ["serde-json"] }
serde = { version = "1", features = ["derive"] }
With this configuration the crate still derives tools and the JSON schema
helpers compile, but Bedrock-specific functions such as
AgentTool::tool_spec() are not generated.
use derive_agent_tools::AgentTool;
use serde::Deserialize;
#[derive(AgentTool, Deserialize)]
#[tool(description = "A tool to get the weather")]
struct WeatherTool {
#[tool(required, description = "The latitude of the location")]
latitude: f64,
#[tool(required, description = "The longitude of the location")]
longitude: f64,
}
// Register tool with Bedrock
#[cfg(feature = "bedrock")]
let spec = WeatherTool::tool_spec();
// Inspect schema if desired
#[cfg(feature = "serde-json")]
let schema = WeatherTool::tool_schema_json();
// If your Agent returns a ToolUse input Document, you can parse it:
// let args: WeatherTool = (&document).try_into()?;
#[tool(...)]:
name = "..." override the tool name (defaults to struct name)description = "..." human-friendly description#[tool(...)]:
required mark a field as required (otherwise it is optional in the schema)description = "..." field descriptionBasic Rust types map to JSON Schema as follows:
bool -> booleanintegerf32, f64 -> numberString, &str -> stringVec<T> -> array (best-effort items type)Option<T> -> uses T's type but is not marked as requiredobjectThis mapping is intentionally minimal and conservative. It will be expanded over time.
tool_spec() builds an aws_sdk_bedrockruntime::types::ToolSpecification using a JSON schema generated from your struct and annotations. Only Bedrock is supported at present. The crate is structured to support additional providers in the future through feature flags and provider-specific builders.
TryFrom<&Document> implementation fails to deserialize the payload, the error message is captured in a lightweight, per-type error struct.