Skip to main content

Free, open-source observability for AI agents. Trace LLM calls, catch silent failures, score output quality.

Project description

agentdecode

Free, open-source observability SDK for AI agents.

Trace every LLM call, tool invocation, and retrieval step your AI agent makes. Catch silent failures, score output quality automatically, and debug agent pipelines with full visibility.

Installation

pip install agentdecode

Quick Start

from agentdecode import AgentDecode

agent = AgentDecode(
    api_key="al_your_api_key",
    endpoint="https://your-app.vercel.app"
)

# Use as a context manager to group spans into a session
with agent.session("Customer Support Agent") as session:
    with session.span("classify_intent", span_type="llm") as span:
        span.model = "gpt-4o-mini"
        span.input = {"message": "Cancel my subscription"}
        # ... your LLM call here ...
        span.output = {"intent": "cancellation", "confidence": 0.97}
        span.input_tokens = 24
        span.output_tokens = 8
        span.cost_usd = 0.0001

    with session.span("lookup_account", span_type="tool") as span:
        span.input = {"user_id": "usr_9281"}
        # ... your DB call here ...
        span.output = {"plan": "pro", "months_active": 14}

    with session.span("generate_response", span_type="llm") as span:
        span.model = "gpt-4o"
        span.input = {"context": "Pro user, 14 months", "intent": "cancellation"}
        # ... your LLM call here ...
        span.output = {"response": "I understand you'd like to cancel..."}
        span.input_tokens = 85
        span.output_tokens = 120
        span.cost_usd = 0.003

# All spans are sent automatically when the session exits

Nested Spans (Parent-Child)

with agent.session("RAG Pipeline") as session:
    with session.span("orchestrator", span_type="agent") as parent:
        parent.input = {"query": "What is our refund policy?"}

        # Child spans — pass the parent to create hierarchy
        with session.span("search_docs", span_type="retrieval", parent=parent) as s:
            s.input = {"query": "refund policy", "top_k": 5}
            s.output = {"documents": ["doc1", "doc2"], "count": 2}

        with session.span("generate_answer", span_type="llm", parent=parent) as s:
            s.model = "gpt-4o"
            s.input = {"context": ["doc1", "doc2"], "question": "refund policy"}
            s.output = {"answer": "Our refund policy allows..."}

        parent.output = {"answer": "Our refund policy allows..."}

Decorator for Simple Tracing

@agent.trace("classify_intent", span_type="llm")
def classify(message: str) -> dict:
    # Your logic here
    return {"intent": "support", "confidence": 0.95}

# Calling this sends a single-span trace automatically
result = classify("I need help with my order")

Error Tracking

Exceptions inside spans are automatically captured with status: "error" and the exception message stored in error_message. The session is still sent so you can see exactly where things broke.

with agent.session("Risky Pipeline") as session:
    with session.span("flaky_api_call", span_type="tool") as span:
        span.input = {"url": "https://api.example.com/data"}
        response = requests.get("https://api.example.com/data")
        response.raise_for_status()  # If this throws, it's captured
        span.output = response.json()

API Reference

AgentDecode(api_key, endpoint)

Parameter Type Required Description
api_key str Your API key (starts with al_)
endpoint str Your AgentDecode server URL

agent.session(name, session_id=None)

Returns a Session context manager. All spans created inside are batched and sent on exit.

session.span(name, span_type="tool", parent=None)

Returns a Span context manager. Set properties on the span object:

Property Type Description
input any Input data (any JSON-serializable value)
output any Output data (any JSON-serializable value)
model str Model name (e.g. "gpt-4o")
input_tokens int Input token count
output_tokens int Output token count
cost_usd float Cost in USD
error_message str Error description
metadata dict Custom key-value pairs

@agent.trace(name, span_type="agent")

Decorator that wraps a function in a single-span session. The function's arguments are captured as input and the return value as output.

Requirements

  • Python ≥ 3.8
  • Zero external dependencies (uses only Python stdlib)

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

agentdecode-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

agentdecode-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for agentdecode-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39ab4443b1ea530aa637e31121712866dabee70f922791a54f2a36ff1c5ab134
MD5 c0829b0de442ea5d6fee9ab0a193b591
BLAKE2b-256 1aef68a2b634cfec2915dd3d95b55e56fd20f749113c7005cae2e9243d89d264

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for agentdecode-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c891c595b994bbd1827e9f79a7048a5382b424ac4dfda806f92d8b667c809f8c
MD5 1a18c74eabc72629ad43f2c927129c30
BLAKE2b-256 f03e7f542f7699f649320d0be5ae8840d22c9137a120beba5563e08d81e6162b

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