Courses / RAG Systems / Module 13
Module 13: Agentic RAG: iterative retrieval, tools, self-checks (continues in Agentic AI)
8 h · theory 2 · hands-on 3 · project 2 · revision 1
You will be able to
- Let a model decide when and what to retrieve
- Add self-checks and corrective retrieval
- Combine search with tools such as SQL
- Cap steps and cost
Capstone increment: Agentic mode for multi-hop questions with a step limit, measured against single-shot RAG.
Job-description skills: Agentic retrieval · Lab tools: langgraph, llama-index
1. When one retrieval isn’t enough
Single-shot RAG retrieves once and answers. Some questions need more: multi-hop questions where the first answer tells you what to look up next, comparisons across documents, questions that need a database or an API as well as text, and vague questions where the first results show what the user meant.
Agentic RAG lets the model decide what to retrieve, read the results, judge whether they are enough, and search again. It is the agent loop from the Agentic AI course with retrieval as its main tool.
2. Retrieval as a tool
Expose search as a tool with a clear schema: a query string, optional filters (document type, year), and k. Return short results with chunk ids so the model can cite them. The model plans, calls search, reads, and either answers or searches again with a better query, the ReAct pattern.
Keep the tool honest: the permission filter from Module 10 applies inside the tool exactly as in single-shot RAG, and the tool, not the model, builds citations from chunk metadata.
3. Self-checks: grade, correct, verify
Corrective RAG (CRAG, Yan and others, 2024) grades retrieved documents and, when they look irrelevant, rewrites the query or falls back to another source. Self-RAG (Asai and others, 2023) trains a model to decide when to retrieve and to critique its own output. In practice teams build the same ideas as nodes in a graph: retrieve, grade relevance, rewrite if needed, generate, check the answer is grounded, and retry or stop.
Each check is a small, focused model call with a binary output, which makes it cheap, testable and easy to calibrate against people (Module 8).
4. Combine documents with structured tools
Many real questions mix sources: “which of our top five customers by revenue have open P1 tickets, and what does the contract say about response time?” needs SQL, a ticket API and contract text. Give the agent read-only tools with narrow scopes, schemas and row limits, and make every tool return citations or record ids.
Prefer fixed workflows where the steps are predictable: if every such question needs the same three lookups, a workflow is cheaper and more reliable than an agent deciding each time.
5. Cap steps and cost, and measure against single-shot
Set a maximum number of retrievals (three to five is typical), a token or cost budget per question, and a timeout. When a limit is hit, return an honest “not found” with what was searched, rather than looping.
Evaluate on a multi-hop question set and on your normal golden set, comparing accuracy, cost and latency with single-shot RAG. Then use the router from Module 7 to send only the question types that benefit to agentic mode.
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 13.1: Agentic RAG in LangGraph
Build a graph with retrieve, grade, rewrite and generate nodes over the capstone index, with a step limit of 4 and a grounded-answer check.
Expected: A graph that answers multi-hop questions and stops with not_found at the limit.
Lab 13.2: Add a SQL tool
Add a read-only SQL tool over a small tickets table (row limit, timeout, allowed tables) and three questions that need both SQL and documents.
Expected: Answers that cite both a document chunk and ticket ids.
Lab 13.3: Agentic mode, measured (capstone increment)
Route multi-hop questions to agentic mode and compare it with single-shot RAG on 15 multi-hop and 30 normal questions.
Expected: A table of accuracy, cost and p95 latency by question type, and the routing rule you chose.
Go deeper
Videos
- Self-reflective RAG with LangGraph: Self-RAG and CRAG · LangChain · ~18 min. Self-RAG and Corrective RAG built as LangGraph graphs, with grading and rewrite nodes.
- Building Corrective RAG from scratch with open-source, local LLMs · LangChain · ~26 min. Corrective RAG from scratch with local open models, step by step.
- What Is Agentic RAG? · Krish Naik · ~15 min. A plain-language explanation of what makes RAG agentic and when it is worth it.
Further reading
- Paper Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection · Asai et al., 2023. A model that decides when to retrieve and grades its own passages and answers.
- Paper Corrective Retrieval Augmented Generation · Yan et al., 2024. Grade retrieved documents and fall back to other sources when they are poor.
- Paper Interleaving Retrieval with Chain-of-Thought Reasoning (IRCoT) · Trivedi et al., 2022. Retrieve again after each reasoning step for multi-hop questions.
- Article Building effective agents · Anthropic. The clearest guide to when you need an agent at all, and the workflow patterns to try first.
GitHub repositories
- langchain-ai/langgraph: The agentic RAG tutorial in the docs: retrieve, grade, rewrite and generate as graph nodes.
- AkariAsai/self-rag: The Self-RAG paper’s code; read how reflection tokens decide when to retrieve.
- huggingface/smolagents: A small agent library; its retriever-tool example is a compact agentic RAG.
Checkpoint quiz
Interview questions
- When would you use agentic RAG instead of single-shot RAG?
- Design an agentic RAG graph. Which nodes, which checks, which limits?
- How do you stop an agentic RAG system from looping or running up cost?
- How would you combine SQL and document retrieval in one answer safely?
- How do you evaluate an agentic RAG system against a single-shot baseline?
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).