Catalog PyPI
PACKAGE EXPLORERView in registry

agentmetrics-langchain

PyPI

AgentMetrics observability integration for LangChain agents

agentmetricsai-agentslangchainmonitoringobservability
Versions collected1
Direct dependencies3From release 0.2.0
Last observed20 Oct, 22:43 UTC

README

Version 0.2.0 documentation

agentmetrics-langchain

PyPI License: MIT

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)

ParameterDefaultDescription
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:

FieldDescription
statussuccess or failed
duration_msWall-clock chain duration
input_tokens / output_tokensAggregated across all LLM calls in the chain
cache_read_tokens / cache_write_tokensCache token counts (Anthropic)
llm_callsNumber of LLM requests in the chain
tool_calls / tool_errorsTool usage counts
tool_namesSet of tools invoked
modelModel name from the first LLM call
estimated_cost_usdComputed from token counts and model pricing
errorFirst 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

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.2.020 Jun 20263

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
andalabx/agentmetrics

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:43 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:f70239bdbd3a0138bed522d9ff2fe89a6a47d931f2dbc50679deb8486824837f