Skip to main content

Agent Rag Tracing

Agentic RAG (Retrieval Augmented Generation) combines the power of traditional RAG systems with autonomous agents that can make decisions and take actions. While traditional RAG simply retrieves relevant context and generates responses, agentic RAG adds a layer of agency - the ability to break down complex queries into sub-tasks, choose appropriate tools and actions, reason about information from multiple sources, and make decisions about what information is relevant. In this tutorial, you will:
  • Build an agentic RAG app using LlamaIndex’s ReAct agent framework
  • Instrument and trace the agentic RAG app with Phoenix
  • Inspect the trace data in Phoenix to understand the agent’s decision-making process

Notebook Walkthrough

We will go through key code snippets on this page. To follow the full tutorial, check out the notebook above.

Build Query Engine Tools using Chroma

Create the two databases that your agent will use to answer questions using Chroma, a vector database that will store the company policies and employees.

Company Policies Database

Employees Database

Add as Tools

LlamaIndex’s ReAct agent framework allows you to add tools to the agent. Here you’ll add the two tools that will be used to answer questions.

Create ReAct Agent

LlamaIndex provides a ReAct agent framework that allows you to create an agent that can use tools to answer questions. Here you’ll create an agent that can use the two tools you created earlier to answer questions.

Test Your Agent

Now you can test your agent with various queries and see how it uses the tools to gather information and provide comprehensive answers.

View Traces in Phoenix

After running your agent, you can inspect the trace data in Phoenix to understand:
  • How the agent broke down complex queries into sub-tasks
  • Which tools were used and in what order
  • The reasoning process behind the agent’s decisions
  • The quality and relevance of retrieved information
  • Performance metrics and latency
The trace data will show you the complete flow of the agentic RAG system, from initial query processing to final response generation, giving you insights into the agent’s decision-making process and opportunities for optimization. As next steps, you can:
  • Expand the agent’s capabilities by adding more tools (e.g., SQL databases, external APIs)
  • Implement more sophisticated reasoning patterns
  • Add evaluation metrics to measure the agent’s performance
  • Scale the system to handle more complex queries and larger datasets
  • Analyze the trace data to optimize the agent’s decision-making process