Time-Travel Debugging for AI Agents
Project description
AgentTrace - Time-Travel Debugging for AI Agents ๐
The Industry's First Time-Travel Debugger for LLM Agents + AutoFix Engine
AgentTrace enables you to record, replay, and debug AI agent executions with full determinism. Jump to any point in time, edit the past, and see what would have happened. Our AutoFix Engine (AFE) automatically detects failures, classifies root causes, generates fixes, validates them in sandboxes, and can even auto-apply solutions.
๐ Quick Start
# Install
pip install agenttrace
# Record a trace
agenttrace record my_agent.py
# List traces
agenttrace list
# Replay a trace
agenttrace replay <trace-id>
# Jump to specific step
agenttrace replay <trace-id> --step 42
โจ Features
โฑ๏ธ Time-Travel Debugging
- Record agent executions with full state capture
- Replay deterministically (same random numbers, same API responses)
- Jump to any step using keyframe snapshots
- Resume execution from any saved step (state hydration + runtime restore)
- Edit the past (fork a branch, tweak payloads, continue execution)
๏ฟฝ AutoFix Engine (AFE)
- Automatic Failure Detection - Detects errors in traces automatically
- Root Cause Analysis - Classifies failures (rate limits, API errors, missing context, etc.)
- Multi-Strategy Fix Generation - Code patches, config changes, prompt improvements, retry policies
- Sandbox Validation - Tests fixes in isolated environments before applying
- Policy-Based Ranking - Prioritizes fixes by confidence, risk, and success rate
- Auto-Apply - High-confidence fixes can be applied automatically
- LLM-Powered - Uses Groq for intelligent code generation and analysis
๏ฟฝ๐ก๏ธ Safety Sandbox
- Virtual File System - File writes are isolated during replay
- VCR Pattern - API calls are cached (no costs during debugging)
- Deterministic Replay - Random numbers, time, and API calls are frozen
โ๏ธ Full SaaS Platform
- Multi-User Auth - Email magic link login with organization isolation
- Cloud Storage - Traces stored in Supabase Storage with CDN delivery
- Worker Fleet - Python workers for distributed trace processing
- Real-Time Dashboard - AFE monitoring, trace timeline, multiverse branching
- Email Notifications - Brevo integration for failure alerts and fix notifications
๐ค Framework Support
- OpenAI API
- Groq API
- LangChain (coming soon)
- AutoGen (coming soon)
๐ Usage
Basic Recording
# my_agent.py
from groq import Groq
client = Groq()
response = client.chat.completions.create(
model="llama3-8b-8192",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
agenttrace record my_agent.py
# Output: โ
Trace recorded: abc123-def456-...
Replay Mode
export AGENTTRACE_MODE=REPLAY
export AGENTTRACE_ID=abc123-def456-...
python my_agent.py
# Runs with cached API responses (free!)
Resuming from a Saved Step
# Jump directly to step 25 and resume from there
agenttrace replay abc123-def456-... --step 25
python my_agent.py # execution restarts with the recorded locals/globals
Branching & Editing History
# Create a branch at a specific step (requires a snapshot/keyframe there)
agenttrace branch create abc123-def456-... --step 42 --name patch-output
# Override a recorded event payload (e.g., change an LLM response)
agenttrace branch edit abc123-def456-...__patch-output --event 42 --payload '{"content":"Rewritten response"}'
# Replay from that branch and continue deterministically
agenttrace replay abc123-def456-... --branch abc123-def456-...__patch-output
python my_agent.py # starts from the forked state with your edits applied
AI-Powered Auto-Fix
# Auto-fix errors using Groq AI
agenttrace fix <trace-id>
# Fix a specific step
agenttrace fix <trace-id> --step 42
# Use your own API key
agenttrace fix <trace-id> --api-key your_groq_key
# Override Groq model (or set GROQ_MODEL env var)
agenttrace fix <trace-id> --model llama-3.1-8b-instant
# Use heuristic suggestions instead of AI
agenttrace fix <trace-id> --no-ai
Setup:
- Copy
.env.exampleto.env - Add your Groq API key:
GROQ_API_KEY=your_key_here - (Optional) Set
GROQ_MODEL=llama-3.1-8b-instant(see https://console.groq.com/docs/models for options) - Get your key from: https://console.groq.com/
The AI fixer analyzes error traces, extracts code context, and generates actual code patches with explanations.
Automatic State Capture
AgentTrace automatically captures:
- Local variables at keyframe intervals
- Global state
- Function call stack
- API request/response pairs
- Random number sequences
- Time/DateTime values
๐ Production Deployment
1๏ธโฃ Supabase Setup
# Run all migrations
cd supabase
supabase db push
# Or manually run SQL files:
# - supabase_fix_afe_constraint.sql (AFE type constraint)
# - supabase_fix_afe_status_constraint.sql (AFE status constraint)
# - supabase_add_notifications.sql (Brevo integration)
2๏ธโฃ Environment Configuration
Copy frontend/.env.local.example to frontend/.env.local and configure:
# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
# Groq (for AFE)
GROQ_API_KEY=your_groq_api_key
# Brevo (for notifications)
BREVO_API_KEY=your_brevo_api_key
BREVO_SENDER_EMAIL=your_email@domain.com
BREVO_SENDER_NAME="AgentTrace"
3๏ธโฃ Frontend Deployment
cd frontend
npm install
npm run build
npm start
Or deploy to Vercel:
vercel --prod
4๏ธโฃ Worker Deployment
cd worker
pip install -r requirements.txt
python main.py
For production, use process managers:
# Using PM2
pm2 start main.py --name agenttrace-worker --interpreter python
# Using systemd (create /etc/systemd/system/agenttrace-worker.service)
# Or containerize with Docker
5๏ธโฃ Brevo IP Whitelisting
Add your worker's IP address to Brevo's authorized IPs:
- Go to https://app.brevo.com/security/authorised_ips
- Add your server IP
- Restart worker
Architecture Overview
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Next.js โโโโโโถโ Supabase โโโโโโโ Python โ
โ Frontend โ โ (Auth/DB/ โ โ Workers โ
โ โ โ Storage) โ โ โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโค
โ โ Polling Jobs โ
โ โ Processing Traces โ
โ โ Running AFE โ
โโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโ
๐งช Tests
Pytest (Tracer + CLI)
pytest tests/e2e
Next.js API Routes
cd frontend
npm install # first run
npm run test:api
UI Automation
cd frontend
npx playwright test # Run UI branch flow tests
๐๏ธ Architecture
AgentTrace uses a Hybrid Keyframe Architecture:
- Delta Log: Lightweight event log (API calls, random numbers)
- Keyframes: Full memory snapshots every N steps (default: 10)
- Fast Seek: Load nearest keyframe + replay deltas = instant jump to any step
๐ Security
- PII Scrubbing: Automatic detection and redaction (coming soon)
- Secrets Detection: API keys are automatically masked
- Sandbox Isolation: Replay can't affect production systems
โ๏ธ Supabase Backend (Optional)
AgentTrace now supports a hosted Supabase backend for team collaboration:
- Multi-user auth โ Email magic link login with org isolation
- Cloud storage โ Traces and snapshots stored in Supabase Storage
- Job queue โ Replay jobs queued in Postgres for worker processing
- Row-level security โ All data scoped by organization
Setup: See supabase/README.md for instructions. You can connect to a real Supabase project directly โ no Docker required!
๐ Recent Improvements
โ December 2024 - Stability & Production Readiness
Bug Fixes:
- Fixed AFE database constraints to support all candidate types
- Fixed script upload for Fork, Simulate, and Replay operations
- Fixed worker organization selection for multi-tenant support
- Fixed Supabase import issues in AFE stats API
- Fixed GitHub secret detection by excluding API keys from commits
Features:
- Added AutoFix Engine link to sidebar navigation
- Created comprehensive stress testing suite (5 concurrent jobs)
- Added utility scripts for debugging and verification
- Implemented reset_traces.py for clean database resets
- Added migration verification scripts
Infrastructure:
- Configured Brevo email notifications for failures and fixes
- Set up proper .gitignore for security (excludes .env files and local traces)
- Established GitHub repository with clean commit history
- Created deployment documentation and setup guides
๐ Roadmap
- Core time-travel engine
- VCR pattern for LLM APIs
- Virtual File System
- Automatic state capture
- CLI tool
- Web UI (Timeline visualizer)
- AutoFix Engine (RCA + multi-strategy fixes)
- Cloud storage & sharing (Supabase backend)
- Python worker for remote replay
- Email notifications (Brevo)
- Stress testing & production stability
- LangChain integration
- CLI login & token auth
- Auto-apply policies with approval workflows
๐ค Contributing
This is a rapidly evolving project. Contributions welcome!
๐ License
MIT License
๐ Acknowledgments
Built on research from:
- Temporal (Durable Execution)
- CRIU (Checkpoint/Restore)
- cloudpickle (State Serialization)
- pyfakefs (Virtual File System)
Made with โค๏ธ for the AI Agent community
Project details
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 agenttrace_sdk-0.3.2.tar.gz.
File metadata
- Download URL: agenttrace_sdk-0.3.2.tar.gz
- Upload date:
- Size: 103.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b89e8ce5ffacc39b43f1ffa82234f5b9ce981645ac7a2c9177fb4bbdc3896d04
|
|
| MD5 |
4c0fcc14652d73f8c3f043602bc826ef
|
|
| BLAKE2b-256 |
7c4c382ead57939175de19bef820dfe8962d8d100decc71fc05293c3f1a8f56c
|
File details
Details for the file agenttrace_sdk-0.3.2-py3-none-any.whl.
File metadata
- Download URL: agenttrace_sdk-0.3.2-py3-none-any.whl
- Upload date:
- Size: 112.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df227eeb1a1290dc636e4190870c38efe8d3d62331ed7def43efd8a4456c27dd
|
|
| MD5 |
451352ee73a52f266f7e2fd70de2bf47
|
|
| BLAKE2b-256 |
31716a802de54a7d53937835b314eb3c1123242248d41f242f88b0005ac1d15b
|