Trace ⋅ Replay ⋅ Test your AI agents like real software
Project description
agentcheck
agentcheck: Trace ⋅ Replay ⋅ Test your AI agents like real software.
AgentCheck is a minimal but complete toolkit for tracing, replaying, diffing, and testing AI agent executions. Think of it as version control and testing for your AI agents.
🚀 Install
pip install agentcheck
⚡ Quickstart Demo
export OPENAI_API_KEY=sk-...
# 1️⃣ Capture baseline trace
python demo/demo_agent.py --output baseline.json
# 2️⃣ Modify the prompt inside demo_agent.py (e.g. change tone)
# 3️⃣ Replay with new code/model
agentcheck replay baseline.json --output new.json
# 4️⃣ See what changed
agentcheck diff baseline.json new.json
# 5️⃣ Assert the new output still mentions the user's name
agentcheck assert new.json --contains "John Doe"
Or run the complete demo:
cd demo && ./demo_run.sh
🎯 Features
| Feature | Description | CLI Command | Python API |
|---|---|---|---|
| Trace | Capture agent execution (prompts, outputs, costs, timing) | agentcheck trace <command> |
@agentcheck.trace() |
| Replay | Re-run trace against current code/model | agentcheck replay trace.json |
agentcheck.replay_trace() |
| Diff | Compare traces and highlight changes | agentcheck diff trace_a.json trace_b.json |
agentcheck.diff_traces() |
| Assert | Test trace contents (CI-friendly) | agentcheck assert trace.json --contains "foo" |
agentcheck.assert_trace() |
📖 Usage
Tracing with Decorator
import agentcheck
import openai
@agentcheck.trace(output="my_trace.json")
def my_agent(user_input: str) -> str:
response = openai.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": user_input}]
)
return response.choices[0].message.content
# Automatically traces execution and saves to my_trace.json
result = my_agent("Hello, world!")
Tracing with Context Manager
import agentcheck
with agentcheck.Trace(output="trace.json") as t:
# Your agent code here
messages = [{"role": "user", "content": "Hello"}]
# Manually add LLM calls to trace
response = openai.chat.completions.create(
model="gpt-4o-mini", messages=messages
)
t.add_llm_call(
messages=messages,
response={"content": response.choices[0].message.content, "usage": response.usage},
model="gpt-4o-mini"
)
CLI Commands
# Trace a Python script
agentcheck trace "python my_agent.py" --output trace.json
# Replay a trace with a different model
agentcheck replay trace.json --model gpt-4 --output new_trace.json
# Compare two traces
agentcheck diff baseline.json new_trace.json
# Assert trace contains expected content
agentcheck assert trace.json --contains "expected output"
# Assert with JSONPath
agentcheck assert trace.json --jsonpath "$.steps[-1].output.content" --contains "John"
# Assert cost and step constraints
agentcheck assert trace.json --max-cost 0.05 --min-steps 1 --max-steps 10
# Pretty-print a trace
agentcheck show trace.json
🏗️ Architecture
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ Your Agent │───▶│ agentcheck │───▶│ trace.json │
│ │ │ tracer │ │ │
└─────────────────┘ └──────────────┘ └─────────────────┘
│
┌─────────────────────┼─────────────────────┐
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ replay │ │ diff │ │ assert │
│ (re-execute) │ │ (compare) │ │ (test) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
📋 Trace Format
AgentCheck uses a standardized JSON schema for traces:
{
"trace_id": "uuid",
"version": "1.0",
"start_time": "2024-01-01T12:00:00Z",
"end_time": "2024-01-01T12:00:05Z",
"metadata": {
"total_cost": 0.0023,
"function_name": "my_agent"
},
"steps": [
{
"step_id": "uuid",
"type": "llm_call",
"start_time": "2024-01-01T12:00:01Z",
"end_time": "2024-01-01T12:00:04Z",
"input": {
"messages": [...],
"model": "gpt-4o-mini"
},
"output": {
"content": "Agent response...",
"usage": {"prompt_tokens": 10, "completion_tokens": 20},
"cost": 0.0023
}
}
]
}
🧪 Testing & CI Integration
AgentCheck is designed for CI/CD pipelines:
# In your CI pipeline
agentcheck replay baseline_trace.json --output ci_trace.json
agentcheck assert ci_trace.json --contains "expected behavior" --max-cost 0.10
# Exit codes
# 0 = success
# 1 = assertion failed or error
🛠️ Development
# Install in development mode
git clone https://github.com/agentcheck/agentcheck
cd agentcheck
pip install -e ".[dev]"
# Run tests
pytest
# Format code
ruff format .
# Type check
mypy agentcheck/
📄 License
MIT License - see LICENSE file.
🤝 Contributing
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
Built for the era of AI agents 🤖✨
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentcheck-0.1.0.tar.gz.
File metadata
- Download URL: agentcheck-0.1.0.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99badbb62805315bff4a261aeb7888b9626652cc5792d66c132537405b9400be
|
|
| MD5 |
ec3a3a644e6031e8eef6068e51fb1266
|
|
| BLAKE2b-256 |
b77ca3e8acc3b7bdd5c733ece9e1c2b1dd376b97d5956623595e5d6927c02006
|
File details
Details for the file agentcheck-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentcheck-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b08b3c23c8eba4492703fe45fa216fd798df63857045579d5e8b64fb8a4af0d
|
|
| MD5 |
553f95d30933aab80f1d2b91307de61a
|
|
| BLAKE2b-256 |
06735def14368c372fd8e086d8626bd4d70dd1a17b8611f576f55f86692c3110
|