LangChain Agent Executor
LangChain Expression Language
AgentXCallbackHandler instance can be reused across multiple invocations. Pass it via LangChain’s standard config={"callbacks": [...]}; no changes to the chain or agent definition are required.
LangGraph
The same handler covers LangGraph (create_agent / create_react_agent) - pass it in the
invoke config exactly as above. LangGraph runs arrive as a real span tree: each graph node
becomes a child span, and every LLM call, tool call, and retrieval is parented under the node
that ran it, so the trace dialog’s Timeline and Graph views show the actual graph trajectory.
Plumbing runnables (RunnableSequence, ChannelWrite, …) are filtered out automatically.
What gets traced
Each top-level chain invocation produces one trace - a root span plus child spans for graph nodes (LangGraph), LLM calls, tool calls, and retrievals, with real per-step timings. Tool calls are additionally mirrored onto the root’s flattoolCalls list, which the Tool-failure check
and trajectory matching read.
AgentXCallbackHandler reference
Call
tracer.flush() before your process exits in scripts or one-shot jobs.
In long-running servers it is not required: traces drain automatically in the
background.
