Skip to main content

agent-meter

Lightweight Python SDK to track AI agent tool calls, costs, and latency.

Install

pip install agentmeter-obs
# or
pip install dnorio-agent-meter

# From source:
cd sdk/python && python3 -m pip install -e .

Quick Start (60 seconds)

from agent_meter import AgentMeter

# Initialize (picks up AGENT_METER_API_KEY from env)
am = AgentMeter(api_key="am_live_...")

# Track a tool call
span = am.track("web_search", model="gpt-4o")
result = do_web_search(query)
span.finish()

# Track with tokens/cost
span = am.track("code_review", model="claude-sonnet-4-20250514")
span.estimated_input_tokens = 2000
span.estimated_output_tokens = 500
span.usd_cost = 0.012
span.finish()

# Flush happens automatically every 5s, or on exit
# Force flush:
am.flush()

Configuration

Env Variable Description Default
AGENT_METER_API_KEY API key (am_live_...)
AGENT_METER_ENDPOINT Server URL http://localhost:8081
AGENT_METER_IDE IDE identifier python-sdk
AGENT_METER_AGENT Agent name

Or pass directly:

am = AgentMeter(
    api_key="am_live_...",
    endpoint="http://localhost:3000",
    ide="my-custom-agent",
    agent="research-bot",
)

Context Manager

import contextlib

@contextlib.contextmanager
def tracked(am, tool_name, **kwargs):
    span = am.track(tool_name, **kwargs)
    try:
        yield span
    except Exception as e:
        span.finish(ok=False, error=str(e))
        raise
    else:
        span.finish()

# Usage
with tracked(am, "database_query", model="gpt-4o") as span:
    results = db.execute(sql)
    span.estimated_input_tokens = len(sql) // 4

Conversations & Tasks

Group spans into conversations (sessions) and tasks:

span = am.track(
    "generate_code",
    model="claude-sonnet-4-20250514",
    conversation_id="conv-abc123",
    task_id="implement-feature-x",
)

Protocol

The SDK sends spans as OTLP-compatible JSON to POST /v1/traces. This is the same format used by OpenTelemetry, making it compatible with any OTLP collector.

Download files

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

Source Distribution

agentmeter_obs-0.1.4.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

agentmeter_obs-0.1.4-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file agentmeter_obs-0.1.4.tar.gz.

File metadata

  • Download URL: agentmeter_obs-0.1.4.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for agentmeter_obs-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8a9d39e7960977b4c32f172c113999a9f2dd8ed6639c38b8737f6c7c2b3910cd
MD5 464e1a43eeccdb9f933b7c016f0d139a
BLAKE2b-256 51c0b33f16cfed53e0c835e4f4a9e1e205630fa4481f9d5f9f460934928d58a9

See more details on using hashes here.

File details

Details for the file agentmeter_obs-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: agentmeter_obs-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for agentmeter_obs-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0999029f3a77e377a70b05c0b94b198a6af1535425fea907037dd5efe1873812
MD5 40db4aa030a220969e8a3b22a5b09c3a
BLAKE2b-256 e1eb18257a56b3b66a4365cd3a79e043811281afd753fd4a638114723ca7c7c9

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