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.
The root span is stamped span kind
agent, and each child span states its
own kind: LLM calls as llm, tool executions as tool, retriever runs as retrieval,
LangGraph nodes as chain.
A chain run invoked inside an active with tracer.trace(...) span does not send an independent
trace - it folds into that span as child spans instead, so an orchestrator wrapping several
chain/agent/retriever calls gets one combined trace.
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.
