An open-source offline AI agent debugging tool: record, replay, analyze failures, and track API costs—free and local.
Project description
AgentLens
AgentLens is an open-source debugging toolkit for AI agents that enables offline recording, replay, failure analysis, and cost tracking. Built for developers who need efficient, local-first debugging without consuming API credits.
Overview
When developing AI agents, debugging is costly and time-consuming. Each iteration requires API calls, resources, and careful tracking of what happened. AgentLens provides:
- Offline debugging - Record and replay agent runs without making additional API calls
- Failure analysis - Identify common failure patterns automatically
- Cost tracking - Monitor token usage and estimated API costs
- Local-first workflow - Everything runs on your machine with no external dependencies
Installation
pip install auriel-agentlens
Quick Start
from agentlens import AgentLens
# Initialize AgentLens
lens = AgentLens()
# 1. Record agent runs with a decorator
@lens.record
def my_agent_function(query):
# Your agent implementation
return result
# Use your agent normally - AgentLens records in the background
response = my_agent_function("Process this data")
# 2. Or use the context manager for more control
with lens.context_record(model="gpt-4") as recording:
# Your agent code here
result = some_function()
recording.log_run(
input_data=query,
output_data=result,
token_usage={"prompt_tokens": 10, "completion_tokens": 20}
)
# 3. Replay the last recorded run
lens.replay()
# 4. Analyze failures in the last run
lens.analyze()
# 5. Track estimated costs
lens.costs(all_runs=True)
Framework Integrations
LangChain Integration
from agentlens import AgentLens
from agentlens.integrations.langchain import LangChainLens
# Initialize AgentLens and LangChainLens
lens = AgentLens()
lc_lens = LangChainLens(lens=lens)
# Wrap a LangChain LLM, Chain or Agent
llm = OpenAI(temperature=0.7)
wrapped_llm = lc_lens.wrap_llm(llm)
# Use wrapped components as normal
response = wrapped_llm("What are three best practices for writing clean code?")
# Wrap a LangChain Chain
chain = LLMChain(llm=llm, prompt=prompt)
wrapped_chain = lc_lens.wrap_chain(chain)
# Wrap a LangChain Agent
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION)
wrapped_agent = lc_lens.wrap_agent(agent)
OpenAI Integration
from agentlens import AgentLens
from agentlens.integrations.openai import OpenAILens
import openai
# Initialize AgentLens and OpenAILens
lens = AgentLens()
openai_lens = OpenAILens(lens=lens)
# Wrap the OpenAI client
client = openai.OpenAI()
wrapped_client = openai_lens.wrap_client(client)
# Use the wrapped client as normal
response = wrapped_client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain debugging in one paragraph."}
]
)
Key Features
Run Recording
Records agent inputs, outputs, tool calls, and token usage to local storage without requiring additional API calls.
@lens.record
def agent_function(input_query):
# Agent implementation
return result
Or using the context manager for more control:
with lens.context_record(model="gpt-4") as recording:
# Custom agent code
result = process_query(query)
recording.log_run(
input_data=query,
output_data=result,
token_usage=token_count,
tool_calls=tools_used
)
Offline Replay
Reproduces agent runs locally, allowing you to inspect each step without consuming API credits.
# Replay the most recent run
lens.replay()
# Replay a specific run by ID
lens.replay(run_id=3)
Failure Analysis
Automatically identifies common issues like timeouts, empty outputs, and potential hallucinations based on output patterns.
# Analyze the most recent run
lens.analyze()
# Analyze a specific run
lens.analyze(run_id=3)
Cost Tracking
Estimates API usage costs based on token counts and configurable pricing models.
# Track costs for the most recent run
lens.costs()
# Track costs for all runs
lens.costs(all_runs=True)
# Track costs for a specific run
lens.costs(run_id=3)
Command Line Interface
AgentLens includes a CLI for working with recorded runs:
# Replay a run
agentlens replay --file runs.jsonl
# Analyze a run
agentlens analyze --id 3 --file runs.jsonl
# Calculate costs
agentlens costs --all --file runs.jsonl
Use Cases
- Development iteration - Debug agents locally without repeatedly hitting APIs
- Cost optimization - Identify expensive or inefficient patterns in agent behavior
- Regression testing - Verify agent behavior after code changes
- Educational purposes - Study and analyze agent decision patterns
Framework Compatibility
Currently supporting:
- Direct Python function decorators and context managers
- LangChain (LLMs, Chains, and Agents)
- OpenAI Python client (both modern and legacy versions)
- Planning future support for CrewAI and other frameworks
Comparison with Alternatives
AgentLens is focused specifically on offline debugging and development iteration, complementing production monitoring tools like LangSmith or Helicone.
| Feature | AgentLens | Production Monitors |
|---|---|---|
| Deployment | Local-only | Cloud/hosted |
| Focus | Development/debugging | Production monitoring |
| Cost | Free, open-source | Freemium/paid tiers |
| Integration | Single decorator | Platform-specific |
| Analysis | Offline-first | Real-time analytics |
Development Setup
To set up AgentLens for development:
# Clone the repository
git clone https://github.com/auriel-ai/agentlens.git
cd agentlens
# Run the setup script
./setup_and_run.sh
Examples
Check out the examples/ directory for full examples including:
- Basic usage with the decorator and context manager
- LangChain integration examples
- OpenAI client integration
- Command line interface examples
Contributing
Contributions are welcome! See CONTRIBUTING.md for details.
License
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 auriel_agentlens-0.1.1.tar.gz.
File metadata
- Download URL: auriel_agentlens-0.1.1.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d9f4117591b3ed6bc3ebaf53a3b223f0251c8610c48c16c65ad7b21e632bb99
|
|
| MD5 |
983c66c7f19ae8eb41c4b1dd6cff75a2
|
|
| BLAKE2b-256 |
147ae6f43cccf900314269b685b9b68cd91971d10130362a2b6ac55b97bfebcf
|
File details
Details for the file auriel_agentlens-0.1.1-py2.py3-none-any.whl.
File metadata
- Download URL: auriel_agentlens-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94168baf6af420fe02140e71b2a1feece101e701c0d3d80d3a7b3ddf840fb00c
|
|
| MD5 |
28b18a5835e6e7c23ad82f705f5f338e
|
|
| BLAKE2b-256 |
f273181491d0df0d22c49d28bd4a55b4ab5f9feaf3c0b7b16fb364b4432e391c
|