Documentation
Record agent runs, snapshot them into test cases, and replay them in CI.
5-minute quickstart
1. Install the SDK (Python 3.11+).
pip install agentrecheck2. Instrument your agent. @trace records the run, @tool records tool calls, and wrap_openai / wrap_anthropic record LLM calls.
from openai import OpenAI
from agentrecheck import trace, tool, wrap_openai
client = wrap_openai(OpenAI())
@tool
def lookup_order(order_id: str) -> dict:
...
@trace
def run_agent(message: str) -> str:
... # your existing agent loop, unchanged3. Create the config, run the agent once, and snapshot that run into a test case.
agentrecheck init --entrypoint agent:run_agent
python agent.py "Where is my order A1002?"
agentrecheck traces # see what was recorded
agentrecheck snapshot latest --id order_status4. Replay. Every case runs against your current code and is compared to its baseline. The exit code is non-zero if anything regressed.
agentrecheck runWant to see a caught regression first? The repository includes examples/support_agent, which runs offline with no API key.
Tracing
A trace is one agent run: its input, every LLM call (model, prompt, output, tokens, latency, cost), every tool call (name, arguments, result, error), and the final output. Traces are saved as JSON under .agentrecheck/traces/.
| @trace / @trace(name=...) | Record each call of a sync or async function as a trace. |
| with start_trace(name): | Context-manager form for code you can't decorate. |
| @tool | Record each call of a function as a tool step, with bound arguments. |
| wrap_openai(client) | Chat Completions and Responses APIs, sync and async. |
| wrap_anthropic(client) | Messages API, sync and async. |
| wrap(client) | Auto-detect the provider. |
| record_llm_call(...) / record_tool_call(...) | Record a step by hand for any other provider or framework. |
| register_adapter(name, detect, wrap) | Plug in your own client adapter. |
| register_price(model, in, out) | Set or override per-million-token prices used for cost. |
Streaming responses are passed through untouched and noted on the step, but their content is not captured yet. Set AGENTRECHECK_DISABLED=1 to turn recording off.
Test cases
agentrecheck snapshot <trace_id> writes a YAML file to agentrecheck_cases/. It contains the input to replay, the baseline (tool sequence, cost, latency, steps, output), and starter assertions. Commit these files.
id: refund_outside_window
name: Refund request outside the 30-day window
input:
args: ["Please refund order A1003, I changed my mind."]
kwargs: {}
baseline:
tool_sequence: [lookup_order]
cost_usd: 0.0001197
latency_ms: 48.0
steps: 3
assertions:
tools:
sequence: [lookup_order]
mode: exact
output:
contains: ["30-day"]
not_contains: ["has been issued"]
budgets:
max_steps: 4Assertions
| tools.sequence + mode: exact | The executed tools must equal the list exactly. |
| tools.sequence + mode: subset | The listed tools must all appear, in order. Other calls are allowed in between. |
| tools.args[].exact | A tool call's arguments must equal this object. |
| tools.args[].regex | Per-argument regular expressions, e.g. order_id: "^A\d+$". |
| tools.args[].json_schema | Validate the arguments against a JSON Schema. |
| tools.args[].index | Which call of that tool to check (0 = first). |
| output.contains / not_contains | Case-insensitive substrings of the final output. |
| output.regex | A regular expression the final output must match. |
| output.judge | LLM-as-judge: a rubric and a min_score between 0 and 1. |
| budgets.max_cost_usd / max_latency_ms / max_steps | Hard ceilings for the run. |
Separately from assertions, each run is compared to its baseline. A cost increase above regression.max_cost_increase_pct (default 25%) fails the case. Latency regression is off by default because CI timing is noisy; set max_latency_increase_pct to enable it.
CLI
| agentrecheck init | Create agentrecheck.yaml and the cases directory. |
| agentrecheck traces | List locally recorded traces. |
| agentrecheck show <id|latest> | Print a trace's step-by-step timeline. |
| agentrecheck snapshot <id|latest> | Turn a trace into a test case. Flags: --id, --name, --mode, --force. |
| agentrecheck run | Replay all cases. Flags: --case, --entrypoint, --json-out, --markdown-out, --no-upload. |
| agentrecheck upload <id|latest|all> | Send local traces to the dashboard. |
Exit codes: 0 all cases passed, 1 at least one regression, 2 configuration error.
CI
Any CI system works: install your dependencies and run agentrecheck run. On GitHub Actions the pass/fail table and diffs are also written to the job summary.
name: AgentRecheck
on: [pull_request]
jobs:
agent-regression:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: "3.11" }
- run: pip install agentrecheck -r requirements.txt
- run: agentrecheck run
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
AGENTRECHECK_API_KEY: ${{ secrets.AGENTRECHECK_API_KEY }}
AGENTRECHECK_API_URL: ${{ vars.AGENTRECHECK_API_URL }}Dashboard and API
The dashboard is optional. Create a project to get an API key, then set two environment variables. Traces upload as each run finishes; agentrecheck run uploads its results with diffs.
export AGENTRECHECK_API_KEY=ark_...
export AGENTRECHECK_API_URL=https://your-deployment.example.comEvery endpoint authenticates with Authorization: Bearer <project api key>.
| POST /api/traces | Ingest one trace, or { traces: [...] } (max 100). |
| GET /api/traces?limit=50 | Recent traces. |
| GET /api/traces/:id | One trace with all steps. |
| POST /api/runs | Upload a test run. |
| GET /api/runs?limit=50 | Recent runs with pass/fail counts. |
| GET /api/runs/:id | One run with per-case checks and diffs. |
LLM-as-judge
Judge checks are optional and run on your own key. Install the extra for your provider and set its key. Without a key, judge checks are reported as skipped, never failed.
pip install "agentrecheck[openai]" # or "agentrecheck[anthropic]"
export OPENAI_API_KEY=... # or ANTHROPIC_API_KEYPick the model with judge_model: openai:gpt-4o-mini in agentrecheck.yaml, or the AGENTRECHECK_JUDGE_MODEL environment variable.