LangChain
Attach one callback handler and every LLM call, tool invocation, and chain error inside your chain lands in AgentPing. Provider and model are inferred from the model name (Claude / GPT / Gemini / Mistral / Cohere), so multi-provider chains are priced correctly without per-LLM wiring.
The handler resolves the active run automatically: inside with agentping.run(...) (Python) or runScopeAsync (TypeScript) you pass no run argument. Pass the run explicitly to scope to a non-default run.
Install
Python:
pip install "agentping-sdk[langchain]" langchain langchain-openai
TypeScript:
npm install @agentping/sdk langchain @langchain/openai
Quickstart
Python uses AgentPingCallbackHandler:
import agentping
from langchain_openai import ChatOpenAI
agentping.init()
with agentping.run("rag-pipeline"):
llm = ChatOpenAI(
model="gpt-4o-mini",
callbacks=[agentping.AgentPingCallbackHandler()],
)
reply = llm.invoke("summarise this report")
TypeScript uses AgentPingLangChainCallbackHandler:
import * as agentping from "@agentping/sdk";
import { ChatOpenAI } from "@langchain/openai";
agentping.init({ apiKey: process.env.AGENTPING_API_KEY });
const run = agentping.run("rag-pipeline");
await agentping.runScopeAsync(run, async () => {
const llm = new ChatOpenAI({
model: "gpt-4o-mini",
callbacks: [new agentping.AgentPingLangChainCallbackHandler()],
});
await llm.invoke("summarise");
});
await run.finish({ status: "success" });
What's captured
| LangChain callback | AgentPing event | Data |
|---|---|---|
| LLM / chat-model end | llm_call |
provider, model, input/output tokens, latency |
| Tool start | tool_call |
tool name, args preview |
| Chain error | error |
message (truncated) |
| LLM error | llm_call_error |
message (truncated) |
Provider and model are read from the result's llm_output. If a custom LLM does not populate llm_output, the event still lands with provider: "langchain".
Advanced (optional)
Attach the handler at the chain level instead of per-LLM so every link is covered with one handler:
chain = retriever | prompt | llm | parser
with agentping.run("rag-pipeline"):
answer = chain.invoke(
{"question": "what's our policy?"},
config={"callbacks": [agentping.AgentPingCallbackHandler()]},
)
The same config={"callbacks": [...]} pattern attaches the handler to an AgentExecutor or a LangGraph graph.invoke(...) call; tool nodes emit tool_call, LLM nodes emit llm_call.
Source
- Python SDK:
agentping.AgentPingCallbackHandlerin agentping-sdk-python - TypeScript SDK:
agentping.AgentPingLangChainCallbackHandlerin agentping-sdk-typescript