7 Agentic RAG System Architectures to Build AI Agents

Pankaj Singh Last Updated : 07 Jan, 2025
27 min read

For me, 2024 has been a year when I was not just using LLMs for content generation but also understanding their internal working. In this quest to learn about LLMs, RAG and more, I discovered the potential of AI Agents—autonomous systems capable of executing tasks and making decisions with minimal human intervention. Going back to 2023, Retrieval-Augmented Generation (RAG) was in the limelight, and 2024 advanced with Agentic RAG workflows, driving innovation across industries. Looking ahead, 2025 is set to be the “Year of AI Agents,” where autonomous systems will revolutionize productivity and reshape industries, unlocking unprecedented possibilities with the Agentic RAG Systems.

These workflows, powered by autonomous AI agents capable of complex decision-making and task execution, enhance productivity and reshape how individuals and organisations tackle problems. The shift from static tools to dynamic, agent-driven processes has unlocked unprecedented efficiencies, laying the groundwork for an even more innovative 2025. Today, we will talk about the types of Agentic RAG systems. In this guide, we will go through the architecture of types of Agentic RAG and more. 

Agentic RAG System: Combination of RAG and Agentic AI Systems

To simply understand Agentic RAG, let’s dissect the term: It is the amalgamation of RAG + AI Agents. If you don’t know these terms, don’t worry! We will be diving into them shortly.

Now, I will shed light on both RAG and Agentic AI systems (AI Agents)

What is RAG (Retrieval-Augmented Generation)?

Agentic RAG System:
Source: Author

RAG is a framework designed to enhance the performance of generative AI models by integrating external knowledge sources into the generative process. Here’s how it works:

  • Retrieval Component: This part fetches relevant information from external knowledge bases, databases, or other data repositories. These sources can include structured or unstructured data, such as documents, APIs, or even live data streams.
  • Augmentation: The retrieved information is used to inform and guide the generative model. This ensures the outputs are more factually accurate, grounded in external data, and contextually rich.
  • Generation: The generative AI system (like GPT) synthesizes the retrieved knowledge with its own reasoning capabilities to produce final outputs.

RAG is particularly valuable when working with complex queries or domains requiring up-to-date, domain-specific knowledge.

What are AI Agents?

AI AGENT WORKFLOW
Source: Dipanjan Sarkar

Here’s the AI Agent Workflow responding to the query: “Who won the Euro in 2024? Tell me more details!”.

  1. Initial Instruction Prompt: The user inputs a query, such as “Who won the Euro in 2024? Tell me more details!”.
  2. LLM Processing and Tool Selection: The Large Language Model (LLM) interprets the query and decides if external tools (like web search) are needed. It initiates a function call for more details.
  3. Tool Execution and Context Retrieval: The selected tool (e.g., a search API) retrieves relevant information. Here, it fetches details about the Euro 2024 final.
  4. Response Generation: The new information is combined with the original query. The LLM generates a complete and final response:
    “Spain won the Euro 2024 against England with a score of 2–1 in the Final in Berlin on July 2024.”

In a nutshell, an Agentic AI System has the following core components:

Large Language Models (LLMs): The Brain of the Operation

LLMs serve as the central processing unit, interpreting input and generating meaningful responses.

  • Input Query: A user-provided question or command that initiates the AI’s operation.
  • Understanding the Query: The AI analyzes the input to grasp its meaning and intent.
  • Response Generation: Based on the query, the AI formulates an appropriate and coherent reply.

Tools Integration: The Hands That Get Things Done

External tools enhance the AI’s functionality to perform specific tasks beyond text-based interactions.

  • Document Reader Tool: Processes and extracts insights from text documents.
  • Analytics Tool: Performs data analysis to provide actionable insights.
  • Conversational Tool: Facilitates interactive and dynamic dialogue capabilities.

Memory Systems: The Key to Contextual Intelligence

Memory allows the AI to retain and leverage past interactions for more context-aware responses.

  • Short-term Memory: Holds recent interactions for immediate contextual use.
  • Long-term Memory: Stores information over time for sustained reference.
  • Semantic Memory: Maintains general knowledge and facts for informed interactions.

This shows how AI integrates user prompts, tool outputs, and natural language generation.

Here’s the definition of AI Agents:

AI Agents are autonomous software systems designed to perform specific tasks or achieve certain objectives by interacting with their environment. Key traits of AI Agents include:

  1. Perception: They sense or retrieve data about their environment (e.g., from APIs or user inputs).
  2. Reasoning: They analyze the data to make informed decisions, often leveraging AI models like GPT for natural language understanding.
  3. Action: They perform actions in the real or virtual world, such as generating responses, triggering workflows, or modifying systems.
  4. Learning: Advanced agents often adapt and improve their performance over time based on feedback or new data.

AI Agents can handle tasks across domains such as customer service, data analysis, workflow automation, and more.

Why Should We Care About Agentic RAG Systems?

Firstly, here are the limitations of basic Retrieval-Augmented Generation (RAG):

  1. When to Retrieve: The system might struggle to determine when retrieval is needed, potentially resulting in incomplete or less accurate answers.
  2. Document Quality: The retrieved documents might not align well with the user’s question, which can undermine the relevance of the response.
  3. Generation Errors: The model may “hallucinate,” adding inaccurate or unrelated information that isn’t supported by the retrieved content.
  4. Answer Precision: Even with relevant documents, the generated response might fail to directly or adequately address the user’s query, making the output less dependable.
  5. Reasoning Issues: The inability of the system to reason through complex queries hinders nuanced understanding.
  6. Limited Adaptability: Traditional systems can’t adapt strategies dynamically, like choosing API calls or web searches.

Importance of Agentic RAG

Understanding Agentic RAG systems, helps us deploy the right solutions for the above-given challenges, and specific tasks and ensures alignment with the intended use case. Here’s why it’s critical:

  1. Tailored Solutions:
    • Different types of Agentic RAG systems are designed for varying levels of autonomy and complexity. For instance:
      • Agentic RAG Router: Agentic RAG Routers is a modular framework that dynamically routes tasks to appropriate retrieval, generation, or action components based on the query’s intent and complexity.
      • Self-Reflective RAG: Self-Reflective RAG integrates introspection mechanisms, enabling the system to evaluate and refine its responses by iteratively assessing retrieval relevance, generation quality, and decision-making accuracy before finalizing outputs.
    • Knowing these types ensures optimal design and resource utilization.
  2. Risk Management:
    • Agentic systems involve decision-making, which may introduce risks like incorrect actions, over-reliance, or misuse. Understanding the scope and limitations of each type mitigates these risks.
  3. Innovation & Scalability:
    • Differentiating between types allows businesses to scale their systems from basic implementations to sophisticated agents capable of handling enterprise-level challenges.

In a nutshell, the agentic RAG can plan, adapt, and iterate to find the right solution to the user.

Agentic RAG: Merging RAG with AI Agents

Combining the AI Agents and RAG workflow, here’s the architecture of Agentic RAG:

Agentic RAG: Merging RAG with AI Agents
Source: Author

Agentic RAG combines the structured retrieval and knowledge integration capabilities of RAG with the autonomy and adaptability of AI agents. Here’s how it works:

  1. Dynamic Knowledge Retrieval: Agents equipped with RAG can retrieve specific information on the fly, ensuring they operate with the most current and contextually relevant data.
  2. Intelligent Decision-Making: The agent processes retrieved data, applying advanced reasoning to generate solutions, complete tasks, or answer questions with depth and accuracy.
  3. Task-Oriented Execution: Unlike a static RAG pipeline, Agentic RAG systems can execute multi-step tasks, adjust to changing objectives, or refine their approaches based on feedback loops.
  4. Continuous Improvement: Through learning, agents improve their retrieval strategies, reasoning capabilities, and task execution over time, becoming more efficient and effective.

Applications of Agentic RAG

Here are applications of Agentic RAG:

  • Customer Support: Automatically retrieving and delivering accurate responses to user inquiries by accessing real-time data sources.
  • Content Creation: Generating context-rich content for complex domains like legal or medical fields, supported by retrieved knowledge.
  • Research Assistance: Helping researchers by autonomously gathering and synthesizing relevant materials from vast databases.
  • Workflow Automation: Streamlining enterprise operations by integrating retrieval-driven decision-making into business processes.

Agentic RAG represents a powerful synergy between Retrieval-Augmented Generation and autonomous AI agents, enabling systems to operate with unparalleled intelligence, adaptability, and relevance. It’s a significant step toward building AI systems that are not only informed but also capable of independently executing sophisticated, knowledge-intensive tasks.

To understand this read this: RAG vs Agentic RAG: A Comprehensive Guide

I hope, now you are well versed with the Agentic RAG, in the next section I will tell you some important and popular types of Agentic RAG Systems along with their architectures.

1. Agentic RAG Routers

As mentioned earlier, the term Agentic signifies that the system behaves like an intelligent agent, capable of reasoning and deciding which tools or methods to utilize for retrieving and processing data. By leveraging both retrieval (e.g., database search, web search, semantic search) and generation (e.g., LLM processing), this system ensures that the user’s query is answered in the most effective way possible.

Similarly,

Agentic RAG Routers are systems designed to dynamically route user queries to appropriate tools or data sources, enhancing the capabilities of Large Language Models (LLMs). The primary purpose of such routers is to combine retrieval mechanisms with the generative strengths of LLMs to deliver accurate and contextually rich responses.

This approach bridges the gap between the static knowledge of LLMs (trained on pre-existing data) and the need for dynamic knowledge retrieval from live or domain-specific data sources. By combining retrieval and generation, Agentic RAG Routers enable applications such as:

  • Question answering
  • Data analysis
  • Real-time information retrieval
  • Recommendation generation
Agentic RAG Routers
Source: Author

Architecture of Agentic RAG Routers

The architecture shown in the diagram provides a detailed visualization of how Agentic RAG Routers operate. Let’s break down the components and flow:

  1. User Input and Query Processing
    • User Input: A user submits a query, which is the entry point for the system. This could be a question, a command, or a request for specific data.
    • Query: The user input is parsed and formatted into a query, which the system can interpret.
  2. Retrieval Agent
    • The Retrieval Agent serves as the core processing unit. It acts as a coordinator, deciding how to handle the query. It evaluates:
      • The intent of the query.
      • The type of information required (structured, unstructured, real-time, recommendations).
  3. Router
    • A Router determines the appropriate tool(s) to handle the query:
      • Vector Search: Retrieves relevant documents or data using semantic embeddings.
      • Web Search: Accesses live information from the internet.
      • Recommendation System: Suggests content or results based on prior user interactions or contextual relevance.
      • Text-to-SQL: Converts natural language queries into SQL commands for accessing structured databases.
  4. Tools: The tools listed here are modular and specialized:
    • Vector Search A & B: Designed to search semantic embeddings for matching content in vectorized forms, ideal for unstructured data like documents, PDFs, or books.
    • Web Search: Accesses external, real-time web data.
    • Recommendation System: Leverages AI models to provide user-specific suggestions.
  5. Data Sources: The system connects to diverse data sources:
    • Structured Databases: For well-organized information (e.g., SQL-based systems).
    • Unstructured Sources: PDFs, books, research papers, etc.
    • External Repositories: For semantic search, recommendations, and real-time web queries.
  6. LLM Integration: Once data is retrieved, it is fed into the LLM:
    • The LLM synthesizes the retrieved information with its generative capabilities to create a coherent, human-readable response.
  7. Output: The final response is sent back to the user in a clear and actionable format.

Types of Agentic RAG Routers

Here are the types of Agentic Rag Routers:

1. Single Agentic RAG Router

Single Agentic RAG Router
Source: Author
  • In this setup, there is one unified agent responsible for all routing, retrieval, and decision-making tasks.
  • Simpler and more centralized, ideal for systems with limited data sources or tools.
  • Use Case: Applications with a single type of query, such as retrieving specific documents or processing SQL-based requests.

In the Single Agentic RAG Router:

  1. Query Submission: The user submits a query, which is processed by a single Retrieval Agent.
  2. Routing via a Single Agent: The Retrieval Agent evaluates the query and passes it to a single router, which decides which tool to use (e.g., Vector Search, Web Search, Text-to-SQL, Recommendation System).
  3. Tool Access:
    • The router connects the query to one or more tools, depending on the need.
    • Each tool fetches data from its respective data source:
      • Text-to-SQL interacts with databases like PostgreSQL or MySQL for structured queries.
      • Semantic Search retrieves data from PDFs, books, or unstructured sources.
      • Web Search fetches real-time online information.
      • Recommendation Systems provide suggestions based on the context or user profile.
  4. LLM Integration: After retrieval, the data is passed to the LLM, which combines it with its generative capabilities to produce a response.
  5. Output: The response is delivered back to the user in a clear, actionable format.

This approach is centralized and efficient for simple use cases with limited data sources and tools.

2. Multiple Agentic RAG Routers

Multiple Agentic RAG Routers
Source: Author
  • This architecture involves multiple agents, each handling a specific type of task or query. 
  • More modular and scalable, suitable for complex systems with diverse tools and data sources.
  • Use Case: Multi-functional systems that serve various user needs, such as research, analytics, and decision-making across multiple domains.

In the Multiple Agentic RAG Routers:

  1. Query Submission: The user submits a query, which is initially processed by a Retrieval Agent.
  2. Distributed Retrieval Agents: Instead of a single router, the system employs multiple retrieval agents, each specializing in a specific type of task. For example:
    • Retrieval Agent 1 might handle SQL-based queries.
    • Retrieval Agent 2 might focus on semantic searches.
    • Retrieval Agent 3 could prioritize recommendations or web searches.
  3. Individual Routers for Tools: Each Retrieval Agent routes the query to its assigned tool(s) from the shared pool (e.g., Vector Search, Web Search, etc.) based on its scope.
  4. Tool Access and Data Retrieval:
    • Each tool fetches data from the respective sources as required by its retrieval agent.
    • Multiple agents can operate in parallel, ensuring that diverse query types are processed efficiently.
  5. LLM Integration and Synthesis: All the retrieved data is passed to the LLM, which synthesizes the information and generates a coherent response.
  6. Output: The final, processed response is returned to the user.

This approach is modular and scalable, suitable for complex systems with diverse tools and high query volume.

Agentic RAG Routers combine intelligent decision-making, robust retrieval mechanisms, and LLMs to create a versatile query-response system. The architecture optimally routes user queries to appropriate tools and data sources, ensuring high relevance and accuracy. Whether using a single or multiple router setup, the design depends on the system’s complexity, scalability needs, and application requirements.

2. Query Planning Agentic RAG

Query Planning Agentic RAG (Retrieval-Augmented Generation) is a methodology designed to handle complex queries efficiently by leveraging multiple parallelizable subqueries across diverse data sources. This approach combines intelligent query division, distributed processing, and response synthesis to deliver accurate and comprehensive results.

Query Planning Agentic RAG
Source: Author

Core Components of Query Planning Agentic RAG

Here are the core components:

  1. User Input and Query Submission
    • User Input: The user submits a query or request into the system.
    • The input query is processed and passed downstream for further handling.
  2. Query Planner: The Query Planner is the central component orchestrating the process. It:
    • Interprets the query provided by the user.
    • Generates appropriate prompts for the downstream components.
    • Decide which tools (query engines) to invoke to answer specific parts of the query.
  3. Tools
    • The tools are specialized pipelines (e.g., RAG pipelines) containing query engines, such as:
      • Query Engine 1
      • Query Engine 2
    • These pipelines are responsible for retrieving relevant information or context from external knowledge sources (e.g., databases, documents, or APIs).
    • The retrieved information is sent back to the Query Planner for integration.
  4. LLM (Large Language Model)
    • The LLM serves as the synthesis engine for complex reasoning, natural language understanding, and response generation.
    • It interacts bidirectionally with the Query Planner:
      • Receives prompts from the planner.
      • Provides context-aware responses or refined outputs based on the retrieved information.
  5. Synthesis and Output
    • Synthesis: The system combines retrieved information from tools and the LLM’s response into a coherent answer or solution.
    • Output: The final synthesized result is presented to the user.

Key Highlights

  • Modular Design: The architecture allows for flexibility in tool selection and integration.
  • Efficient Query Planning: The Query Planner acts as an intelligent intermediary, optimizing which components are used and in what order.
  • Retrieval-Augmented Generation: By leveraging RAG pipelines, the system enhances the LLM’s knowledge with up-to-date and domain-specific information.
  • Iterative Interaction: The Query Planner ensures iterative collaboration between the tools and the LLM, refining the response progressively.

3. Adaptive RAG 

Adaptive Retrieval-Augmented Generation (Adaptive RAG) is a method that enhances the flexibility and efficiency of large language models (LLMs) by tailoring the query handling strategy to the complexity of the incoming query. 

Key Idea of Adaptive RAG

Adaptive RAG dynamically chooses between different strategies for answering questions—ranging from simple single-step approaches to more complex multi-step or even no-retrieval processes—based on the complexity of the query. This selection is facilitated by a classifier, which analyzes the query’s nature and determines the optimal approach.

Comparison with Other Methods

Here’s the comparison with single-step, multi-step and adaptive approach:

  1. Single-Step Approach
    • How it Works: For both simple and complex queries, a single round of retrieval is performed, and an answer is generated directly from the retrieved documents.
    • Limitation:
      • Works well for simple queries like “When is the birthday of Michael F. Phelps?” but fails for complex queries like “What currency is used in Billy Giles’ birthplace?” due to insufficient intermediate reasoning.
      • This results in inaccurate answers for complex cases.
  2. Multi-Step Approach
    • How it Works: Queries, whether simple or complex, go through multiple rounds of retrieval, generating intermediate answers iteratively to refine the final response.
    • Limitation:
      • Though powerful, it introduces unnecessary computational overhead for simple queries. For example, repeatedly processing “When is the birthday of Michael F. Phelps?” is inefficient and redundant.
  3. Adaptive Approach
    • How it Works: This approach uses a classifier to determine the query’s complexity and choose the appropriate strategy:
      • Straightforward Query: Directly generate an answer without retrieval (e.g., “Paris is the capital of what?”).
      • Simple Query: Use a single-step retrieval process.
      • Complex Query: Employ multi-step retrieval for iterative reasoning and answer refinement.
    • Advantages
      • Reduces unnecessary overhead for simple queries while ensuring high accuracy for complex ones.
      • Adapts flexibly to a variety of query complexities.
Adaptive RAG  ARCHITECTURE
Source: Author

Adaptive RAG Framework

  • Classifier Role:
    • A smaller language model predicts query complexity.
    • It is trained using automatically labelled datasets, where the labels are derived from past model outcomes and inherent patterns in the data.
  • Dynamic Strategy Selection:
    • For simple or straightforward queries, the framework avoids wasting computational resources.
    • For complex queries, it ensures sufficient iterative reasoning through multiple retrieval steps.

RAG System Architecture Flow from LangGraph

Here’s another example of an adaptive RAG System architecture flow from LangGraph:

adaptive RAG System architecture flow from LangGraph
Source: Adaptive RAG

1. Query Analysis

The process begins with analyzing the user query to determine the most appropriate pathway for retrieving and generating the answer.

  • Step 1: Route Determination
    • The query is classified into categories based on its relevance to the existing index (database or vector store).
    • [Related to Index]: If the query is aligned with the indexed content, it is routed to the RAG module for retrieval and generation.
    • [Unrelated to Index]: If the query is outside the scope of the index, it is routed for a web search or another external knowledge source.
  • Optional Routes: Additional pathways can be added for more specialized scenarios, such as domain-specific tools or external APIs.

2. RAG + Self-Reflection

If the query is routed through the RAG module, it undergoes an iterative, self-reflective process to ensure high-quality and accurate responses.

  1. Retrieve Node
    • Retrieves documents from the indexed database based on the query.
    • These documents are passed to the next stage for evaluation.
  2. Grade Node
    • Assesses the relevance of the retrieved documents.
    • Decision Point:
      • If documents are relevant: Proceed to generate an answer.
      • If documents are irrelevant: The query is rewritten for better retrieval and the process loops back to the retrieve node.
  3. Generate Node
    • Generates a response based on the relevant documents.
    • The generated response is evaluated further to ensure accuracy and relevance.
  4. Self-Reflection Steps
    • Does it answer the question?
      • If yes: The process ends, and the answer is returned to the user.
      • If no: The query undergoes another iteration, potentially with additional refinements.
    • Hallucinations Check
      • If hallucinations are detected (inaccuracies or made-up facts): The query is rewritten, or additional retrieval is triggered for correction.
  5. Re-write Question Node
    • Refines the query for better retrieval results and loops it back into the process.
    • This ensures that the model adapts dynamically to handle edge cases or incomplete data.

3. Web Search for Unrelated Queries

If the query is deemed unrelated to the indexed knowledge base during the Query Analysis stage:

  • Generate Node with Web Search: The system directly performs a web search and uses the retrieved data to generate a response.
  • Answer with Web Search: The generated response is delivered directly to the user.

In essence, Adaptive RAG is an intelligent and resource-aware framework that improves response quality and computational efficiency by leveraging tailored query strategies.

4. Agentic Corrective RAG 

A low-quality retriever often introduces significant irrelevant information, hindering generators from accessing accurate knowledge and potentially leading them astray.

Likewise, here are some issues with RAG:

Issues with Traditional RAG (Retrieval-Augmented Generation)

  • Low-Quality Retrievers: These can introduce a substantial amount of irrelevant or misleading information. This not only impedes the model’s ability to acquire accurate knowledge but also increases the risk of hallucinations during generation.
  • Undiscriminating Utilization: Many conventional RAG systems indiscriminately incorporate all retrieved documents, irrespective of their relevance. This leads to the integration of unnecessary or incorrect data.
  • Inefficient Document Processing: Current RAG methods often treat complete documents as knowledge sources, even though large portions of retrieved text may be irrelevant, diluting the quality of generation.
  • Dependency on Static Corpora: Retrieval systems that rely on fixed databases can only provide limited or suboptimal documents, failing to adapt to dynamic information needs.

Corrective RAG (CRAG)

CRAG aims to address the above issues by introducing mechanisms to self-correct retrieval results, enhancing document utilization, and improving generation quality.

Key Features:

  • Retrieval Evaluator: A lightweight component to assess the relevance and reliability of retrieved documents for a query. This evaluator assigns a confidence degree to the documents.
  • Triggered Actions: Depending on the confidence score, different retrieval actions—Correct, Ambiguous, or Incorrect—are triggered.
  • Web Searches for Augmentation: Recognizing the limitations of static databases, CRAG integrates large-scale web searches to supplement and improve retrieval results.
  • Decompose-Then-Recompose Algorithm: This method selectively extracts key information from retrieved documents, discarding irrelevant sections to refine the input to the generator.
  • Plug-and-Play Capability: CRAG can seamlessly integrate with existing RAG-based systems without requiring extensive modifications.

Corrective RAG Workflow

Corrective RAG Workflow
Source: Dipanjan Sarkar

Step 1: Retrieval

Retrieve context documents from a vector database using the input query. This is the initial step to gather potentially relevant information.

Step 2: Relevance Check

Use a Large Language Model (LLM) to evaluate whether the retrieved documents are relevant to the input query. This ensures the retrieved documents are appropriate for the question.

Step 3: Validation of Relevance

  • If all documents are relevant (Correct), no specific corrective action is required, and the process can proceed to generation.
  • If ambiguity or incorrectness is detected, proceed to Step 4.

If documents are ambiguous or incorrect:

  1. Rephrase the query based on insights from the LLM.
  2. Conduct a web search or alternative retrieval to fetch updated and accurate context information.

Step 5: Response Generation

Send the refined query and relevant context documents (corrected or original) to the LLM for generating the final response. The type of response depends on the quality of retrieved or corrected documents:

  • Correct: Use the query with retrieved documents.
  • Ambiguous: Combine original and new context documents.
  • Incorrect: Use the corrected query and newly retrieved documents for generation.

This workflow ensures high accuracy in responses through iterative correction and refinement.

Agentic Corrective RAG System Workflow

The idea is to couple a RAG system with a few checks in place and perform web searches if there is a lack of relevant context documents to the given user query as follows:

Agentic Corrective RAG System Workflow
Source: Dipanjan Sarkar
  1. Question: This is the input from the user, which starts the process.
  2. Retrieve (Node): The system queries a vector database to retrieve context documents that might answer the user’s question.
  3. Grade (Node): A Large Language Model (LLM) evaluates whether the retrieved documents are relevant to the query.
    • If all documents are deemed relevant, the system proceeds to generate an answer.
    • If any document is irrelevant, the system moves to rephrase the query and attempts a web search.

Step 1 – Retrieve Node

The system retrieves documents from a vector database based on the query, providing context or answers.

Step 2 – Grade Node

An LLM evaluates document relevance:

  • All relevant: Proceeds to answer generation.
  • Some irrelevant: Flags the issue and refines the query.

Branching Scenarios After Grading

  • Step 3A – Generate Answer Node: If all documents are relevant, the LLM generates a quick response.
  • Step 3B – Rewrite Query Node: For irrelevant results, the query is rephrased for better retrieval.
  • Step 3C – Web Search Node: A web search gathers additional context.
  • Step 3D – Generate Answer Node: The refined query and new data are used to generate the answer.

We can build this as an agentic RAG system by having a specific functionality step as a node in the graph and using LangGraph to implement it. Key steps in the node will include prompts being sent to LLMs to perform specific tasks as seen in the detailed workflow below:

The Agentic Corrective RAG Architecture enhances Retrieval-Augmented Generation (RAG) with corrective steps for accurate answers:

  1. Query and Initial Retrieval: A user query retrieves context documents from a vector database.
  2. Document Evaluation: The LLM Grader Prompt evaluates each document’s relevance (yes or no).
  3. Decision Node:
    • All Relevant: Directly proceed to generate the answer.
    • Irrelevant Documents: Trigger corrective steps.
  4. Query Rephrasing: The LLM Rephrase Prompt rewrites the query for optimized web retrieval.
  5. Additional Retrieval: A web search retrieves improved context documents.
  6. Response Generation: The RAG Prompt generates an answer using validated context only.

Here’s what the CRAG do in short:

  • Error Correction: This architecture iteratively improves context accuracy by identifying irrelevant documents and retrieving better ones.
  • Agentic Behavior: The system dynamically adjusts its actions (e.g., rephrasing queries, conducting web searches) based on the LLM’s evaluations.
  • Factuality Assurance: By anchoring the generation step to validated context documents, the framework minimizes the risk of hallucinated or incorrect responses.

5. Self-Reflective RAG

Self-reflective RAG (Retrieval-Augmented Generation) is an advanced approach in natural language processing (NLP) that combines the capabilities of retrieval-based methods with generative models while adding an additional layer of self-reflection and logical reasoning. For instance, self-reflective RAG helps in retrieval, re-writing questions, discarding irrelevant or hallucinated documents and re-try retrieval. In short, it was introduced to capture the idea of using an LLM to self-correct poor-quality retrieval and/or generations.

Key Components of Self Route

  • Decision-making by LLMs: Queries are evaluated to determine if they can be answered with the given retrieved context.
  • Routing: If a query is answerable, response is generated immediately. Otherwise, it is routed to a long-context model with the full context documents to generate the response.
  • Efficiency and Accuracy: This design balances cost-efficiency (avoiding unnecessary computation cost and time) and accuracy (leveraging long-context models only when needed).

Key Features of Self-RAG

  1. On-Demand Adaptive Retrieval:
    • Unlike traditional RAG methods, which retrieve a fixed set of passages beforehand, SELF-RAG dynamically decides whether retrieval is necessary based on the ongoing generation process.
    • This decision is made using reflection tokens, which act as signals during the generation process.
  1. Reflection Tokens: These are special tokens integrated into the LLMs workflow, serving two purposes:
    • Retrieval Tokens: Indicate whether more information is needed from external sources.
    • Critique Tokens: Self-evaluate the generated text to assess quality, relevance, or completeness.
    • By using these tokens, the LLMs can decide when to retrieve and ensure generated text aligns with cited sources.
  2. Self-Critique for Quality Assurance:
    • The LLM critiques its own outputs using the generated critique tokens. These tokens validate aspects like relevance, support, or completeness of the generated segments.
    • This mechanism ensures that the final output is not only coherent but also well-supported by retrieved evidence.
  3. Controllable and Flexible: Reflection tokens allow the model to adapt its behavior during inference, making it suitable for diverse tasks, such as answering questions requiring retrieval or generating self-contained outputs without retrieval.
  4. Improved Performance: By combining dynamic retrieval and self-critique, SELF-RAG surpasses standard RAG models and large language models (LLMs) in generating high-quality outputs that are better supported by evidence.

Basic RAG flows involve an LLM generating outputs based on retrieved documents. Advanced RAG approaches, like routing, allow the LLM to select different retrievers based on the query. Self-reflective RAG adds feedback loops, re-generating queries or re-retrieving documents as needed. State machines, ideal for such iterative processes, define steps (e.g., retrieval, query refinement) and transitions, enabling dynamic adjustments like re-querying when retrieved documents are irrelevant.

state machine by Langgraph
Source: LangGraph

The Architecture of Self-reflective RAG

The Architecture of Self-reflective RAG
Source: Author

I have created a Self-Reflective RAG (Retrieval-Augmented Generation) architecture. Here’s the flow and components:

  1. The process starts with a Query (shown in green)
  2. First Decision Point: “Is Retrieval Needed?”
    • If NO: The query goes directly to the LLM for processing
    • If YES: The system proceeds to retrieval steps
  3. Knowledge Base Integration
    • A Knowledge base (shown in purple) connects to the “Retrieval of Relevant Documents” step
    • This retrieval process pulls potentially relevant information to answer the query
  4. Relevance Evaluation
    • Retrieved documents go through an “Evaluate Relevance” step
    • Documents are classified as either “Relevant” or “Irrelevant”
    • Irrelevant documents trigger another retrieval attempt
    • Relevant documents are passed to the LLM
  5. LLM Processing
    • The LLM (shown in yellow) processes the query along with relevant retrieved information
    • Produces an initial Answer (shown in green)
  6. Validation Process
    • The system performs a Hallucination Check: Determines if the generated answer aligns with the provided context (avoiding unsupported or fabricated responses).
  7. Self-Reflection
    • The “Critique Generated Response” step (shown in blue) evaluates the answer
    • This is the “Self-Reflective” part of the architecture
    • If the answer isn’t satisfactory, the system can trigger a query rewrite and restart the process
  8. Final Output: Once an “Accurate Answer” is generated, it becomes the final Output

Grading and Generation Decisions

  • Retrieve Node: Handles the initial retrieval of documents.
  • Grade Documents: Assesses the quality and relevance of the retrieved documents.
  • Transform Query: If no relevant documents are found, the query is adjusted for re-retrieval.
  • Generation Process:
    • Decides whether to generate an answer directly based on the retrieved documents.
    • Uses conditional edges to iteratively refine the answer until it is deemed useful.

Workflow of Traditional RAG and Self-Rag

Here’s the workflow of both traditional RAG and Self-Rag using the example prompt “How did US states get their names?”

Traditional RAG Workflow

  1. Step 1 – Retrieve K documents: Retrieve specific documents like:
    • “Of the fifty states, eleven are named after an individual person”
    • “Popular names by states. In Texas, Emma is a popular baby name”
    • “California was named after a fictional island in a Spanish book”
  2. Step 2 – Generate with retrieved docs:
    • Takes the original prompt (“How did US states get their names?”) + all retrieved documents
    • The language model generates one response combining everything
    • This can lead to contradictions or mixing unrelated information (like claiming California was named after Christopher Columbus)

Self-RAG Workflow

  1. Step 1 – Retrieve on demand:
    • Starts with the prompt “How did US states get their names?”
    • Makes initial retrieval about state name sources
  2. Step 2 – Generate segments in parallel:
    • Creates multiple independent segments, each with its own:
      • Prompt + Retrieved information
      • Fact verification
      • Examples:
        • Segment 1: Facts about states named after people
        • Segment 2: Information about Texas’s naming
        • Segment 3: Details about California’s name origin
  3. Step 3 – Critique and select:
    • Evaluate all generated segments
    • Pick the most accurate/relevant segment
    • Can retrieve additional information if needed
    • Combines verified information into the final response

The key improvement is that Self-RAG

  • Breaks down the response into smaller, verifiable pieces
  • Verifies each piece independently
  • Can dynamically retrieve more information when needed
  • Assembles only the verified information into the final response

As shown in the bottom example with “Write an essay of your best summer vacation”:

  • Traditional RAG still tries to retrieve documents unnecessarily
  • Self-RAG recognizes no retrieval is needed and generates directly from personal experience.

6. Speculative RAG 

Speculative RAG is a smart framework designed to make large language models (LLMs) both faster and more accurate when answering questions. It does this by splitting the work between two kinds of language models:

  1. A small, specialized model that drafts potential answers quickly.
  2. A large, general-purpose model that double-checks these drafts and picks the best one.
speculative RAG
Source: Author

Why Do We Need Speculative RAG?

When you ask a question, especially one that needs precise or up-to-date information (like “What are the latest features of the new iPhone?”), regular LLMs often struggle because:

  1. They can “hallucinate”: This means they might confidently give answers that are wrong or made up.
  2. They rely on outdated knowledge: If the model wasn’t trained on recent data, it can’t help with newer facts.
  3. Complex reasoning takes time: If there’s a lot of information to process (like long documents), the model might take forever to respond.

That’s where Retrieval-Augmented Generation (RAG) steps in. RAG retrieves real-time, relevant documents (like from a database or search engine) and uses them to generate answers. But here’s the issue: RAG can still be slow and resource-heavy when handling lots of data.

Speculative RAG fixes this by adding specialized teamwork: (1) a specialist RAG drafter, and (2) a generalist RAG verifier

How Speculative RAG Works?

Imagine Speculative RAG as a two-person team solving a puzzle:

  1. Step 1: Gather Clues
    A “retriever” goes out and fetches documents with information related to your question. For example, if you ask, “Who played Doralee Rhodes in the 1980 movie Nine to Five?”, it pulls articles about the movie and maybe the musical.
  2. Step 2: Drafting Answers (Small Model)
    A smaller, faster language model (the specialist drafter) works on these documents. Its job is to:
    • Quickly create multiple drafts of possible answers.
    • Include reasoning for each draft (like saying, “This answer is based on this source”).
  3. This model is like a junior detective who quickly sketches out ideas.
  4. Step 3: Verifying the Best Answer (Big Model)
    A larger, more powerful language model (the generalist verifier) steps in next. It:
    • Check each draft for accuracy and relevance.
    • Scores them based on confidence.
    • Pick the best one as the final answer.
  5. Think of this model as the senior detective who carefully examines the junior’s work and makes the final call.

An Example to Tie it Together

Let’s go through an example query:
“Who starred as Doralee Rhodes in the 1980 film Nine to Five?”

  1. Retrieve Documents: The system finds articles about both the movie (1980) and the musical (2010).
  2. Draft Answers (Specialist Drafter):
    • Draft 1: “Dolly Parton played Doralee Rhodes in the 1980 movie Nine to Five.”
    • Draft 2: “Doralee Rhodes is a character in the 2010 musical Nine to Five.”
  3. Verify Answers (Generalist Verifier):
    • Draft 1 gets a high score because it matches the movie and the question.
    • Draft 2 gets a low score because it’s about the musical, not the movie.
  4. Final Answer: The system confidently outputs: “Dolly Parton played Doralee Rhodes in the 1980 movie Nine to Five.”

Why is this Approach Smart?

  • Faster Responses: The smaller model handles the heavy lifting of generating drafts, which speeds things up.
  • More Accurate Answers: The larger model focuses only on reviewing drafts, ensuring high-quality results.
  • Efficient Resource Use: The larger model doesn’t waste time processing unnecessary details—it only verifies.

Key Benefits of Speculative RAG

  1. Balanced Performance: It’s fast because the small model drafts, and it’s accurate because the big model verifies.
  2. Avoids Wasting Effort: Instead of reviewing everything, the big model only checks what the small model suggests.
  3. Real-World Applications: Great for answering tough questions that require both reasoning and real-time, up-to-date information.

Speculative RAG is like having a smart assistant (the specialist drafter) and a careful editor (the generalist verifier) working together to make sure your answers are not just fast but also spot-on accurate!

Standard RAG vs. Self-Reflective RAG vs. Corrective RAG vs. Speculative RAG

1. Standard RAG

  • What it does: It retrieves documents from a knowledge base and directly incorporates them into the generalist LM’s input.
  • Weakness: This approach burdens the generalist LM with both understanding the documents and generating the final answer. It doesn’t differentiate between relevant and irrelevant information.

2. Self-Reflective RAG

  • What it adds: The generalist LM learns to classify whether the retrieved documents are relevant or irrelevant and can tune itself based on those classifications.
  • Weakness: It requires additional instruction-tuning of the generalist LM to handle these classifications and may still produce answers that are less efficient.

3. Corrective RAG

  • What it adds: Uses an external Natural Language Inference (NLI) model to classify documents as Correct, Ambiguous, or Incorrect before incorporating them into the generalist LM’s prompt.
  • Weakness: This adds complexity by introducing an extra NLI step, slowing down the process.

4. Speculative RAG

  • Key Innovation: It divides the task into two parts:
    • A specialist RAG drafter (a smaller LM) rapidly generates multiple drafts and rationales for the answer.
    • The generalist LM evaluates these drafts and selects the best one.
  • Step-by-Step Process:
    • Question Input: When the system receives a knowledge-intensive question, it retrieves relevant documents.
    • Parallel Drafting: The specialist RAG drafter works on subsets of retrieved documents in parallel. Each subset generates:
      • A draft answer (α)
      • An accompanying rationale (β).
    • Verification and Selection: The generalist LM evaluates all the drafts (α1,α2,α3) and their rationales to assign scores. It selects the most confident draft as the final answer.

 The Speculative RAG framework achieves a perfect balance of speed and accuracy:

  • The small specialist LM does the heavy lifting (drafting answers based on retrieved documents).
  • The large generalist LM ensures the final output is accurate and well-justified. This approach outperforms earlier methods by reducing latency while maintaining state-of-the-art accuracy.
ApproachHow It WorksWeaknessSpeculative RAG Improvement
Standard RAGPasses all retrieved documents to the generalist LM directly.Inefficient and prone to irrelevant content.Offloads drafting to a specialist, reducing burden.
Self-Reflective RAGLM learns to classify documents as relevant/irrelevant.Requires instruction-tuning, still slow.Specialist LM handles this in parallel without tuning.
Corrective RAGUses Natural Language Inference (NLI) models to classify document correctness.Adds complexity, slows response times.Avoids extra steps; uses drafts for fast evaluation.
Speculative RAGSplits drafting (specialist LM) and verifying (generalist LM).None (faster and more accurate).Combines speed, accuracy, and parallel processing.

7. Self Route Agentic RAG 

Self Route is a design pattern in Agentic RAG systems where Large Language Models (LLMs) play an active role in deciding how a query should be processed. The approach relies on the LLM’s ability to self-reflect and determine whether it can generate an accurate response based on the context provided. If the model decides it cannot generate a reliable response, it routes the query to an alternative method, such as a long-context model, for further processing. This architecture leverages the LLM’s internal calibration for determining answerability to optimize performance and cost. Introduced in Retrieval Augmented Generation or Long-Context LLMs? A Comprehensive Study and Hybrid Approach, this method combines Retrieval-Augmented Generation (RAG) and Long Context (LC) to achieve cost efficiency while maintaining performance comparable to LC. Self Route utilizes the LLM itself to route queries through self-reflection, operating on the assumption that LLMs are well-calibrated in predicting whether a query is answerable given the provided context. 

Key components of Self Route:

  1. Decision-making by LLMs: Queries are evaluated to determine if they can be answered with the given context.
  2. Routing: If a query is answerable, it is processed immediately. Otherwise, it is routed to a long-context model with additional or full context.
  3. Efficiency and Accuracy: This design balances cost-efficiency (avoiding unnecessary computation) and accuracy (leveraging long-context models only when needed).
Self Route Agentic RAG 
Source: Dipanjan Sarkar

1. Standard RAG Flow

  1. Input Query and Context Retrieval:
    • A user query is submitted.
    • Relevant context documents are retrieved using a Vector Database, which matches the query with pre-indexed documents.
  2. Decision Node:
    • A long context LLM like GPT-4o or Gemini receives the query and the context documents.
    • It uses the LLM Judge Prompt:

Prompt:

Write UNANSWERABLE if the query cannot be answered based on the provided context else write ANSWERABLE.
Query: <query>
Context Doc: <context>
  • This step determines whether the context is sufficient to answer the query.
  • Outcome:
    • If the query is judged ANSWERABLE, the flow proceeds with Standard RAG Prompt.
    • If UNANSWERABLE, the flow moves to the Long-Context LLM Flow.
  1. RAG Prompt (for ANSWERABLE queries):

If sufficient context is available, the following prompt is used to generate the response:

Given a query and context documents, use only the provided information to answer the query, do not make up answers.
Query: <query>
Context: <context>
  1. Answer Generation:
    • The GPT 4o model processes the RAG Prompt and generates the answer based on the provided context.

2. Long-Context LLM Flow

  1. Trigger Condition:
    • If the query is judged UNANSWERABLE by the Decision Node, the process switches to the Long-Context LLM Flow.
  2. Merging Context Documents:
    • The LLM Judge Prompt identifies the insufficiency in the context, so a merge operation combines multiple related context documents into a single long-context document for better context continuity.
  3. Long Context Prompt:

The merged document is then used as input to the GPT-4o model with the following prompt:

Given a query and this context document, use only the provided information to answer the query, do not makeup answers.
Query: <query>
Context: <long_context>
  1. Answer Generation:
    • The GPT 4o model processes the Long Context Prompt and generates a response based on the enriched, merged context.

Key Features and Workflow

Here are key features and workflow:

  1. Dynamic Decision-Making:
    • The architecture evaluates whether the context is sufficient to answer a query dynamically, ensuring that the system adapts based on the input complexity.
  2. Two-Tiered Answer Generation:
    • Standard RAG Flow: Handles straightforward queries with sufficient context.
    • Long-Context LLM Flow: Addresses complex queries requiring extensive or combined context.
  3. Prompts for Fine-Grained Control:
    • Explicit instructions in the RAG Prompt and Long Context Prompt ensure factuality by restricting the model to the provided context, avoiding hallucination.
  4. Scalability with Vector Database:
    • The system scales efficiently by retrieving relevant context from a vector database before making decisions about query processing.

Summary

  • The Standard RAG Flow efficiently handles queries with available and sufficient context.
  • The Long-Context LLM Flow extends the capability to handle complex queries by merging multiple documents into a coherent long context.
  • Carefully designed prompts and decision nodes ensure accuracy, context adherence, and adaptability to varying query requirements.

Conclusion

As the field of Retrieval-Augmented Generation (RAG) advances, Agentic RAG system has emerged as a transformative innovation, blending traditional RAG workflows with the autonomy and adaptability of AI agents. This fusion allows systems to retrieve relevant knowledge dynamically, refine context intelligently, and execute multi-step tasks with precision.

From Agentic RAG Routers and Self-Reflective RAG to advanced architectures like Speculative RAG and Self-Route RAG, each approach addresses specific challenges, such as irrelevant retrievals, reasoning errors, or computational inefficiencies. These systems demonstrate significant progress in enhancing accuracy, adaptability, and scalability across diverse applications, including customer support, workflow automation, and research assistance.

By integrating generative AI with advanced retrieval mechanisms, Agentic RAG not only enhances efficiency but also sets the stage for future AI innovations. As we move toward 2025, these technologies are poised to redefine how we harness data, automate workflows, and tackle complex problem-solving, making them an essential toolkit for businesses and developers alike.

Also, if you are looking for a comprehensive program on AI Agents online, then explore: Agentic AI Pioneer Program

Hi, I am Pankaj Singh Negi - Senior Content Editor | Passionate about storytelling and crafting compelling narratives that transform ideas into impactful content. I love reading about technology revolutionizing our lifestyle.

Responses From Readers

Clear

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details