Usage
RegisterAgentXLlamaIndexHandler on LlamaIndex’s global Settings.callback_manager (or scope it to a single query engine / agent). Every subsequent top-level query() / chat() / retrieve() call - including its nested retrieval and LLM steps - is traced automatically.
Settings:
Building the index itself (
VectorStoreIndex.from_documents(...)) is not
traced - only real query/chat/retrieve/agent-step calls produce a trace.
Node parsing, chunking, and embedding events fired during index construction
are intentionally not sent to AgentX.What gets traced
Each top-level call produces one trace: aquery()/chat() call, an agent step, or - if you call a retriever or LLM directly with no query engine wrapping it - that bare call itself.
LlamaIndex’s
CallbackManager.start_trace(trace_id) reuses a fixed
operation-name string ("query", "chat", …) rather than a unique id per
call, so AgentXLlamaIndexHandler doesn’t key state on it - it walks the
real event_id/parent_id chain instead, which stays correct under
concurrent calls in the same process.AgentXLlamaIndexHandler 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.
