agentmetrics - Python SDK
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
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agentmetrics-0.2.0.tar.gz | 18.8 kB | With provenance | Details for agentmetrics-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agentmetrics-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for agentmetrics-0.2.0-py3-none-any.whl |
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 logRelease 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 logSecurity for agentmetrics 0.2.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for agentmetrics-0.2.0.tar.gz
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 logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.