Skip to main content

Crate ferrin_tool

Crate ferrin_tool 

Source
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§

DescriptionContext
Inputs available when resolving a dynamic description.
DuplicateToolError
A tool name was inserted twice into a crate::ToolSet.
ModelOutputArgs
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_defined or Tool::provider_executed.
ToolBuilder
Builds a Tool. I is the input type handed to the execute closure.
ToolContext
Per-call information handed to a tool execution.
ToolHooks
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.
NeedsApproval
Tool-level approval declaration. Call-level approval policies configured on the generation take precedence over it.
ToolError
Error returned by a tool execution.
ToolKind
Who defines and who executes a tool.
ToolOutput
One output of a tool execution.

Traits§

JsonSchema
A type which can be described as a JSON Schema document.
ToolExecute
Executes a tool.

Functions§

execute_to_completion
Drives an output stream to its end, forwarding preliminary values to on_preliminary and returning the final value.

Type Aliases§

ApprovalFn
Decides per call whether approval is needed.
DescriptionFn
Produces a description per call.
InputAvailableHook
Called once the full input is available and valid.
InputDeltaHook
Called for each streamed input delta.
InputStartHook
Called when the model starts producing input for the tool.
ToModelOutputFn
Converts an execution output into what the model receives.
ToolOutputStream
Stream of outputs produced by one execution.

Derive Macros§

JsonSchema
Derive macro for JsonSchema trait.