Observed since 20 Oct, 22:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
AgentMetrics observability integration for LangChain agents
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.
pip install agentmetrics-langchain
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()
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.
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 |
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]})
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.0 | 20 Jun 2026 | 3 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 22:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:f70239bdbd3a0138bed522d9ff2fe89a6a47d931f2dbc50679deb8486824837f