import type { Metadata } from "next"; import { CodeBlock } from "@/components/code-block"; export const metadata: Metadata = { title: "Python SDK", description: "Full reference for the AgentLens Python SDK: init(), @trace decorator, log_decision(), TraceContext, and configuration.", }; function ApiSection({ name, signature, description, children, }: { name: string; signature: string; description: string; children?: React.ReactNode; }) { return (
{signature}
{description}
{children}The AgentLens Python SDK provides decorators, context managers, and helper functions to instrument your AI agents.
pip install vectry-agentlens
| Parameter | Type | Default | Description |
|---|---|---|---|
| api_key | str | required | Your AgentLens API key (from Dashboard → API Keys) |
| endpoint | str | required | AgentLens server URL |
| flush_interval | float | 5.0 | Seconds between automatic flushes |
| max_batch_size | int | 100 | Max traces per batch request |
| enabled | bool | True | Set to False to disable tracing globally |
| Parameter | Type | Description |
|---|---|---|
| name | str | None | Trace name. Defaults to the function name. |
| tags | list[str] | None | Tags to attach to the trace |
| metadata | dict | None | Arbitrary metadata dict |
| Parameter | Type | Description |
|---|---|---|
| type | str | One of: TOOL_SELECTION, ROUTING, RETRY, ESCALATION, MEMORY_RETRIEVAL, PLANNING, CUSTOM |
| chosen | dict | What was chosen |
| alternatives | list[dict] | What else was considered |
| reasoning | str | None | Why this choice was made |
| context_snapshot | dict | None | Snapshot of context at decision time |
The SDK can also be configured via environment variables. These take
precedence over values passed to init().
| Variable | Description |
|---|---|
| AGENTLENS_API_KEY | API key for authentication |
| AGENTLENS_ENDPOINT | Server URL |
| AGENTLENS_ENABLED | Set to "false" to disable tracing |
| AGENTLENS_FLUSH_INTERVAL | Flush interval in seconds |