Expand description
Ferrin tool system.
Tool definitions (Tool, ToolKind, ToolSet), the execution
contract (ToolExecute, ToolOutput, ToolContext, ToolError),
approval declarations (NeedsApproval), model-output normalisation,
caller restrictions, tool fingerprints and (feature sandbox) the
Sandbox trait with a local-process implementation.
Tool call parsing, approval resolution, execution scheduling and repair live in the core crate; this crate only describes tools and runs one execution when asked.
Design: docs/01-architecture/06-tool-system.md, ADR 0012.
§Attribution
Portions of this crate are derived from the Vercel AI SDK (Apache-2.0,
Copyright 2023 Vercel, Inc.), translated from TypeScript to Rust and
modified. See the NOTICE file in the crate root.
Re-exports§
pub use callers::PreparedToolCallers;pub use callers::ToolCaller;pub use callers::ToolCallerDefinition;pub use callers::ToolCallers;pub use fingerprint::ToolDrift;pub use model_output::ErrorMode;pub use sandbox::LocalProcessSandbox;pub use sandbox::Sandbox;pub use sandbox::SandboxProcess;
Modules§
- callers
- Caller restrictions: which callers (the model directly, or other tools) may trigger a tool, and how caller tools receive their callees.
- fingerprint
- Tool fingerprints for drift detection.
- model_
output - Conversion of execution results into the output the model receives.
- sandbox
- Sandbox abstraction (feature
sandbox): a session that reads and writes files and runs commands on behalf of tools.
Structs§
- Description
Context - Inputs available when resolving a dynamic description.
- Duplicate
Tool Error - A tool name was inserted twice into a
crate::ToolSet. - Model
Output Args - Arguments of a
ToModelOutputFn. - Schema
- A JSON Schema paired with a function that validates a JSON value and
converts it into
T. - Tool
- A tool definition. Built with
Tool::function,Tool::dynamic,Tool::provider_definedorTool::provider_executed. - Tool
Builder - Builds a
Tool.Iis the input type handed to the execute closure. - Tool
Context - Per-call information handed to a tool execution.
- Tool
Hooks - Lifecycle hooks around tool input.
- ToolSet
- Named tools available to a call. Insertion order is preserved; names are unique.
Enums§
- Description
- Tool description sent to the model.
- Needs
Approval - Tool-level approval declaration. Call-level approval policies configured on the generation take precedence over it.
- Tool
Error - Error returned by a tool execution.
- Tool
Kind - Who defines and who executes a tool.
- Tool
Output - One output of a tool execution.
Traits§
- Json
Schema - A type which can be described as a JSON Schema document.
- Tool
Execute - Executes a tool.
Functions§
- execute_
to_ completion - Drives an output stream to its end, forwarding preliminary values to
on_preliminaryand returning the final value.
Type Aliases§
- Approval
Fn - Decides per call whether approval is needed.
- Description
Fn - Produces a description per call.
- Input
Available Hook - Called once the full input is available and valid.
- Input
Delta Hook - Called for each streamed input delta.
- Input
Start Hook - Called when the model starts producing input for the tool.
- ToModel
Output Fn - Converts an execution output into what the model receives.
- Tool
Output Stream - Stream of outputs produced by one execution.
Derive Macros§
- Json
Schema - Derive macro for
JsonSchematrait.