Expand description
Reliability primitives for tool dispatch loops.
This module groups three small, host-driven utilities that downstream agents combine when wrapping a normalized tool loop:
RetryClass+RetryClassifier— turn aKernelErrorinto a deterministic “should I retry this call?” verdict. The default impl (DefaultRetryClassifier) covers every existingKernelErrorvariant; hosts can supply a custom classifier when they layer in transport-specific errors (timeouts, rate limits, etc.) by chaining or overriding.ToolCallFingerprint— a stable, content-addressed hash of aToolInvocation(tool name + canonical JSON args). Used to detect repeated calls and group retry attempts.HistoryEntry+repair_history— deterministic coalescing of a raw(invocation, outcome)sequence into the smallest history the model should see. Multiple retries of the same fingerprint collapse to a single canonical entry; the host stays in control of how many physical retries actually happened.
These primitives are intentionally synchronous and infallible: they operate on already-materialized invocations and outcomes, never on live transports.
§Example
use rig_compose::{
DefaultRetryClassifier, HistoryEntry, KernelError, RetryClass,
RetryClassifier, ToolInvocation, repair_history,
};
use serde_json::json;
let classifier = DefaultRetryClassifier;
let inv = ToolInvocation::new("search", json!({"q": "rig"})).expect("valid");
let history = vec![
HistoryEntry::Failed {
invocation: inv.clone(),
class: classifier.classify(&KernelError::ToolFailed("timeout".into())),
message: "timeout".into(),
},
HistoryEntry::Completed {
invocation: inv,
output: json!({"hits": 3}),
},
];
let repaired = repair_history(&history);
assert_eq!(repaired.len(), 1);
assert!(matches!(repaired[0], HistoryEntry::Completed { .. }));Structs§
- Default
Retry Classifier - Default classifier covering every
KernelErrorvariant. - Tool
Call Fingerprint - Stable content hash of a
ToolInvocation.
Enums§
- History
Entry - One entry in a tool-call history slice fed back to the model.
- Retry
Class - Deterministic verdict on whether an errored tool invocation may be retried.
Traits§
- Retry
Classifier - Classify a
KernelErroras transient or permanent.
Functions§
- repair_
history - Deterministically coalesce a tool-call history.