Skip to content

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

This module is an introduction. Agentic AI covers it in full.

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.

Questionmulti-hopPlanwhat do I need?Toolsearch, SQL, fetchGraderelevant? enough?Answerwith citationsRewrite querycorrective stepStep limitmax 4 retrievalsCost capper questionThe model decides what to retrieve nextGuardsnot enoughtry again
Worth it for multi-hop questions; slower and costlier for simple ones. Route simple questions to single-shot RAG.

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.

Common misconception: “Agentic RAG is always better.” On single-fact questions it usually matches single-shot RAG at two to four times the cost and latency. It earns its keep on multi-hop questions.

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.

In production: Log every tool call with its arguments, results and cost in the trace. When an agentic answer is wrong, the trace shows which step went off course.

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 code

Labs

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

Further reading

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

1. Which question benefits most from agentic RAG?
2. What does a grader node do?
3. The agent hits its step limit. Best behaviour?
4. Where do permission filters go in agentic RAG?
5. How should agentic mode be rolled out?

Interview questions

  1. When would you use agentic RAG instead of single-shot RAG?
  2. Design an agentic RAG graph. Which nodes, which checks, which limits?
  3. How do you stop an agentic RAG system from looping or running up cost?
  4. How would you combine SQL and document retrieval in one answer safely?
  5. 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).