AgentMetrics observability integration for LlamaIndex agents
Project description
agentmetrics-llamaindex
AgentMetrics integration for LlamaIndex. Call instrument() once and every agent run and query engine response reports back to your dashboard showing latency, cost, token counts, tool calls, and errors, via LlamaIndex's native instrumentation API with zero changes to your agent code.
Install
pip install agentmetrics-llamaindex
Quickstart
from agentmetrics_llamaindex import instrument
# Register on the global root dispatcher once at startup
span_handler = instrument(
agent_id="my-llamaindex-agent",
base_url="http://localhost:8099",
)
# Run your agents and query engines as normal
response = agent.chat("Summarize this document")
span_handler.flush()
API
instrument(agent_id, base_url)
Registers AgentMetricsSpanHandler and AgentMetricsEventHandler on the global LlamaIndex root dispatcher. Returns the span handler for flushing.
| Parameter | Default | Description |
|---|---|---|
agent_id |
"llamaindex-agent" |
Fallback label if the agent has no name attribute |
base_url |
"http://localhost:8099" |
AgentMetrics server address |
AgentMetricsSpanHandler
LlamaIndex BaseSpanHandler that tracks top-level agent/engine spans. Emits a run summary on span completion or error.
AgentMetricsEventHandler
LlamaIndex BaseEventHandler that accumulates token counts and tool calls from LLMChatEndEvent, LLMCompletionEndEvent, and AgentToolCallEvent.
.flush(timeout=10.0)
Blocks until all in-flight HTTP requests complete.
What gets tracked
Each top-level agent or query engine span emits one event to /v1/events:
| Field | Description |
|---|---|
status |
success or failed |
duration_ms |
Wall-clock span duration |
input_tokens / output_tokens |
Aggregated across all LLM calls |
cache_read_tokens / cache_write_tokens |
Cache token counts (Anthropic) |
llm_calls |
Number of LLM requests in the span |
tool_calls |
Tool call count from AgentToolCallEvent |
tool_names |
Set of tools invoked |
model |
Model name extracted from raw LLM response |
estimated_cost_usd |
Computed from token counts and model pricing |
error |
First 500 chars of the error message on failure |
The handler detects top-level spans by checking whether the span has no parent and whether the owning instance is an agent, engine, runner, or query object.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentmetrics_llamaindex-0.1.0.tar.gz.
File metadata
- Download URL: agentmetrics_llamaindex-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cd5393443f756b178d7f23d65d17b545b99632db7c8ea0b4a2f2b5c883ba5ba
|
|
| MD5 |
a832c54d02b529f0df8eb627c3f02d3b
|
|
| BLAKE2b-256 |
2cc3aba76a5d8b4b858e0376d152c4f456be033812ea80df578677edc9c68f23
|
File details
Details for the file agentmetrics_llamaindex-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentmetrics_llamaindex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07d6bdcc80c9016fae29206cf68a5aeab573ca4052f54831817200be2bc66e20
|
|
| MD5 |
3d546ef1bdcba752b131ca952d74b1af
|
|
| BLAKE2b-256 |
48b5c860fa6cd4a97aee5bc86722614edd41e5a41e9915deb7dfcfdc47c4791e
|