Skip to main content

agentmetrics - Python SDK

PyPI Python 3.9+ License: MIT

AgentMetrics Python SDK. Add @agentmetrics.track to any agent function and every run reports back to your dashboard showing latency, cost, token usage, tool calls, and failures, self-hosted with no account required.


Install

pip install agentmetrics

Requires Python 3.9 or later.


Quickstart

import agentmetrics

agentmetrics.configure(base_url="http://localhost:8099")
agentmetrics.instrument()  # auto-patches OpenAI, Anthropic, LiteLLM, and more

@agentmetrics.track(agent_id="my-agent")
def run(task: str) -> str:
    answer = call_llm(task)
    return answer

Every call to run() reports to your dashboard showing duration, cost, token usage, tool calls, and when it failed.


API

agentmetrics.configure()

Call once at startup before any @track decorators execute.

agentmetrics.configure(
    base_url="http://localhost:8099",  # AgentMetrics server address
    environment="production",          # optional, tags every run
    sample_rate=1.0,                   # optional, 0.0 to 1.0
    batch_size=20,                     # optional, events per batch
    flush_interval=2.0,                # optional, seconds between flushes
)

agentmetrics.instrument()

Patches installed LLM SDKs to auto-capture token counts and model names on every call, and is safe to call multiple times.

agentmetrics.instrument()

Supported: OpenAI (+ Azure, Groq, Together AI) · Anthropic · LiteLLM · Google Gemini · Cohere · Mistral · LangChain / LangGraph / CrewAI · LlamaIndex

@agentmetrics.track()

Decorator for sync and async agent functions.

@agentmetrics.track(agent_id="my-agent", metadata={"env": "prod"})
def run(task: str) -> str:
    return call_llm(task)

@agentmetrics.track(agent_id="async-agent")
async def run_async(task: str) -> str:
    return await call_llm_async(task)
Parameter Type Description
agent_id str Identifier shown in the dashboard
metadata dict Optional key-value pairs attached to every run

agentmetrics.step()

Context manager for timing a named phase within a tracked agent.

@agentmetrics.track(agent_id="pipeline")
def run(query: str) -> str:
    with agentmetrics.step("retrieve"):
        docs = vector_search(query)
    with agentmetrics.step("generate"):
        return call_llm(query, docs)

agentmetrics.tool()

Context manager for tracking individual tool calls.

@agentmetrics.track(agent_id="research-agent")
def run(query: str) -> str:
    with agentmetrics.tool("web_search"):
        results = web_search(query)
    return summarize(results)

agentmetrics.score()

Attaches a named evaluation score to the current run. Call from inside a @track function.

@agentmetrics.track(agent_id="my-agent")
def run(task: str) -> str:
    answer = call_llm(task)
    agentmetrics.score("relevance", 0.92)
    return answer

agentmetrics.flush()

Blocks until all queued events are sent. Call before process exit in scripts.

agentmetrics.flush(timeout=10.0)

agentmetrics.trace_id

Returns the active trace ID from inside a tracked function.

@agentmetrics.track(agent_id="my-agent")
def run(task: str) -> str:
    print(agentmetrics.trace_id)  # e.g. "a3f1c2d4-..."
    return call_llm(task)

License

MIT

Metadata

Release files for agentmetrics 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentmetrics 0.2.0
File Size Uploaded
agentmetrics-0.2.0.tar.gz 18.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentmetrics 0.2.0
File Interpreter ABI Platform
agentmetrics-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.8 kB

Release files / agentmetrics-0.2.0.tar.gz

Download URL agentmetrics-0.2.0.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d2f24605bf78a27e384706591c3d95ebb033ee53c521f42824b41962d83c7c5a
BLAKE2b-256 checksum
How to use checksums
dce93125767ef4a0a56d6c7b822bffb8fdc0d7ad5dd7107ef852e083a9a379a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 20, 2026.

Transparency log

Release files / agentmetrics-0.2.0-py3-none-any.whl

Download URL agentmetrics-0.2.0-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
840f565ab301dcc6a5ad1f4b5af998fc637c1303a6ad9df086a9a7c0a1b92960
BLAKE2b-256 checksum
How to use checksums
452e4c328c5cb58ef750f6da67fc40934d0fe4c70f029737ee048e5d0519c985
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page