Skip to main content

Crate agentsnap

Crate agentsnap 

Source
Expand description

Snapshot tests for AI agent traces.

The Jest-snapshot pattern, applied to agent runs. Build a Trace of LLM calls and tool invocations from your test, then call assert_matches: the first run records the snapshot to disk; later runs compare against it and panic with a unified diff if anything changed. Set AGENTSNAP_UPDATE=1 in the environment to refresh the snapshot.

§Quick start

use agentsnap::{assert_matches, Trace, TraceCall};
use serde_json::json;

let mut trace = Trace::new("answer_user");
trace.push(TraceCall::llm("planner", json!({"q": "hi"}), json!({"plan": ["greet"]})));
trace.push(TraceCall::tool("greet_tool", json!({"name": "world"}), json!("hi world")));

// First run: writes snapshots/answer_user.snap.json
// Subsequent runs: panics if anything diverges
assert_matches(&trace, "snapshots/answer_user.snap.json");

Structs§

Trace
One full agent run, identified by a name.
TraceCall
One step in an agent trace.

Enums§

MatchResult
Outcome of a compare call.
SnapError
Errors from snapshot ops.
TraceCallKind
What kind of step a trace call represents.

Functions§

assert_matches
Test helper: compare-or-record, panic on mismatch.
compare
Compare a trace to the snapshot at path. Records on first run.
record
Write the trace as a snapshot at path, overwriting if present.