esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

What Is Agentic RAG?

What agentic RAG is, how an agent plans, searches, grades and retries, and when a simple pipeline is the better choice, for your AI interview.

In short

Agentic RAG is retrieval-augmented generation where an AI agent picks its own searches, grades the results and searches again if they are weak. It handles multi-part questions that one search misses, but it adds time and cost, so start with a simple pipeline.

12 min readAdvancedCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

Agentic RAG means the model chooses its own searches. A normal RAG system runs one search with the user's question, then answers from the results. An agentic one plans several searches, grades what comes back, and searches again with a better query when the results are weak. I would use it for questions that span several sources. For a question one search can answer, I would keep the simple pipeline, because every extra step adds delay and cost.

What is agentic RAG, in plain words?

RAG, short for retrieval-augmented generation, means searching your own documents first, then giving the best matches to an AI model so it answers from them. In a standard setup, your code runs that search once, with the user's question, and the model writes the answer from what came back.

Agentic RAG puts an AI agent in charge of that search. The agent is a model that chooses its own next step. It can split a question into parts, pick a source for each part, check what came back, and search again if the results are weak.

A paralegal makes a good comparison. A junior who follows a checklist pulls one box of old files, reads it and writes up what is there. A good paralegal reads the first pages, sees the answer is probably in another box, pulls that one, and stops once the evidence is enough. The second paralegal is the agent.

Now the AI version. A legal team has 40,000 supplier contracts. A single fixed query misses the clause that matters. The agent runs several searches, grades them, and writes an answer that cites the clauses it used.

Key words

Agent
An AI model that chooses its next step and can use tools, such as a search.
Retrieval
Finding the stored documents that match a question.
Grading
Checking whether a search result actually helps answer the question.
Query rewriting
Turning a weak search into a better one, often with the contract's own words.
Step limit
A hard cap on how many searches or model calls the agent may make.

How does the agent's search loop work?

A common shape for agentic RAG is this loop. Here it is for the legal question: can we end a supplier deal after a data breach?

  1. 1

    Plan

    The agent splits the question into parts and picks a source for each, such as the contract index (a searchable store of the documents) or the renewal table.

  2. 2

    Search

    It runs the searches. Several can run at the same time, as Microsoft's agentic retrieval does, which keeps the wait short.

  3. 3

    Grade

    It reads each result and asks whether it answers its part of the question.

  4. 4

    Retry or answer

    Weak results: it rewrites the query and searches again. Strong results: it writes the answer and cites the clauses.

  5. 5

    Stop

    A step limit ends the loop, so a confused agent cannot search forever. When the limit is hit, it says what it found and what is missing.

The agent's search loop

Legal question

Can we exit after a breach?

Agent

plans, grades, decides

Sources

Contract index

40,000 supplier contracts

Policy index

our own security rules

Cited answer

with citations, or not found

  1. 1The agent gets the legal question.
  2. 2It sends searches to the contract and policy indexes.
  3. 3The results come back, and the agent grades them.
  4. 4Good enough: it writes a cited answer.
The agent sends searches to the right source, and the results come back for grading. If they are weak, it tries again with a better query, and otherwise it writes a cited answer.

Here is the loop as a short program. It is a sketch: a keyword match stands in for the search, and the rewrites are fixed in advance, so no model writes them.

Python
# A simplified agent loop: a tiny keyword index, a grader and a rewrite list.
CONTRACT_TERMS = {
    "breach": ["Clause 9.2: the supplier may end the deal after a data breach."],
    "unauthorised access": ["Clause 14.1: notify us within 24 hours of unauthorised access."],
}
MAX_STEPS = 3

def search(query):
    return [text for term, texts in CONTRACT_TERMS.items() if term in query for text in texts]

def answer(query, rewrites):
    for step in range(1, MAX_STEPS + 1):
        hits = search(query)
        grade = "strong" if hits else "weak"
        print(f"step {step}: {query!r} -> {len(hits)} hit(s), {grade}")
        if grade == "strong":
            return hits
        if not rewrites:
            break
        query = rewrites.pop(0)
    return []

hits = answer("security incident exit", ["breach", "unauthorised access"])
print(hits[0] if hits else "Not found: say what was searched and what is missing.")

Output

step 1: 'security incident exit' -> 0 hit(s), weak
step 2: 'breach' -> 1 hit(s), strong
Clause 9.2: the supplier may end the deal after a data breach.

Why use it, and when should you skip it?

Agentic RAG is worth its cost only when one search cannot do the job. Anthropic's post on agents says that simpler options often come first. Microsoft describes its own agentic retrieval as a multi-query pipeline designed for complex questions. In our reading, that is closer to a fixed workflow than to a free-roaming agent.

  • Use it when

    Several sources or several parts

    The answer needs a clause from one place and a renewal date from another. One search cannot cover both.

  • Skip it when

    One search already answers it

    A fixed pipeline is faster, cheaper and easier to test. Start there, and add an agent when you measure a gap.

Two ways to search

Classic RAG

One fixed search

same search every time

Agentic RAG

Plan and search

several checked searches

Clause missed

answer may lack the clause

Clause found

answer cites the right clause

  1. 1One search may miss the clause that matters.
  2. 2The agent searches again with better queries and grades each result.
Two paths, side by side. The fixed pipeline runs one search and answers from what it gets. The agentic path runs several checked searches, so a clause stored in another index is more likely to be found.
  • “Agentic systems often trade latency and cost for better task performance, and you should consider when this tradeoff makes sense.”

    Anthropic

  • “Agentic retrieval adds latency compared to a single-query pipeline, but it handles query complexity that a single query can't.”

    Microsoft, Azure AI Search

Anthropic also points out that autonomy brings higher costs, and that one mistake can build on the next. One wrong grade early can send the rest of the run in the wrong direction.

Tip

Asked whether you would always use it? Say no. Start with the simplest pipeline, prove it misses something, then add the loop.

What does a real run look like?

Here is a made-up but realistic run. A compliance team asks: which supplier contracts let us end the deal after a data breach, and does any of them renew this quarter? The answer needs two sources, which is the case agentic RAG is built for.

  1. 1

    The single search

    One query covers both parts. It returns five passages, mostly about payment terms. The exit clause and the renewal date are missed, so the answer says it cannot tell. About 2 model calls and 3 seconds.

  2. 2

    Round one

    The agent plans three searches: breach exit clauses, renewal dates, and the company's security rules. Two come back strong. The security search returns weak hits, so the grader marks it weak.

  3. 3

    Round two

    It rewrites that search with the words the contracts use, such as unauthorised access, and gets three matching notice clauses.

  4. 4

    The answer

    Four suppliers allow an exit after a breach, and two of them renew this quarter. Each claim cites its clause and date. About 7 model calls and 14 seconds in total.

Tip

The trade is clear here. The agent fixed the miss, but it took about three and a half times the calls and nearly five times the seconds. Measure both before you ship.

How would you stop an agentic RAG system from running up cost or looping?

Put limits on the loop, log what it does, and test it like any other system.

  1. 1

    Cap the rounds

    Set a maximum number of searches and model calls per question. When the cap is hit, return what was found and what is missing.

  2. 2

    Log every step

    Keep the query, the results, the grade and the reason for each rewrite. A lawyer can then audit the answer.

  3. 3

    Test on real questions

    Keep a set of real questions with known answers, and run it after each change. Look for wrong answers and for extra rounds that added nothing.

Tip

A strong answer names the two costs, calls and seconds, and the control that matters most: the step limit.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: an agent picks its own searches, grades the results and retries when they are weak.
  • What it fixes: questions with several parts, and first searches that miss.
  • What it costs: more model calls, more seconds, and more places to fail.
  • The limits: a step cap, logging, and tests on real questions.
  • When to skip it: a single search that already answers the question well.
  • Honesty about the term: it can be defined in several ways, so describe what your system does.

Common traps

  • Trap"It's just RAG with a smarter model."

    BetterSearch quality still decides the answer. Test the search on its own, then add the agent's planning and checks.

  • Trap"The model decides everything, so the code can stay simple."

    BetterYour code sets the step limit and the allowed sources. The model only proposes the steps.

  • Trap"More searches always give better answers."

    BetterMore rounds add cost and delay, and can drift off topic. Cap them and measure.

Can you spot the weak point?

Spot the risky setup

Which agent setup for a legal search is the risky one?

Quick check

A legal team's agent misses breach clauses in its first search. Which change is most likely to help?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q136What is GraphRAG?10 min
  2. Q138RAG vs long context: which to use?12 min
  3. Q143How do you answer multi-hop questions?12 min
  4. Q150How would you design RAG for 10 million documents?12 min
  5. Q133What are common RAG failure modes?11 min
  6. Q140How do you enforce access control in RAG?11 min

Last updated on 26 November 2026

Building an agent that searches your contracts or policies?

I can help you design an agent with step limits, checked searches and tests on real questions. Book a short call and tell me what your team needs to find.