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.2.0.tar.gz (15.0 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.2.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentlens_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 15.0 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.2.0.tar.gz
Algorithm Hash digest
SHA256 f804b972351b56786aa3caef6a37b538a1c8f0fc9ed6bf0ef484471b3b9a0f7d
MD5 7a8e95c39d9674698e4c8c4d047a0c19
BLAKE2b-256 ada65c20f2da400596017c2ac5450310cd557f1086edf172944982fbe79acf3e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentlens_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37b08410fb7f31b28eacaedbdaa5a60126cf386799e34103680d2b5b4726b0ec
MD5 ab5220b7e9473e38abbb247200ec0fc7
BLAKE2b-256 53945fb9589a8d61da40e7c8df174c591052b0f73d8753e80b47073522e9e374

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