claude_api/tool_dispatch/mod.rs
1//! Tool-dispatch: the [`Tool`] trait, registry, typed inputs, and the agent
2//! loop runner.
3//!
4//! Three ergonomic shapes for registering tools:
5//!
6//! 1. **[`Tool`] trait** -- implement directly when each tool is its own type.
7//! Gives full control over the JSON Schema, the async handler, and errors.
8//! 2. **[`ToolRegistry::register`]** -- closure-based handler. The registry
9//! wraps closures in an internal `FnTool<F>` adapter. Convenient for
10//! one-off tools that don't need a dedicated type.
11//! 3. **[`TypedTool`] + `ToolRegistry::register_typed`** -- typed-input
12//! handler driven by `schemars`. The input JSON is deserialized into a
13//! concrete `Args` type before dispatch. Behind the `schemars-tools`
14//! feature (or use `#[derive(Tool)]` from `claude-api-derive` for the
15//! most ergonomic form).
16//!
17//! The agent loop lives in [`runner`] (feature `conversation`). It drives
18//! repeated `messages.create` calls, dispatching tools in parallel via
19//! [`Tool::invoke`], optionally enforcing a cost budget and a mid-stream
20//! approval gate.
21//!
22//! Gated on the `async` feature.
23
24pub mod registry;
25pub mod tool;
26
27#[cfg(feature = "conversation")]
28#[cfg_attr(docsrs, doc(cfg(feature = "conversation")))]
29pub mod runner;
30
31#[cfg(feature = "schemars-tools")]
32#[cfg_attr(docsrs, doc(cfg(feature = "schemars-tools")))]
33pub mod typed;
34
35pub use registry::{FnTool, ToolRegistry};
36pub use tool::{ApprovalDecision, Tool, ToolApprover, ToolError, fn_approver};
37
38#[cfg(feature = "conversation")]
39pub use runner::RunOptions;
40
41#[cfg(feature = "schemars-tools")]
42pub use typed::TypedTool;