Skip to main content

AgentLens: local-first diagnostics & observability for AI agents. Answers 'Why did my agent behave this way?' with one line and a single SQLite file.

Project description

AgentLens

Local-first diagnostics & observability for AI agents. One line to integrate, a single SQLite file, a built-in dashboard. AgentLens answers the question other tools don't:

Why did my agent behave this way?

Not a prompt tracker. Not a token dashboard. A diagnostics platform for agent behavior — tool usage, memory access, workflow paths, decisions, failures, retries, latency, and cost.

pip install pyagentlens               # core: store + dashboard + manual API + auto-patch
pip install "pyagentlens[langchain]"  # framework adapters as extras (langgraph, crewai, …)
pip install "pyagentlens[all]"        # every adapter

Package name on PyPI is pyagentlens; the import name is agentlens.

from agentlens import monitor
monitor.start()          # auto-patches installed LLM SDKs — that's it

Full docs: see Guide.md — in-depth reference for humans and AI coding agents (when-to-use-what tables, every API signature, per-framework snippets, troubleshooting, and an agent cheat sheet).

agentlens ui             # dashboard at http://127.0.0.1:7180

No server to deploy. No cloud. No external services. Data lives in a hidden ./.agentlens/agentlens.db (SQLite, WAL).


Three ways to instrument (mix freely)

1. Zero-config auto-patch

monitor.start() detects and patches whatever is installed — OpenAI, Anthropic, Google Gemini, Groq, LiteLLM — so every LLM call becomes an llm span with tokens and cost, with no code changes.

2. Manual (framework-agnostic, always available)

import agentlens
agentlens.init(project="research-bot")

with agentlens.trace_session("chat"):
    with agentlens.trace_agent("planner", role="lead"):
        agentlens.log_decision(options=["search", "answer"], chosen="search", reason="needs fresh info")
        agentlens.log_memory("read", "user_prefs", hit=True)
        agentlens.log_tool("web_search", args={"q": "ai news"}, result=[...], retry_count=1)
        agentlens.log_llm(model="gpt-4o", input_tokens=1200, output_tokens=400)

A tool/LLM logged with an error= (or a trace_* block that raises) is automatically recorded as a failure.

3. Framework adapters

Framework Import Maturity
LangChain agentlens.adapters.langchain.AgentLensCallbackHandler full
LangGraph agentlens.adapters.langgraph.AgentLensCallbackHandler full (LangChain callbacks)
LlamaIndex agentlens.adapters.llamaindex.AgentLensLlamaHandler full
CrewAI agentlens.adapters.crewai (step_callback, instrument_tools) best-effort
AutoGen agentlens.adapters.autogen.instrument_agent best-effort
PydanticAI agentlens.adapters.pydanticai.instrument_agent best-effort
OpenAI Agents SDK agentlens.adapters.openai_agents.install best-effort
Strands Agents agentlens.adapters.strands.callback_handler best-effort
Anthropic Agent SDK agentlens.adapters.anthropic_agents.traced_async_tool tool-level
MCP agentlens.adapters.mcp.instrument_server / traced_tool tool-level
FastMCP agentlens.adapters.fastmcp.instrument_server tool-level

Plus a universal agentlens.adapters.wrap_tool(fn) / @traced_tool() that works with any framework or none.


The dashboard

  • Overview — runs, success/failure rate, cost, p50/p95 latency.
  • Runs → Run detail — the workflow execution graph (span tree: session → workflow → agent → tool/memory/llm/decision), click any node to inspect.
  • Agent Explorer — runs, failures, latency, and attributed cost per agent.
  • Tool Explorer — most used / slowest / most failed tools, retries.
  • Memory Explorer — reads/writes/updates/deletes and read hit-rate.
  • Failure Explorer — exceptions, messages, retries, jump to the failing run.
  • Cost Explorer — token usage, cost by day, by model, most expensive agents.

Try it now (no keys needed)

pip install -e .
python examples/demo_agent.py
agentlens ui

Design

Local-first, zero-config, framework-agnostic, async-safe. Observability code never crashes your app (emit failures are swallowed). One Span model covers every event; kind-specific data lives in attributes. Cost is computed from an editable price book (agentlens/server/pricing.py).

CLI: agentlens ui [--port 7180] [--host] [--backend-store-uri PATH], agentlens providers, agentlens version. Override the port with AGENTLENS_PORT.

Single process writes straight to local SQLite. For multiple processes/workers sharing one dashboard, run agentlens ui once and point each worker at it: agentlens.init(project=..., tracking_uri="http://127.0.0.1:7180").

See Guide.md for the complete reference.

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

pyagentlens-0.1.1.tar.gz (56.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyagentlens-0.1.1-py3-none-any.whl (64.9 kB view details)

Uploaded Python 3

File details

Details for the file pyagentlens-0.1.1.tar.gz.

File metadata

  • Download URL: pyagentlens-0.1.1.tar.gz
  • Upload date:
  • Size: 56.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pyagentlens-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2e3c2bfc28c0459a2ef27a582d0551188c36c4965b3d6985afc887905abdfe83
MD5 109015e5a7e3bf6ee20b2d619e4069d5
BLAKE2b-256 b9ac59d2b5964fc3f5aa9f621b915d10f82dcb6b8e43ad3687f26f473d24e561

See more details on using hashes here.

File details

Details for the file pyagentlens-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyagentlens-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 64.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pyagentlens-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16fee7f4fd1255e59baa3e9c920dc0676bcf6930e1a80838de541e855aa2b2b9
MD5 6c66233a91ffaf53615d66c0478b2cda
BLAKE2b-256 ed8ba4076f30df42b148c9e1c6c116712e43287b47c6f444fa6a092d63b72653

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page