Skip to main content

Module tool

Module tool 

Source
Expand description

Tool authoring contracts, dispatch context, and canonical execution values. Tool is the tool trait; each call gets a ToolContext.

use rig_core::tool::ToolOutput;

let output = ToolOutput::json(serde_json::json!({"count": 3}));
assert!(output.as_json().is_some());

Re-exports§

pub use context::ContextValue;
pub use context::PublishedContext;
pub use context::ToolContext;
pub use context::ToolContextError;
pub use context::ToolResultContext;
pub use contextual::DynamicTool;
pub use contextual::LivenessFn;
pub use contextual::Tool;
pub use contextual::ToolEmbedding;
pub use contextual::tool_definition;
pub use contextual::tool_name;
pub use managed::ManagedToolSink;
pub use managed::ManagedToolToken;
pub use schema::args_schema;

Modules§

builtin
Built-in tools shipped with rig that agents can use out of the box.
context
Typed inbound context and explicitly published host-only tool-result metadata.
contextual
Contextual tool authoring and JSON-argument dispatch adapters. ToolContext carries typed inbound values and host-only result metadata; model-visible outputs retain their text, JSON, or multimodal representation.
feedback
What the model reads about its tool calls: a tool’s result shaped as a tool result, the error result of a call that never ran, what a call that did not finish says (not_finished), and the feedback for arguments that do not fit a tool.
managed
Registry contracts for refreshable external tool sources. Generation tokens protect newer registrations from stale refreshes, while DynamicTool::is_live reports disconnection without tool execution.
schema
A tool’s parameters derived from its arguments type, so the schema the model sees and the type its arguments are parsed into cannot disagree:
validate
Whether a value fits a JSON schema, and where it does not: the check a tool call’s arguments pass before the tool runs (arguments_refusal).

Structs§

ContentHash
The SHA-256 of a file’s bytes, as lowercase hex: which content a tool read or left (content_hash).
FileChange
One file a tool call changed.
FileRead
One file a tool call read.
FileState
A file on one side of a FileChange: as it was before the change, or as the change left it.
FilesChanged
The files a tool call changed, in the order it changed them.
FilesRead
The files a tool call read, in the order it read them, each once: a file it showed the model, or one it found matches in.
Hunk
One run of a FileChange: the lines it removed and added, between the lines around them it kept.
Lines
Lines of a file that a Hunk spans: count lines from line start, counted from 1. An empty span starts at the line it comes before. Shown as a unified diff’s range (3,2; 3; 2,0 for an empty one before line 3).
LinesShown
The lines of a file a tool showed: count lines from line first, of the total it has.
OutputCut
A tool’s output was cut to fit: the model’s text keeps one end, or both ends and some lines from between, and says so in a line of its own. A front reads this fact, not that line’s wording, to draw and count the cut.
ToolExecutionError
One public envelope for every tool execution failure.
ToolOutput
The canonical model-visible output produced by a tool.
ToolResult
The single structured execution view used by dispatch, hooks, and telemetry.

Enums§

ChangeKind
What a tool call did to a file.
ExitStatus
How a process a tool call ran ended.
HunkLine
A line of a Hunk, with its ending. Its wire form is the line as a unified diff shows it: its sign ( , - or +), then its text.
KeptEnd
Which part of a cut output a tool kept (OutputCut::kept).
Scope
What a footprint names: these paths (absolute; a directory covers what is under it), or anything at all. A guard compares paths as they are, so a host makes a footprint normalized before any guard sees it; the rig kernel does so for every tool call.
ToolErrorKind
Normalized classification for a tool execution error.
Touches
What a tool call may read and change, so calls that touch different things run side by side.

Traits§

IntoToolOutput
Conversion into Rig’s canonical tool output.

Functions§

content_hash
The ContentHash of bytes.