Skip to main content
Glama

AgentLens

πŸ”­ AgentLens

Open-source observability and evaluation platform for AI agents. Trace every step of your agent, score its behavior with LLM-as-judge evaluations, catch prompt regressions in CI, and give your coding agents (Claude Code, Cursor, etc.) native access to run history via MCP.

CI Python License Code style: ruff

Zero-config by default. One SQLite file, one lens serve command, done. Scale to Postgres when you need to.


Why AgentLens?

Everyone is shipping agents now. Almost nobody knows what their agents actually do in production: which tools they call, what the LLM sees, how much it costs, and β€” crucially β€” whether yesterday's prompt change made the agent worse.

AgentLens brings the discipline of classical observability (traces, spans, cost accounting) and classical QA (regression suites, semantic scoring) to the agent world, in a single lightweight package with no infrastructure requirements.

Pain point

AgentLens answer

"Which tool call blew up my agent's latency?"

Auto-nested async span traces via @agent, @tool, @llm decorators

"Is this prompt actually better than v2.3.1?"

Prompt regression suites with keyword + semantic checks, CI-gated

"How do I know the agent did a good job?"

LLM-as-judge evaluations with configurable rubrics

"What did that run cost me?"

Per-span token counting (tiktoken) and cost estimation

"I want my coding agent to look at run history"

Built-in MCP server, pluggable into Claude Code / Cursor

Related MCP server: LangSmith MCP Server

Quick start

pip install agentlens

# 1. Start the server + dashboard
lens serve            # β†’ http://localhost:3368

# 2. Run the traced demo agent
lens demo

# 3. Run evaluations and regression suites
lens regression init my_suite.yml
lens regression run my_suite.yml

Instrument your agent (30 seconds)

from agentlens.sdk import agent, tool, llm
from agentlens.evals import evaluate
from agentlens.regression import load_suite, run_suite

@llm(model="gpt-4o-mini")
async def answer(question: str) -> str:
    # your LLM call here β€” tokens and cost are tracked automatically
    ...

@tool("search_index")
async def search_index(query: str) -> list[str]:
    ...

@agent("rag_agent")
async def rag_agent(question: str) -> str:
    ctx = await search_index(question)
    return await answer(f"Context: {ctx}\nQuestion: {question}")

# Span tree, parent-child nesting and cost β€” all automatic.
result = await rag_agent("How do I reset my password?")

Features

🧭 Tracing SDK

Drop-in decorators (@agent, @tool, @llm, @retriever) that build a full span tree with automatic parent-child nesting through contextvars. Works for both async and synchronous functions. Each span records input/output, model, token counts, estimated cost (using real per-model pricing for OpenAI and Anthropic models, with an extensible registry for your own models) and status. Spans are flushed to the AgentLens API through a pluggable callback, so you can persist them, export them to OTLP, or mock them in tests.

πŸ§‘β€βš–οΈ LLM-as-judge evaluations

Score agent outputs against built-in criteria (CORRECTNESS, RELEVANCE, COHERENCE, SAFETY, HALLUCINATION, COMPLETENESS) or define your own rubric. The judge is any OpenAI-compatible endpoint β€” OpenAI, Anthropic gateways, Ollama, LiteLLM β€” configured with two environment variables. Every case x criterion pair produces a numeric score, a human-readable reason, and a pass/fail verdict, aggregated into an evaluation report.

πŸ›‘οΈ Prompt regression suites

YAML-defined test suites, the way prompt engineers have been wishing for:

name: support-agent
agent: support_agent
model: gpt-4o-mini
version: "1.2.0"

cases:
  - name: refund question
    input: "When will I receive my refund?"
    expected_contains: ["refund", "days"]
    expected_not_contains: ["deny"]
    min_score: 0.8
    tags: ["billing"]

lens regression run suite.yml executes every case, applies keyword checks plus optional semantic scoring, and exits non-zero on failure β€” perfect for CI. Compare versions side by side in the dashboard.

πŸ’° Cost tracking

Token counting via tiktoken (exact for OpenAI encoders, character-ratio fallback for unknown models), per-model pricing registry, and aggregated cost summaries across runs. Know exactly what your agent fleet spends.

πŸ€– Native MCP server

AgentLens ships as a proper MCP server (mcp server), exposing four tools:

Tool

Purpose

lens_search_runs

Find recent agent runs, filter by project

lens_run_summary

Full summary + span tree of a run

lens_eval_latest

Latest LLM-as-judge evaluation results

lens_regression_status

Latest regression report

Wire it into your favorite coding agent and let it debug your production agents for you:

// ~/.config/claude/claude_desktop_config.json
{
  "mcpServers": {
    "agentlens": {
      "command": "lens",
      "args": ["mcp-server"]
    }
  }
}

πŸ“Š REST API + dashboard

A FastAPI application (/v1/spans, /v1/runs, /v1/evals, /v1/regressions, /v1/summary) with OpenAPI docs at /docs, plus a dark-themed embedded dashboard with run tables, interactive span trees, evaluation results, and regression history. SQLite zero-config by default; flip to Postgres with LENS_STORAGE_BACKEND=postgres.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   decorators   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   flush   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Your code β”‚ ─────────────► β”‚ Tracing SDK  β”‚ ───────►  β”‚  AgentLens API   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚  (FastAPI)       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   run      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚                  β”‚
β”‚  YAML      β”‚ ─────────► β”‚ Regression runnerβ”‚ ──┐       β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  suites    β”‚            β”‚ (+ keyword/sem.) β”‚   β”‚       β”‚  β”‚ Dashboard / β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚       β”‚  β”‚ MCP server  β”‚ β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   evaluate β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚       β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚  Test casesβ”‚ ─────────► β”‚ LLM-as-judge     β”‚ β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β–Ίβ””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚                β”‚
                                                 β”‚         β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
                                                 └────────►│ SQLite /    β”‚
                                                           β”‚ Postgres    β”‚
                                                           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

CLI reference

Command

Description

lens serve

Start API + dashboard (default port 3368)

lens mcp-server

Run the MCP server over stdio

lens regression run <file>

Run a regression suite (exits non-zero on failure)

lens regression init <file>

Scaffold a regression suite

lens demo

Run a traced demo agent, print the span tree

Configuration happens through LENS_ environment variables or a .env file (LENS_PORT, LENS_STORAGE_BACKEND, LENS_DATABASE_URL, LENS_JUDGE_MODEL, LENS_JUDGE_BASE_URL, LENS_JUDGE_API_KEY, ...). See agentlens/core/settings.py for the full list.

Docker

docker compose up --build
# β†’ http://localhost:3368

Development

git clone https://github.com/Nexus-universe-space/agentlens.git
cd agentlens
pip install -e ".[dev]"

ruff check agentlens tests examples     # lint
ruff format agentlens tests examples    # format
pytest tests/unit tests/integration     # 41 tests
mypy agentlens                          # strict-ish typing

CI runs lint, tests (Python 3.10–3.13 with coverage), and typing on every push and PR.

Project layout

agentlens/
β”œβ”€β”€ agentlens/
β”‚   β”œβ”€β”€ api/        FastAPI REST API (spans, runs, evals, regressions, summary)
β”‚   β”œβ”€β”€ cli/        Click CLI (serve, mcp-server, regression, demo)
β”‚   β”œβ”€β”€ core/       Settings, Pydantic models, token/cost engine
β”‚   β”œβ”€β”€ evals/      LLM-as-judge evaluation engine
β”‚   β”œβ”€β”€ mcp/        MCP server with typed tools
β”‚   β”œβ”€β”€ regression/ YAML suite loader + regression runner
β”‚   β”œβ”€β”€ sdk/        Tracing decorators (agent / tool / llm / retriever)
β”‚   β”œβ”€β”€ storage/    Async SQLAlchemy store (SQLite + Postgres)
β”‚   └── web/        Embedded React dashboard (zero build step)
β”œβ”€β”€ tests/          41 tests β€” unit + integration (SQLite, API, MCP)
β”œβ”€β”€ examples/       Traced RAG agent + sample regression suite
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
└── .github/workflows/ci.yml

Roadmap

  • OTLP trace exporter (Honeycomb, Grafana Tempo, Jaeger)

  • Multi-agent session grouping and conversation views

  • Real-time WebSocket updates in the dashboard

  • Evaluation presets per domain (coding, RAG, customer support)

  • Human-in-the-loop annotation of eval cases

  • Prompt version diffing with blame attribution

Contributing

Contributions are very welcome! Please read CONTRIBUTING.md for the workflow, and review our Code of Conduct.

License

MIT β€” see LICENSE.

A
license - permissive license
-
quality - not tested
C
maintenance

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    B
    quality
    D
    maintenance
    Enables AI assistants to query and analyze AI agent sessions from observability providers like Shepherd (AIOBS) and Langfuse, allowing users to debug agent runs, compare sessions, track performance, and analyze LLM usage patterns.
    18
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    Enables language models to access LangSmith observability platform features including fetching conversation history, managing prompts, retrieving traces and runs, working with datasets and examples, and analyzing experiments.
    13
    131
    MIT
  • F
    license
    B
    quality
    D
    maintenance
    Provides AI agents with access to file metadata, vector search, and workflow metrics. It enables operations such as file metadata retrieval and semantic search over file embeddings using pgvector.
    3

View all related MCP servers

Related MCP Connectors

  • Give your agent web search and authoritative datasets: S&P Global, FRED, OECD, SimilarWeb & more.

  • Give your agent live data from Twitter, Reddit, the web and GitHub. No API keys, no scraping stack.

  • AI agent run monitoring with incident replay and SLA receipts.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Nexus-universe-space/agentlens'

If you have feedback or need assistance with the MCP directory API, please join our Discord server