Skip to main content

Lightweight SDK for tracking AI agent costs and reliability with AgentAxon

Project description

AgentAxon Python SDK

Lightweight SDK for tracking AI agent costs, latency, and reliability with AgentAxon.

Installation

pip install agentaxon

Quick Start

from agentaxon import AgentAxon
import openai
import os

# 1. Initialize (do this once in your app)
ap = AgentAxon(
    api_key=os.environ.get("AGENTAXON_API_KEY"),
    endpoint="https://your-agentaxon-domain.com/api/events" # Your deployed dashboard URL
)

# 2. Wrap any AI call with the @ap.track decorator
@ap.track(provider="openai", agent_name="customer-support-bot")
def ask_bot(question):
    return openai.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": question}]
    )

# 3. Call your function as normal
response = ask_bot("How do I upgrade my plan?")

How it Works

The @ap.track decorator automatically intercepts the response from the LLM provider, extracts the input_tokens and output_tokens, measures the latency, and pushes the event to your AgentAxon dashboard in a background thread so it never slows down your application.

If an exception occurs during the API call, AgentAxon catches it, logs the error against the agent_name, and re-raises the exception.

Supported Providers

  • openai (Extracts tokens from standard OpenAI completions)
  • anthropic (Extracts tokens from standard Anthropic messages)
  • google (Extracts tokens from Gemini GenerationResponse)

Advanced Usage (Manual Tracking)

If you aren't using one of the supported providers or you want to track costs manually, you can use ap.log_event():

ap.log_event(
    provider="custom-llm",
    model="llama-3",
    agent_name="local-agent",
    input_tokens=150,
    output_tokens=45,
    latency_ms=1200,
    status="success"
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

agentaxon-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for agentaxon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c78a4762a4a5cc961c5f3ef4383c34e6b61641348910cae18f9b06d527ead6b
MD5 43fee941a84ad0b37c3b55860b69786b
BLAKE2b-256 e5260faddc540dcdb47ec90cdb107a1a3a27bebf774dc8a47c81a5e969fac872

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