Expand description
Procedural macros for claude-api.
Re-exported from the parent crate behind the derive feature; users
should write claude_api::derive::Tool, not depend on this crate
directly.
§#[derive(Tool)]
Derive an implementation of claude_api::tool_dispatch::Tool for a
struct that already implements serde::Deserialize and
schemars::JsonSchema. The struct’s fields define the tool input;
the user supplies the behavior via an inherent async fn run(self).
ⓘ
use claude_api::derive::Tool;
use claude_api::tool_dispatch::ToolError;
use serde::Deserialize;
use schemars::JsonSchema;
/// Get the current weather for a city.
#[derive(Deserialize, JsonSchema, Tool)]
struct GetWeather {
/// City to look up.
city: String,
}
impl GetWeather {
async fn run(self) -> Result<serde_json::Value, ToolError> {
Ok(serde_json::json!({"temp": 72, "city": self.city}))
}
}
// Use:
let tool = GetWeather::tool();§Attribute syntax
#[tool(name = "...")]– override the tool name. Default:snake_caseof the type name.#[tool(description = "...")]– override the description. Default: the first line of the struct’s doc comment.
Derive Macros§
- Tool
- Derive
claude_api::tool_dispatch::Toolfor a struct.