macro_rules! tool {
($name:expr, $handler:expr $(,)?) => { ... };
($name:expr, description = $description:expr, $handler:expr $(,)?) => { ... };
}Expand description
Builds a typed local registration.
The macro is intentionally limited to typed-handler ergonomics. It does not generate dispatch, routing, or lifecycle code.
use tools_kit::{Toolset, ToolsetBackend, ToolHandlerBackend};
use tools_kit::declaration::ToolName;
use tools_kit::execution::{ToolHandlerInput, ToolHandlerOutput, ToolInvocation};
let registration = tools_kit::tool!("double", |value: i64| async move { Ok(value * 2) })?;
let tools = Toolset::local(vec![registration])?;
let result = async {
let mut handler = tools.tool_handler(ToolName::new("double")?).await?;
handler.step(ToolHandlerInput::Invoke(ToolInvocation {
call_id: None, arguments: serde_json::json!(3),
})).await
}.await;
let cleanup = tools.shutdown().await;
if let Err(error) = &cleanup {
eprintln!("Cleanup failed: {error}");
}
let ToolHandlerOutput::Completed(result) = result? else { panic!("completion expected") };
assert_eq!(result.structured_content, Some(serde_json::json!(6)));
cleanup?;