SDK Setup
Wire the PulseAgent LangChain callback handler in two minutes.
Pipes every LangChain run into the PulseAgent dashboard as a parent + child trace tree. Costs, latencies, and failures show up in real time, no extra widgets to wire into your app.
1. Install
pip install pulseagent
2. Initialize (Python / LangChain)
Instantiate the handler once per process, then pass it to config={"callbacks": [handler]} on every .invoke() call. PulseAgentLangChainHandler is a BaseCallbackHandler subclass that auto-emits a parent + child trace tree as LangChain walks the chain.
import os
from langchain_openai import OpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from pulseagent import PulseAgentLangChainHandler
# PulseAgent auto-emits a parent + child trace tree on every callback.
handler = PulseAgentLangChainHandler(
api_key=os.environ["PULSEAGENT_API_KEY"],
backend_url=os.environ.get("PULSEAGENT_BACKEND_URL", "https://pulseagent-7.polsia.app"),
agent_name="my_langchain_agent",
)
agent = AgentExecutor(agent=create_openai_tools_agent(llm=OpenAI(), tools=[], prompt=None), tools=[])
result = agent.invoke(
{"input": "What is the capital of France?"},
config={"callbacks": [handler]},
)
handler.flush() # wait for trace posts to drain before process exit
3. Node / TypeScript
The TypeScript SDK has no CallbackHandler class — the equivalent is the @instrument decorator, which writes one execution event per call. Reads PULSEAGENT_API_KEY from env.
import { registerKey, instrument, flush } from "pulseagent";
// Register the API key with the backend once per process.
await registerKey({ name: "production" });
export const researcher = instrument({
agentName: "researcher",
model: "gpt-4o",
})(
async function researcher(query: string) {
const r = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: query }],
});
return r;
}
);
// Call before process exit to avoid dropping events.
process.on("SIGTERM", async () => { await flush(); process.exit(0); });
4. Verify it works
Run any LangChain AgentExecutor.invoke with the handler attached, then open the dashboard trace view to confirm the tree appears.
import os
from langchain_openai import OpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.tools import tool
from pulseagent import PulseAgentLangChainHandler
@tool
def add(a: int, b: int) -> int: return a + b
handler = PulseAgentLangChainHandler(api_key=os.environ["PULSEAGENT_API_KEY"])
agent = AgentExecutor(
agent=create_openai_tools_agent(llm=OpenAI(), tools=[add], prompt=None),
tools=[add],
)
agent.invoke({"input": "What is 2 + 3?"}, config={"callbacks": [handler]})
handler.flush()
# -> Click "Open Funnel tab ->" below to see the trace tree.