Skip to main content

AgentMetrics observability integration for Claude Managed Agents

Project description

agentmetrics-anthropic

PyPI License: MIT

AgentMetrics integration for Claude Managed Agents (Python). Wrap your session event stream with one tracker and every session reports back to your dashboard when it terminates showing latency, cost, token counts with cache, tool calls, and errors.


Install

pip install agentmetrics-anthropic

Quickstart

import anthropic
from agentmetrics_anthropic import AgentMetricsSessionTracker

client  = anthropic.Anthropic()
tracker = AgentMetricsSessionTracker(
    agent_id="my-claude-agent",
    base_url="http://localhost:8099",
)

# Sync stream
with tracker.stream(client, session_id="sess_...") as stream:
    for event in stream:
        pass  # handle events as normal

tracker.flush()

Async

async with tracker.astream(client, session_id="sess_...") as stream:
    async for event in stream:
        pass

await tracker.flush()

API

AgentMetricsSessionTracker(agent_id, base_url)

Parameter Default Description
agent_id "anthropic-agent" Label shown in the dashboard
base_url "http://localhost:8099" AgentMetrics server address

.stream(client, session_id, **kwargs)

Returns a sync context manager. Yields the same events as client.beta.sessions.events.stream(). Emits a run summary on session.status_terminated.

.astream(client, session_id, **kwargs)

Async version of .stream().

.flush(timeout=10.0)

Blocks until all in-flight HTTP requests complete. Call before process exit.


What gets tracked

Each session emits one event to /v1/events when it terminates:

Field Description
status success or failed
duration_ms Wall-clock session duration
input_tokens / output_tokens Aggregated across all LLM calls
cache_read_tokens / cache_write_tokens Cache token counts
llm_calls Number of LLM requests in the session
tool_calls / tool_errors Tool usage counts
tool_names Set of tools invoked
model Model name from the first LLM call
estimated_cost_usd Computed from token counts and model pricing
error First 500 chars of the error message on failure

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

agentmetrics_anthropic-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

agentmetrics_anthropic-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for agentmetrics_anthropic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ad02878e9132d634f3382c3687fda9c286f4e10677099c8d2a6dddeaac2dc27b
MD5 fd65fdc1bc7d07a760693b85b6b790da
BLAKE2b-256 692b3b6386f33de3f8b0a8141bc7a82f669e6f5850c3fd9bee7f8c0bd076f048

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agentmetrics_anthropic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d77605b429efdcf509333a610fd75afb897a96adf7fb1ca5d3581bc42cebc907
MD5 c5d7c39dd995bf18fb4a9f66d74c225c
BLAKE2b-256 800968d0e3117cf8d8df314091fa929113b9a9d2f1f7c7de065490f8a974de4b

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