An open API service indexing awesome lists of open source software.

https://github.com/agentkitai/agentlens

Open-source observability and audit trail platform for AI agents. MCP-native, tamper-evident event logging, real-time dashboard.
https://github.com/agentkitai/agentlens

agent-observability ai-agents ai-safety hono mcp model-context-protocol observability react typescript

Last synced: 3 months ago
JSON representation

Open-source observability and audit trail platform for AI agents. MCP-native, tamper-evident event logging, real-time dashboard.

Awesome Lists containing this project

README

          


๐Ÿ” AgentLens



Open-source observability & audit trail for AI agents



PyPI
npm server
npm mcp
License: MIT
Build Status




๐Ÿ“– Documentation ยท Quick Start ยท Dashboard ยท โ˜๏ธ Cloud

---

## ๐Ÿ“‘ Table of Contents

- [Quick Start](#-quick-start)
- [Architecture](#-architecture)
- [Integration Guides](#-integration-guides)
- [Key Features](#-key-features)
- [Dashboard](#-dashboard)
- [AgentLens Cloud](#-agentlens-cloud)
- [Packages](#-packages)
- [API Overview](#-api-overview)
- [CLI](#-cli)
- [Development](#-development)
- [Contributing](#-contributing)
- [AgentKit Ecosystem](#-agentkit-ecosystem)
- [License](#-license)

---

AgentLens is a **flight recorder for AI agents**. It captures every LLM call, tool invocation, approval decision, and error โ€” then presents it through a queryable API and real-time web dashboard.

**Four ways to integrate โ€” pick what fits your stack:**

| Integration | Language | Effort | Capture |
|---|---|---|---|
| ๐Ÿค– **[OpenClaw Plugin](#-openclaw-plugin)** | [OpenClaw](https://github.com/openclaw/openclaw) | **Copy & enable** | Every Anthropic call โ€” prompts, tokens, cost, tools โ€” zero code |
| ๐Ÿ **[Python Auto-Instrumentation](#-python-auto-instrumentation)** | Python | **1 line** | Every OpenAI / Anthropic / LangChain call โ€” deterministic |
| ๐Ÿ”Œ **[MCP Server](#-mcp-integration)** | Any (MCP) | Config block | Tool calls, sessions, events from Claude Desktop / Cursor |
| ๐Ÿ“ฆ **[SDK](#-programmatic-sdk)** | Python, TypeScript | Code | Full control โ€” log events, query analytics, build integrations |

## ๐Ÿš€ Quick Start

### Docker (recommended)

```bash
git clone https://github.com/agentkitai/agentlens
cd agentlens
cp .env.example .env
docker compose up
# Open http://localhost:3000
```

For production (auth enabled, Stripe, TLS):
```bash
docker compose -f docker-compose.yml -f docker-compose.prod.yml up
```

### Without Docker

```bash
npx @agentlensai/server
# Opens on http://localhost:3400 with SQLite โ€” zero config
```

### Create an API Key

```bash
curl -X POST http://localhost:3400/api/keys \
-H "Content-Type: application/json" \
-d '{"name": "my-agent"}'
```

Save the `als_...` key from the response โ€” it's shown only once. Then head to the [Integration Guides](#-integration-guides) to instrument your agent.

๐Ÿ“– [Full setup guide โ†’](./docs/guide/)

## ๐Ÿ—๏ธ Architecture

```mermaid
graph TB
subgraph Agents["Your AI Agents"]
PY["Python App
(OpenAI, Anthropic, LangChain)"]
MCP_C["MCP Client
(Claude Desktop, Cursor)"]
TS["TypeScript App"]
OC["OpenClaw Plugin"]
end

PY -->|"agentlensai.init()
auto-instrumentation"| SERVER
MCP_C -->|MCP Protocol| MCP_S["@agentlensai/mcp"]
MCP_S -->|HTTP| SERVER
TS -->|"@agentlensai/sdk"| SERVER
OC -->|HTTP| SERVER

subgraph Server["@agentlensai/server"]
direction TB
INGEST[Ingest Engine]
QUERY[Query Engine]
ALERT[Alert Engine]
LLM_A[LLM Analytics]
HEALTH[Health Scoring]
COST[Cost Optimizer]
REPLAY[Session Replay]
BENCH[Benchmark Engine]
GUARD[Guardrails]
end

SERVER --> DB[(SQLite / Postgres)]
SERVER --> DASH["Dashboard
(React SPA)"]

EXT["AgentGate / FormBridge"] -->|Webhook| SERVER
```

## ๐Ÿ”ง Integration Guides

### ๐Ÿค– OpenClaw Plugin

If you're running [OpenClaw](https://github.com/openclaw/openclaw), the AgentLens plugin captures every Anthropic API call automatically โ€” prompts, completions, token usage, costs, latency, and tool calls.

```bash
cp -r packages/openclaw-plugin /usr/lib/node_modules/openclaw/extensions/agentlens-relay
openclaw config patch '{"plugins":{"entries":{"agentlens-relay":{"enabled":true}}}}'
openclaw gateway restart
```

Set `AGENTLENS_URL` if your AgentLens instance isn't on `localhost:3000`. See the [plugin README](./packages/openclaw-plugin/README.md) for details.

### ๐Ÿ Python Auto-Instrumentation

One line โ€” every LLM call captured automatically across **9 providers** (OpenAI, Anthropic, LiteLLM, AWS Bedrock, Google Vertex AI, Google Gemini, Mistral AI, Cohere, Ollama):

```bash
pip install agentlensai[all-providers]
```

```python
import agentlensai

agentlensai.init(
url="http://localhost:3400",
api_key="als_your_key",
agent_id="my-agent",
)
# Every LLM call is now captured automatically
```

**Key guarantees:** โœ… Deterministic ยท โœ… Fail-safe ยท โœ… Non-blocking ยท โœ… Privacy (`init(redact=True)`)

๐Ÿ“– [Python SDK full docs โ†’](./docs/guide/)

### ๐Ÿ”Œ MCP Integration

For Claude Desktop, Cursor, or any MCP client โ€” add to your config:

```json
{
"mcpServers": {
"agentlens": {
"command": "npx",
"args": ["@agentlensai/mcp"],
"env": {
"AGENTLENS_API_URL": "http://localhost:3400",
"AGENTLENS_API_KEY": "als_your_key_here"
}
}
}
}
```

AgentLens ships **12 MCP tools** โ€” 5 core observability, 3 intelligence & analytics, 4 operations. [Full MCP tool reference โ†’](./docs/reference/api.md)

๐Ÿ“– [MCP setup guide โ†’](./docs/guide/)

### ๐Ÿ“ฆ Programmatic SDK

**Python:**
```bash
pip install agentlensai
```
```python
from agentlensai import AgentLensClient
client = AgentLensClient("http://localhost:3400", api_key="als_your_key")
sessions = client.get_sessions()
analytics = client.get_llm_analytics()
```

**TypeScript:**
```bash
npm install @agentlensai/sdk
```
```typescript
import { AgentLensClient } from '@agentlensai/sdk';
const client = new AgentLensClient({ baseUrl: 'http://localhost:3400', apiKey: 'als_your_key' });
const sessions = await client.getSessions();
```

๐Ÿ“– [SDK reference โ†’](./docs/reference/api.md)

## โœจ Key Features

- **๐Ÿ Python Auto-Instrumentation** โ€” `agentlensai.init()` captures every LLM call across 9 providers automatically. Deterministic โ€” no reliance on LLM behavior.
- **๐Ÿ”Œ MCP-Native** โ€” Ships as an MCP server. Works with Claude Desktop, Cursor, and any MCP client.
- **๐Ÿง  LLM Call Tracking** โ€” Full prompt/completion visibility, token usage, cost aggregation, latency measurement, and privacy redaction.
- **๐Ÿ“Š Real-Time Dashboard** โ€” Session timelines, event explorer, LLM analytics, cost tracking, and alerting.
- **๐Ÿ”’ Tamper-Evident Audit Trail** โ€” Append-only event storage with SHA-256 hash chains per session.
- **๐Ÿ’ฐ Cost Tracking** โ€” Track token usage and estimated costs per session, per agent, per model. Alert on cost spikes.
- **๐Ÿšจ Alerting** โ€” Configurable rules for error rate, cost threshold, latency anomalies, and inactivity.
- **โค๏ธโ€๐Ÿฉน Health Scores** โ€” 5-dimension health scoring with trend tracking.
- **๐Ÿ’ก Cost Optimization** โ€” Complexity-aware model recommendation engine with projected savings.
- **๐Ÿ“ผ Session Replay** โ€” Step-through any past session with full context reconstruction.
- **โš–๏ธ A/B Benchmarking** โ€” Statistical comparison of agent variants using Welch's t-test and chi-squared analysis.
- **๐Ÿ›ก๏ธ Guardrails** โ€” Automated safety rules with dry-run mode for safe testing.
- **๐Ÿ”Œ Framework Plugins** โ€” LangChain, CrewAI, AutoGen, Semantic Kernel โ€” auto-detection, fail-safe, non-blocking.
- **๐Ÿ”— AgentKit Ecosystem** โ€” Integrations with [AgentGate](https://github.com/agentkitai/agentgate), [FormBridge](https://github.com/agentkitai/formbridge), [Lore](https://github.com/agentkitai/lore), and [AgentEval](https://github.com/agentkitai/agenteval).
- **๐Ÿ”’ Tenant Isolation** โ€” Multi-tenant support with per-tenant data scoping and API key binding.
- **๐Ÿ  Self-Hosted** โ€” SQLite by default, no external dependencies. MIT licensed.

## ๐Ÿ“ธ Dashboard

AgentLens ships with a real-time web dashboard for monitoring your agents.

๐Ÿ“ธ Dashboard Screenshots (click to expand)

### Overview โ€” At-a-Glance Metrics

![Dashboard Overview](demo/dashboard-overview.jpg)

The overview page shows **live metrics** โ€” sessions, events, errors, and active agents โ€” with a 24-hour event timeline chart, recent sessions with status badges, and a recent errors feed.

### Sessions โ€” Track Every Agent Run

![Sessions List](demo/dashboard-sessions.jpg)

Every agent session with sortable columns: agent name, status, start time, duration, event count, error count, and total cost.

### Session Detail โ€” Timeline & Hash Chain

![Session Detail](demo/dashboard-session-detail.jpg)

Full event timeline with tamper-evident hash chain verification. Filter by event type, view cost breakdown.

### Events Explorer โ€” Search & Filter Everything

![Events Explorer](demo/dashboard-events.jpg)

Searchable, filterable view of every event across all sessions.

### ๐Ÿง  LLM Analytics โ€” Prompt & Cost Tracking

![LLM Analytics](demo/dashboard-llm-analytics.jpg)

Total LLM calls, cost, latency, and token usage across all agents with model comparison.

### ๐Ÿง  Session Timeline โ€” LLM Call Pairing

![LLM Timeline](demo/dashboard-llm-timeline.jpg)

LLM calls in session timeline with model, tokens, cost, and latency.

### ๐Ÿ’ฌ Prompt Detail โ€” Chat Bubble Viewer

![LLM Call Detail](demo/dashboard-llm-detail.jpg)

Full prompt and completion in a chat-bubble style viewer with metadata panel.

### โค๏ธโ€๐Ÿฉน Health Overview โ€” Agent Reliability

![Health Overview](demo/dashboard-health.jpg)

5-dimension health score for every agent with trend tracking.

### ๐Ÿ’ก Cost Optimization โ€” Model Recommendations

![Cost Optimization](demo/dashboard-cost-optimization.jpg)

Analyzes LLM call patterns and recommends cheaper model alternatives with confidence levels.

### ๐Ÿ“ผ Session Replay โ€” Step-Through Debugger

![Session Replay](demo/dashboard-session-replay.jpg)

Step through any past session event by event with full context reconstruction.

### โš–๏ธ Benchmarks โ€” A/B Testing for Agents

![Benchmarks](demo/dashboard-benchmarks.jpg)

Create and manage A/B experiments with statistical significance testing.

### ๐Ÿ›ก๏ธ Guardrails โ€” Automated Safety Rules

![Guardrails](demo/dashboard-guardrails.jpg)

Create and manage automated safety rules with trigger history and activity feed.

## โ˜๏ธ AgentLens Cloud

Don't want to self-host? **AgentLens Cloud** is a fully managed SaaS โ€” same SDK, zero infrastructure:

```python
import agentlensai
agentlensai.init(cloud=True, api_key="als_cloud_your_key_here", agent_id="my-agent")
```

- **Same SDK, one parameter change** โ€” switch `url=` to `cloud=True`
- **Managed Postgres** โ€” multi-tenant with row-level security
- **Team features** โ€” organizations, RBAC, audit logs, usage billing
- **No server to run** โ€” dashboard at [app.agentlens.ai](https://app.agentlens.ai)

๐Ÿ“– [Cloud Setup Guide](./docs/guide/cloud-setup.md) ยท [Migration Guide](./docs/guide/cloud-migration.md) ยท [Troubleshooting](./docs/guide/troubleshooting.md)

## ๐Ÿ“ฆ Packages

### Python (PyPI)

| Package | Description | PyPI |
|---|---|---|
| [`agentlensai`](./packages/python-sdk) | Python SDK + auto-instrumentation for 9 LLM providers | [![PyPI](https://img.shields.io/pypi/v/agentlensai)](https://pypi.org/project/agentlensai/) |

### TypeScript / Node.js (npm)

| Package | Description | npm |
|---|---|---|
| [`@agentlensai/server`](./packages/server) | Hono API server + dashboard serving | [![npm](https://img.shields.io/npm/v/@agentlensai/server)](https://npmjs.com/package/@agentlensai/server) |
| [`@agentlensai/mcp`](./packages/mcp) | MCP server for agent instrumentation | [![npm](https://img.shields.io/npm/v/@agentlensai/mcp)](https://npmjs.com/package/@agentlensai/mcp) |
| [`@agentlensai/sdk`](./packages/sdk) | Programmatic TypeScript client | [![npm](https://img.shields.io/npm/v/@agentlensai/sdk)](https://npmjs.com/package/@agentlensai/sdk) |
| [`@agentlensai/core`](./packages/core) | Shared types, schemas, hash chain utilities | [![npm](https://img.shields.io/npm/v/@agentlensai/core)](https://npmjs.com/package/@agentlensai/core) |
| [`@agentlensai/cli`](./packages/cli) | Command-line interface | [![npm](https://img.shields.io/npm/v/@agentlensai/cli)](https://npmjs.com/package/@agentlensai/cli) |
| [`@agentlensai/dashboard`](./packages/dashboard) | React web dashboard (bundled with server) | private |

## ๐Ÿ”Œ API Overview

| Endpoint | Description |
|---|---|
| `POST /api/events` | Ingest events (batch) |
| `GET /api/events` | Query events with filters |
| `GET /api/sessions` | List sessions |
| `GET /api/sessions/:id/timeline` | Session timeline with hash chain verification |
| `GET /api/analytics` | Bucketed metrics over time |

[Full API Reference โ†’](./docs/reference/api.md)

## โŒจ๏ธ CLI

```bash
npx @agentlensai/cli health # Overview of all agents
npx @agentlensai/cli health --agent my-agent # Detailed health with dimensions
npx @agentlensai/cli optimize # Cost optimization recommendations
```

Both commands support `--format json` for machine-readable output. See `agentlens health --help` for all options.

## ๐Ÿ› ๏ธ Development

```bash
git clone https://github.com/agentkitai/agentlens.git
cd agentlens
pnpm install

pnpm typecheck && pnpm test && pnpm lint # Run all checks
pnpm dev # Start dev server
```

**Requirements:** Node.js โ‰ฅ 20.0.0 ยท pnpm โ‰ฅ 10.0.0

## ๐Ÿค Contributing

We welcome contributions! See **[CONTRIBUTING.md](CONTRIBUTING.md)** for setup instructions, coding standards, and the PR process.

## ๐Ÿงฐ AgentKit Ecosystem

| Project | Description | |
|---------|-------------|-|
| **AgentLens** | Observability & audit trail for AI agents | โฌ…๏ธ you are here |
| [Lore](https://github.com/agentkitai/lore) | Cross-agent memory and lesson sharing | |
| [AgentGate](https://github.com/agentkitai/agentgate) | Human-in-the-loop approval gateway | |
| [FormBridge](https://github.com/agentkitai/formbridge) | Agent-human mixed-mode forms | |
| [AgentEval](https://github.com/agentkitai/agenteval) | Testing & evaluation framework | |
| [agentkit-mesh](https://github.com/agentkitai/agentkit-mesh) | Agent discovery & delegation | |
| [agentkit-cli](https://github.com/agentkitai/agentkit-cli) | Unified CLI orchestrator | |
| [agentkit-guardrails](https://github.com/agentkitai/agentkit-guardrails) | Reactive policy guardrails | |

## ๐Ÿ“„ License

[MIT](LICENSE) ยฉ [Amit Paz](https://github.com/amitpaz)