agentmetrics-langchain
AgentMetrics integration for LangChain. Pass one callback to any chain or agent .invoke() call and every run reports back to your dashboard showing latency, cost, token counts, tool calls, and errors, with no changes to your agent logic.
Install
pip install agentmetrics-langchain
Quickstart
from agentmetrics_langchain import AgentMetricsCallback
cb = AgentMetricsCallback(
agent_id="my-langchain-agent",
base_url="http://localhost:8099",
)
result = agent.invoke(
{"input": "What is the weather in Paris?"},
config={"callbacks": [cb]},
)
cb.flush()
API
AgentMetricsCallback(agent_id, base_url)
| Parameter | Default | Description |
|---|---|---|
agent_id |
"langchain-agent" |
Label shown in the dashboard |
base_url |
"http://localhost:8099" |
AgentMetrics server address |
The callback is a BaseCallbackHandler. Pass it via config={"callbacks": [cb]} on any chain or agent .invoke() call. It tracks the top-level chain only, with nested sub-chains aggregated into the same run.
Supports both OpenAI-style and Anthropic-style token counting from usage_metadata and llm_output.
.flush(timeout=10.0)
Blocks until all in-flight HTTP requests complete. Call before process exit in scripts.
What gets tracked
Each top-level chain invocation emits one event to /v1/events on completion or error:
| Field | Description |
|---|---|
status |
success or failed |
duration_ms |
Wall-clock chain duration |
input_tokens / output_tokens |
Aggregated across all LLM calls in the chain |
cache_read_tokens / cache_write_tokens |
Cache token counts (Anthropic) |
llm_calls |
Number of LLM requests in the chain |
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 |
LangGraph
The callback works with LangGraph graphs the same way:
from langgraph.graph import StateGraph
from agentmetrics_langchain import AgentMetricsCallback
cb = AgentMetricsCallback(base_url="http://localhost:8099")
app = build_graph().compile()
result = app.invoke(state, config={"callbacks": [cb]})
License
Metadata
Release files for agentmetrics-langchain 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_langchain-0.2.0.tar.gz | 5.0 kB | Without provenance | Details for agentmetrics_langchain-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agentmetrics_langchain-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for agentmetrics_langchain-0.2.0-py3-none-any.whl |
Total release size: 10.5 kB
Release files / agentmetrics_langchain-0.2.0.tar.gz
| Download URL | agentmetrics_langchain-0.2.0.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66ddabf0ba7fb82ce118cb36772f07278081964c39b89480036f3895502992fa
|
|
BLAKE2b-256 checksum How to use checksums |
0965357a9ae455276536228432bb765bf6f149782f3513ad88b4dfd56a8877aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / agentmetrics_langchain-0.2.0-py3-none-any.whl
| Download URL | agentmetrics_langchain-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8508e5f191f28ffa5750d9bad2ca91659739b6652d5ae2761352ad1a6cb045d4
|
|
BLAKE2b-256 checksum How to use checksums |
b21adca6bfa3133acee424cb05a4d7d7a3cfce5734167d4e9fe3a372c66483ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for agentmetrics-langchain 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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.