Skip to main content

agentlens-sdk

Python SDK for AgentLens — real-time observability and debugging for AI agents.

Install

pip install agentlens-sdk

With framework extras:

pip install "agentlens-sdk[openai]"
pip install "agentlens-sdk[anthropic]"
pip install "agentlens-sdk[langchain]"
pip install "agentlens-sdk[all]"

Prerequisites

Start the AgentLens server first:

pip install agentlens-server
agentlens-server
# Server running at http://localhost:8766

Then open the dashboard at http://localhost:5173.

Usage

Option 1: Auto-instrument (recommended)

from agentlens_sdk import auto_instrument

auto_instrument()  # patches OpenAI + Anthropic clients automatically

# All subsequent OpenAI/Anthropic calls are traced — no other changes needed
import openai
client = openai.AsyncOpenAI()
response = await client.chat.completions.create(...)

Option 2: @trace decorator

from agentlens_sdk import init, trace

init(server_url="ws://localhost:8766/ws")

@trace(name="my_agent")
async def my_agent(query: str) -> str:
    result = await call_llm(query)
    return result

Option 3: Manual spans

from agentlens_sdk import get_tracer

async def my_agent(query: str) -> str:
    with get_tracer().span("my_agent") as span:
        span.set_attribute("query", query)
        result = await call_llm(query)
        span.set_output(result)
        return result

Framework Integrations

LangChain

from agentlens_sdk.interceptors.langchain_interceptor import AgentLensCallbackHandler

handler = AgentLensCallbackHandler()
chain = my_chain.with_config(callbacks=[handler])

CrewAI

from agentlens_sdk import auto_instrument
auto_instrument()  # CrewAI is auto-detected

AutoGen

from agentlens_sdk import auto_instrument
auto_instrument()  # AutoGen ConversableAgent is auto-detected

Configuration

from agentlens_sdk import init

init(
    server_url="ws://localhost:8766/ws",   # AgentLens server WebSocket URL
    http_url="http://localhost:8766",       # AgentLens server HTTP URL
    session_name="my-agent-v2",            # Optional: name shown in dashboard
)

Design Principles

  • Never raises exceptions — all SDK operations are silent on failure. Your agent always runs.
  • Non-blocking — async, buffered, batch-sent. Adds <5ms overhead per traced call.
  • Auto session management — creates a session on first event, closes it on process exit.
  • Sensitive data redaction — fields named api_key, token, password, secret, authorization are automatically replaced with [REDACTED].
  • Graceful degradation — if the server isn't running, events are silently dropped.

License

MIT

Metadata

Release files for agentlens-sdk 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentlens-sdk 0.2.0
File Size Uploaded Provenance Actions
agentlens_sdk-0.2.0.tar.gz 15.0 kB Without provenance Details for agentlens_sdk-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agentlens-sdk 0.2.0
File Interpreter ABI Platform Actions
agentlens_sdk-0.2.0-py3-none-any.whl Python 3 none any Details for agentlens_sdk-0.2.0-py3-none-any.whl

Total release size: 33.4 kB

Release files / agentlens_sdk-0.2.0.tar.gz

Download URL agentlens_sdk-0.2.0.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f804b972351b56786aa3caef6a37b538a1c8f0fc9ed6bf0ef484471b3b9a0f7d
BLAKE2b-256 checksum
How to use checksums
ada65c20f2da400596017c2ac5450310cd557f1086edf172944982fbe79acf3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.5

Release files / agentlens_sdk-0.2.0-py3-none-any.whl

Download URL agentlens_sdk-0.2.0-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37b08410fb7f31b28eacaedbdaa5a60126cf386799e34103680d2b5b4726b0ec
BLAKE2b-256 checksum
How to use checksums
53945fb9589a8d61da40e7c8df174c591052b0f73d8753e80b47073522e9e374
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.5

Security for agentlens-sdk 0.2.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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page