Skip to main content

Python SDK for AgentLens — observability for AI agents

Project description

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

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

agentlens_sdk-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

agentlens_sdk-0.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file agentlens_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: agentlens_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.5

File hashes

Hashes for agentlens_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 71ecfc846a1bc68276ac0051c24b1224ef4eaebd9d52005ef14520ef7b86567e
MD5 c93a5aefb7740f2190c70503eec3eb71
BLAKE2b-256 7d1512da6e0fa3022361625bda6174384010f5c92b52252efb11f1f2184534ea

See more details on using hashes here.

File details

Details for the file agentlens_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agentlens_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.5

File hashes

Hashes for agentlens_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f341a319aa07ca1659ec849e2beab9a32d88e867cece19ae3f8f709d84cc5000
MD5 03392cf3d823d3401405314d94559f99
BLAKE2b-256 54940ebe0e163f5e1e6c9f6170b53219773437957ca97a5977409f0edbe17020

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