Skip to main content

Module reliability

Module reliability 

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

  1. RetryClass + RetryClassifier — turn a KernelError into a deterministic “should I retry this call?” verdict. The default impl (DefaultRetryClassifier) covers every existing KernelError variant; hosts can supply a custom classifier when they layer in transport-specific errors (timeouts, rate limits, etc.) by chaining or overriding.
  2. ToolCallFingerprint — a stable, content-addressed hash of a ToolInvocation (tool name + canonical JSON args). Used to detect repeated calls and group retry attempts.
  3. 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§

DefaultRetryClassifier
Default classifier covering every KernelError variant.
ToolCallFingerprint
Stable content hash of a ToolInvocation.

Enums§

HistoryEntry
One entry in a tool-call history slice fed back to the model.
RetryClass
Deterministic verdict on whether an errored tool invocation may be retried.

Traits§

RetryClassifier
Classify a KernelError as transient or permanent.

Functions§

repair_history
Deterministically coalesce a tool-call history.