Skip to main content

Module tool_dispatch

Module tool_dispatch 

Source
Available on crate feature async only.
Expand description

Tool-dispatch: the Tool trait, registry, typed inputs, and the agent loop runner.

Three ergonomic shapes for registering tools:

  1. Tool trait – implement directly when each tool is its own type. Gives full control over the JSON Schema, the async handler, and errors.
  2. ToolRegistry::register – closure-based handler. The registry wraps closures in an internal FnTool<F> adapter. Convenient for one-off tools that don’t need a dedicated type.
  3. TypedTool + ToolRegistry::register_typed – typed-input handler driven by schemars. The input JSON is deserialized into a concrete Args type before dispatch. Behind the schemars-tools feature (or use #[derive(Tool)] from claude-api-derive for the most ergonomic form).

The agent loop lives in runner (feature conversation). It drives repeated messages.create calls, dispatching tools in parallel via Tool::invoke, optionally enforcing a cost budget and a mid-stream approval gate.

Gated on the async feature.

Re-exports§

pub use registry::FnTool;
pub use registry::ToolRegistry;
pub use tool::ApprovalDecision;
pub use tool::Tool;
pub use tool::ToolApprover;
pub use tool::ToolError;
pub use tool::fn_approver;
pub use runner::RunOptions;conversation
pub use typed::TypedTool;schemars-tools

Modules§

registry
ToolRegistry and the FnTool closure adapter.
runnerconversation
The agent loop runner.
tool
The Tool async trait and its companion ToolError.
typedschemars-tools
Schemars-driven typed tool registration.