AgentLens
Runtime profiler and optimization engine for AI agents using MCP.
AgentLens sits between your agent and its tools — observing every MCP schema load, tool call, and LLM call, then using that history to automatically pre-select the minimal tool set for future runs. The result: 80–95% reduction in schema token overhead, zero code changes in the agent.
pip install agentlens
The Problem
Every agent connecting to an MCP server loads all tool schemas on every call — even tools it will never use. A 50-tool server dumps 8,000–15,000 tokens of schema into every LLM call. No existing observability tool (LangSmith, Arize, Helicone) measures or optimizes this.
The Solution
Before AgentLens After AgentLens
───────────────── ───────────────
Agent → 50 tool schemas Agent → 6 tool schemas (snapshot)
↓ 12,000 tokens ↓ 800 tokens
LLM picks 6 tools LLM calls correct tools
Cost: $0.036/call Cost: $0.0024/call (93% saving)
AgentLens profiles your agent, builds a snapshot of the tools it actually uses per task type, and on the next run pre-loads only those tools.
Installation
# Core
pip install agentlens
# With Postgres support
pip install "agentlens[postgres]"
# With LangChain support
pip install "agentlens[langchain]"
# With OpenAI support
pip install "agentlens[openai]"
# Everything
pip install "agentlens[postgres,langchain,openai]"
Requires Python 3.11+.
Quick Start
1. Wrap your Anthropic client (10 lines)
import anthropic
from agentlens import AgentLens
lens = AgentLens(store="sqlite:///agentlens.db")
await lens.init()
raw = anthropic.Anthropic()
async with lens.session(agent_id="my-agent", task_type="code-review") as sess:
client = lens.wrap_anthropic(session=sess)
# client records every call — token counts, cost, latency
2. Wrap your MCP client (zero code in the agent)
# Start AgentLens as a transparent proxy in front of your MCP server
agentlens proxy start --upstream "uvx mcp-server-filesystem /tmp"
# Your agent now points to this proxy instead of the real server
# All tool calls are profiled automatically
3. Build a snapshot after enough sessions
agentlens snapshot build code-review --min-sessions 5
4. Use the snapshot — agent loads only 6 tools instead of 50
agentlens proxy start --upstream "uvx mcp-server-filesystem /tmp" --task-type code-review
5. View your savings
agentlens stats show --last 7d
agentlens dashboard show # live terminal UI
Architecture
┌────────────────────────────────────────────────────────┐
│ Agent / LLM App │
└──────────────┬───────────────────────────┬─────────────┘
│ SDK wrapper │ MCP proxy
┌─────────▼──────────┐ ┌──────────▼──────────┐
│ AgentLens SDK │ │ AgentLens Proxy │
│ wrap_anthropic() │ │ (zero code change) │
│ wrap_openai() │ │ stdio / HTTP │
└─────────┬──────────┘ └──────────┬───────────┘
└──────────────┬────────────┘
│
┌──────────▼──────────┐
│ Profiler Engine │
│ LensEvent stream │
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ Profile Store │
│ SQLite · Postgres │
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ Snapshot System │
│ build · export │
│ import · predict │
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ Optimization Engine │
│ pre-select tools │
│ compress schemas │
└─────────────────────┘
SDK Reference
AgentLens facade
from agentlens import AgentLens
lens = AgentLens(
store="sqlite:///agentlens.db", # or "postgresql://..."
model="claude-sonnet-4-6",
)
await lens.init()
# Session context manager
async with lens.session(agent_id="my-agent", task_type="code-review") as sess:
client = lens.wrap_anthropic(session=sess) # Anthropic
client = lens.wrap_openai(session=sess) # OpenAI (pip install agentlens[openai])
interceptor = lens.wrap_mcp(session=sess, source="my-mcp-server")
# Predictive task inference (v3)
task_type = await lens.classify_task(
message="Please review this pull request",
known_task_types=["code-review", "db-query", "deploy"],
)
Snapshot Registry (share snapshots across teams)
from agentlens.snapshot.registry import SnapshotRegistry
# Export
registry = SnapshotRegistry()
registry.add(snapshot)
registry.export("my_snapshots.json")
# Import
registry = SnapshotRegistry.import_from("my_snapshots.json")
snap = registry.get("code-review")
LangChain Integration
from agentlens.integrations.langchain import LangChainLensCallback
cb = LangChainLensCallback(store=store, session_id="my-session")
chain.invoke({"input": "..."}, config={"callbacks": [cb]})
CLI Reference
# Traces
agentlens trace show <session-id>
# Stats
agentlens stats show --last 7d
# Snapshots
agentlens snapshot build <task-type> --min-sessions 5
agentlens snapshot list
agentlens snapshot export <task-type> snapshots.json
agentlens snapshot import snapshots.json
# MCP Proxy
agentlens proxy start --upstream "uvx mcp-server-filesystem /tmp"
agentlens proxy start --upstream "..." --task-type code-review --port 3100
# Dashboard
agentlens dashboard show --refresh 2
Competitive Landscape
| Tool | Observability | Token cost | MCP-aware | Snapshot optimization | Predictive inference |
|---|---|---|---|---|---|
| LangSmith | ✅ | Partial | ❌ | ❌ | ❌ |
| Arize Phoenix | ✅ | Partial | ❌ | ❌ | ❌ |
| Helicone | Partial | ✅ | ❌ | ❌ | ❌ |
| AgentLens | ✅ | ✅ | ✅ | ✅ | ✅ |
Roadmap
| Version | Status | What shipped |
|---|---|---|
| v1 (0.1.0) | ✅ | Profiler engine, LensEvent, SQLiteStore, Anthropic + MCP integrations, CLI basics |
| v2 (0.2.0) | ✅ | MCP proxy server, SnapshotStore, PostgresStore, LangChain integration, live dashboard |
| v3 (0.3.0) | ✅ | Predictive task inference, SnapshotRegistry, OpenAI integration, PyPI publish |
License
MIT
Metadata
Release files for ai-agent-profiler 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_agent_profiler-0.3.0.tar.gz | 28.0 kB | Without provenance | Details for ai_agent_profiler-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_agent_profiler-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for ai_agent_profiler-0.3.0-py3-none-any.whl |
Total release size: 60.7 kB
Release files / ai_agent_profiler-0.3.0.tar.gz
| Download URL | ai_agent_profiler-0.3.0.tar.gz |
|---|---|
| Size | 28.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2e492af9a9c3f1b99b6878da53c533e83e4b26b2253655b2659dd18f99db4f7
|
|
BLAKE2b-256 checksum How to use checksums |
c4069eea4a1101d9f4b503865ef1d5461ae77caee1be2134347a2827f08dd43d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / ai_agent_profiler-0.3.0-py3-none-any.whl
| Download URL | ai_agent_profiler-0.3.0-py3-none-any.whl |
|---|---|
| Size | 32.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f902c722f3ec5d322877807cbb7ba8bcad2f00d2677648cbe2f4b637f709dac
|
|
BLAKE2b-256 checksum How to use checksums |
d200b02a5d3ff7d087c210febcd7a277f50662e45db307b8ee6cd363689dc6b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for ai-agent-profiler 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.