Skip to main content

AgentTel Python SDK — AI-native telemetry for Python services

Project description

AgentTel Python SDK

AI-native telemetry SDK for Python services. Full feature parity with the JVM SDK — semantic attributes, baselines, anomaly detection, SLO tracking, GenAI instrumentation, agentic observability, and MCP agent interface.

Installation

pip install agenttel

# With extras
pip install agenttel[fastapi]       # FastAPI middleware + auto-config
pip install agenttel[openai]        # OpenAI instrumentation
pip install agenttel[anthropic]     # Anthropic instrumentation
pip install agenttel[langchain]     # LangChain instrumentation
pip install agenttel[bedrock]       # AWS Bedrock instrumentation
pip install agenttel[agent]         # MCP server (aiohttp)
pip install agenttel[all]           # Everything

Quick Start (FastAPI)

1. Create agenttel.yml

agenttel:
  enabled: true
  topology:
    team: payments
    tier: critical
    domain: fintech
    on-call-channel: "#payments-oncall"
  dependencies:
    - name: postgres
      type: database
      criticality: required
      timeout-ms: 3000
    - name: stripe-api
      type: external_api
      criticality: degraded
      timeout-ms: 5000
      circuit-breaker: true
  operations:
    "[POST /api/transfers]":
      profile: critical-write
      expected-latency-p50: "80ms"
      expected-latency-p99: "300ms"
      expected-error-rate: 0.002
      runbook-url: "https://wiki.example.com/runbooks/transfers"
  profiles:
    critical-write:
      retryable: false
      idempotent: false
      escalation-level: page_oncall
      safe-to-restart: false
  baselines:
    rolling-window-size: 1000
    rolling-min-samples: 10
  anomaly-detection:
    enabled: true
    z-score-threshold: 3.0

2. Instrument Your App

from fastapi import FastAPI
from agenttel.fastapi import instrument_fastapi

app = FastAPI()
engine = instrument_fastapi(app)

@app.post("/api/transfers")
async def create_transfer(request: dict):
    # Your spans automatically get AgentTel enrichment:
    # - topology attributes (team, tier, domain)
    # - operation context (retryable, runbook, escalation)
    # - baseline attributes (P50, P99, error rate)
    # - anomaly detection on span end
    # - SLO budget tracking
    return {"status": "completed"}

3. Use the Decorator

from agenttel.fastapi import agent_operation

@app.get("/api/accounts/{account_id}")
@agent_operation(
    expected_latency_p50="10ms",
    expected_latency_p99="50ms",
    retryable=True,
    runbook_url="https://wiki.example.com/runbooks/get-account",
)
async def get_account(account_id: str):
    return {"id": account_id}

GenAI Instrumentation

from openai import OpenAI
from agenttel.genai import instrument_openai

client = instrument_openai(OpenAI())

# All completions are now traced with:
# - gen_ai.system, gen_ai.request.model
# - gen_ai.usage.input_tokens, gen_ai.usage.output_tokens
# - agenttel.genai.cost_usd
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
)

Anthropic, LangChain, and AWS Bedrock are also supported:

from anthropic import Anthropic
from agenttel.genai import instrument_anthropic, instrument_langchain

client = instrument_anthropic(Anthropic())
instrument_langchain()  # Global LangChain instrumentation

Agentic Observability

from agenttel.agentic import AgentTracer
from agenttel.enums import AgentType, StepType

tracer = (AgentTracer.create()
    .agent_name("incident-responder")
    .agent_type(AgentType.SINGLE)
    .framework("langchain")
    .build())

with tracer.invoke("diagnose high latency") as invocation:
    with invocation.step(StepType.THOUGHT, "analyzing metrics"):
        pass  # reasoning

    with invocation.tool_call("get_service_health") as tool:
        result = {"status": "degraded"}
        tool.set_result(result)

    with invocation.task("check dependencies") as task:
        with task.step(StepType.ACTION, "querying deps"):
            pass

    invocation.complete(goal_achieved=True)

Architecture

agenttel-python/
├── src/agenttel/
│   ├── attributes.py          # Semantic attribute constants
│   ├── enums.py               # All enums (ServiceTier, ErrorCategory, etc.)
│   ├── models.py              # Pydantic data models
│   ├── config.py              # YAML config loader
│   ├── processor.py           # OTel SpanProcessor
│   ├── engine.py              # High-level orchestrator
│   ├── baseline/              # Static, rolling, composite baselines
│   ├── anomaly/               # Z-score anomaly detection + pattern matching
│   ├── slo/                   # SLO tracking with error budgets
│   ├── error/                 # Error classification
│   ├── causality/             # Dependency state tracking
│   ├── topology/              # Service topology registry
│   ├── fastapi/               # FastAPI middleware + decorators
│   ├── genai/                 # OpenAI, Anthropic, LangChain, Bedrock wrappers
│   ├── agent/                 # MCP server, health aggregation, identity
│   └── agentic/               # AgentTracer, scopes, orchestration patterns
└── tests/

Requirements

  • Python 3.11+
  • OpenTelemetry SDK 1.20+
  • Pydantic 2.0+

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

agenttel-0.3.0a1.tar.gz (52.4 kB view details)

Uploaded Source

Built Distribution

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

agenttel-0.3.0a1-py3-none-any.whl (64.3 kB view details)

Uploaded Python 3

File details

Details for the file agenttel-0.3.0a1.tar.gz.

File metadata

  • Download URL: agenttel-0.3.0a1.tar.gz
  • Upload date:
  • Size: 52.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for agenttel-0.3.0a1.tar.gz
Algorithm Hash digest
SHA256 8c9e65299375a28e2d31fd8058e2aab19f5c70dc763aaa983938990a3b399839
MD5 e82f2bc454c17fe2b8ac3017862ba1d6
BLAKE2b-256 ad2058e98fcd6017d3bf8df1b7301c7709c879e6ae58e0047a50bbffa8796ccc

See more details on using hashes here.

File details

Details for the file agenttel-0.3.0a1-py3-none-any.whl.

File metadata

  • Download URL: agenttel-0.3.0a1-py3-none-any.whl
  • Upload date:
  • Size: 64.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for agenttel-0.3.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f0099c1f028df46ad5068e4fd61e1b2329e1726d3814fac5ec8bd5fca7773e2
MD5 c3d1a2170bda6833517f989efcdaed5f
BLAKE2b-256 a66590220f278a4aa45ed282921168618207737933a5ca025ec84a5f9b51f7b5

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