Dev.to AI 🤖 Ai 👁 0 📖 2 min read

Record, mock-replay and CI-gate your agent's tool path

Unit tests like a deterministic function. Agents like a tool world that moved under them. I wanted a way to pin the tool path — not the entire mind of the model — and fail CI when that path drifted. Agent Replay Lab is

Unit tests like a deterministic function. Agents like a tool world that moved under them. I wanted a way to pin the tool path — not the entire mind of the model — and fail CI when that path drifted.

Agent Replay Lab is the open-source answer I shipped for TypeScript agents. I'm Jarvis Nelson Osorio. This is a tutorial for the v0.1 path: record, mock-replay offline, and gate structural drift. The packages are not on npm yet. This is not an MCP server.

Install and prove the demo

Node.js 22+ and pnpm:

git clone https://github.com/JarvisOsorio/agent-replay-lab.git
cd agent-replay-lab
pnpm install
pnpm build
pnpm test
pnpm --filter @agent-replay-lab/example-basic-agent demo

The example records a run, replays it against mocks, and shows an intentional regression. If that demo does not pass, stop there.

Wrap the tool, not the agent

You do not migrate onto a new framework. You wrap the tool function:

import { Replay, ReplayStore, wrapTool } from "@agent-replay-lab/core";

const store = new ReplayStore(".agent-replay/store.sqlite");
store.ensureProject("demo", "demo");

const replay = new Replay({ store, projectId: "demo" });
const getWeather = wrapTool(replay, "getWeather", async (args: { city: string }) => {
  return { tempC: 21, city: args.city };
});

await getWeather.execute({ city: "Berlin" });
replay.complete();

Known secret key names and common token shapes are redacted before persist. Treat that as a first layer, not as a complete privacy product. For after-the-fact remediation of existing stores, pair this with agentscrub.

Use the CLI as a CI knife

After pnpm --filter @agent-replay-lab/cli build:

pnpm --filter @agent-replay-lab/cli exec agent-replay init my-agent
pnpm --filter @agent-replay-lab/cli exec agent-replay list
pnpm --filter @agent-replay-lab/cli exec agent-replay inspect <runId>
pnpm --filter @agent-replay-lab/cli exec agent-replay replay <runId>
pnpm --filter @agent-replay-lab/cli exec agent-replay diff <runA> <runB>
pnpm --filter @agent-replay-lab/cli exec agent-replay fixture create <runId> golden
pnpm --filter @agent-replay-lab/cli exec agent-replay test golden --json
pnpm --filter @agent-replay-lab/cli exec agent-replay test golden --run <candidateRunId>

fixture create pins tool sequence, arguments and responses. test golden --run uses the same bar as diff and exits 1 on structural drift. Other exit codes: 2 for an invalid fixture, 3 for infrastructure. Output has a human form and a --json form.

Import remaps a cassette into the local project id so list, replay and test work immediately, while the integrity hash is still verified against the file.

Matching is strict, and mocks fail closed

Object keys are sorted for canonical JSON. Volatile fields such as requestId, timestamps, traceId and spanId are dropped. Misses and argument mismatches are errors, never silent skips. If a mock is missing, offline replay fails closed. There is no hidden HTTP client in that path.

What you should not claim after a green test

A green Replay Lab test means the tool path matched the fixture against a stubbed tool world. It does not mean the model is deterministic. It does not pin retries, clocks or state machines. Live-tools and live-model modes are not in v0.1. There is no dashboard and no MCP adapter in this release.

I would rather you take the smaller win: a hermetic, Apache 2.0 cassette you can keep next to the repo and run in CI with the network denied.

Canonical write-up: https://jarvis-nelson-osorio.pages.dev/blog/jarvis-nelson-osorio-agent-replay-lab-vcr-for-agent-tools/

Hub: https://jarvisosorio.com/open-source/

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.