Catalog PyPI
PACKAGE EXPLORERView in registry

agent-replay-py

PyPI

Record & replay LLM API calls for deterministic agent tests.

agentcassettehttpxllmpytestrecord-replaytestingvcr
Versions collected1
Direct dependencies3From release 0.1.0
Last observed20 Oct, 23:12 UTC

README

Version 0.1.0 documentation

agent-replay (Python)

Record & replay LLM API calls for deterministic agent tests.

agent-replay captures the HTTP traffic your agent makes to LLM providers (Anthropic, OpenAI, …) into a human-readable JSONL "cassette", then plays it back on subsequent runs so your tests are fast, offline, and deterministic — while still flagging when a prompt has drifted away from what was recorded.

Install

pip install agent-replay-py

The install name is agent-replay-py; the import name is agentreplay (there is an unrelated agentreplay project on PyPI, so we distinguish the distribution name).

Optional extras:

pip install "agent-replay-py[pytest]"   # pytest fixture & marker

Quick start

import agentreplay as ar

with ar.cassette("tests/cassettes/hello.jsonl", mode="auto") as c:
    client = c.httpx_client()   # a preconfigured httpx.Client
    r = client.post(
        "https://api.anthropic.com/v1/messages",
        json={"model": "claude-3", "messages": [{"role": "user", "content": "hi"}]},
    )
    print(r.json())
  • First run: the cassette file doesn't exist yet → records the real response.
  • Later runs: the file exists → serves the recorded response, no network.
  • mode accepts "record" | "replay" | "auto" | "passthrough", and can be overridden globally via AGENTREPLAY_MODE.

Async is the same shape:

async with ar.cassette("tests/cassettes/hello.jsonl") as c:
    async with c.httpx_async_client() as client:
        r = await client.post(...)

pytest

agent-replay ships a pytest plugin. Cassettes are auto-named from the test node id and stored under tests/cassettes/.

import pytest

@pytest.mark.agentreplay(mode="auto")
def test_agent(agentreplay):
    client = agentreplay.httpx_client()
    ...

CLI

agentreplay inspect tests/cassettes/hello.jsonl   # header + summary
agentreplay show    tests/cassettes/hello.jsonl 0 # pretty-print seq 0
agentreplay verify  tests/cassettes/hello.jsonl   # re-check fingerprints

Divergence

When the request your code sends no longer matches what was recorded (a prompt changed, a tool schema was edited, …), agent-replay produces a structured diff (ar.Report) instead of silently returning stale data. The divergence policy ("warn" | "error") controls whether it raises.

License

MIT — see LICENSE.

The TypeScript sibling of this package lives at @retr0hxx/agent-replay.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.019 Jul 20263

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
retr0hxx/agent-replay

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 23:12 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:23b9a3b747f906e7d49834b84fa7415802d3227716afa14b8261997bb8f3ceed