# 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.

AI and LLM interview question Q137, Retrieval-augmented generation (RAG). Advanced, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-agentic-rag

## Say it in 30 seconds

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.

## Say it in 2 minutes

A standard RAG system has a fixed path. Your code takes the question, runs one search, passes the top results to the model, and the model writes the answer. Agentic RAG puts an agent in that path. The agent is a model that chooses its next step, so it decides what to search for and whether to search again.

Take a legal team asking which supplier contracts allow an exit after a data breach. One search may miss the clause, because contracts say security incident or unauthorised access. An agent can split the question into parts, search the contract index and the policy index, and grade each result. If the results are weak, it rewrites the query and tries again, with a hard limit on steps.

The cost is real. Each step adds model calls and seconds, and an agent can loop or pick the wrong source. So I would keep a simple pipeline for questions one search can answer. For the rest, I would set a step limit, log every search, and measure answer quality on a set of real questions before trusting it.

The word itself is used in several ways. Anthropic notes that agent can be defined in several ways, and a 2025 survey sorts these systems by how many agents they use, how they are controlled, how autonomous they are and how they represent knowledge. So the label covers a wide range. I would describe what my system actually does, and skip the argument over the label.

## 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.

- **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. **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. **Search:** It runs the searches. Several can run at the same time, as Microsoft's agentic retrieval does, which keeps the wait short.
3. **Grade:** It reads each result and asks whether it answers its part of the question.
4. **Retry or answer:** Weak results: it rewrites the query and searches again. Strong results: it writes the answer and cites the clauses.
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.

*Diagram, The agent's search loop: 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.*
1. The agent gets the legal question.
2. It sends searches to the contract and policy indexes.
3. The results come back, and the agent grades them.
4. Good enough: 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:

```text
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.

*Diagram, Two ways to search: 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.*
1. One search may miss the clause that matters.
2. The agent searches again with better queries and grades each result.

> "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. **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. **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. **Round two:** It rewrites that search with the words the contracts use, such as unauthorised access, and gets three matching notice clauses.
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. **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. **Log every step:** Keep the query, the results, the grade and the reason for each rewrite. A lawyer can then audit the answer.
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." Better: Search 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." Better: Your code sets the step limit and the allowed sources. The model only proposes the steps.
- Trap: "More searches always give better answers." Better: More 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?

A. Run up to 4 rounds of search, and stop early once the grader marks results strong.
B. Keep searching until the agent feels sure, with no limit on rounds.
C. Grade each result set, and rewrite the query only when the grade is weak.
D. Log every query, result and grade so a lawyer can audit the answer.

**Answer:** B. Without a step limit the loop can run on, adding cost and delay, and an agent that is never sure never answers. Cap the rounds, and return what was found and what is missing.

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

A. Add a longer system prompt
B. Let the agent grade the results and rewrite a weak query
C. Add a second model that checks the final answer
D. Lower the temperature

**Answer:** B. Grading and rewriting target the search that missed. A longer prompt, a second checking model or a lower temperature will not change which clauses the search finds.

## Can you answer these from memory?

**Flash cards**

- **What is agentic RAG?** Retrieval where an AI agent plans searches, grades the results and retries when they are weak.
- **Classic RAG vs agentic RAG?** Classic: one fixed search. Agentic: the model picks searches and checks them.
- **What does grading do?** Checks whether each search result actually helps answer its part of the question.
- **What is the main cost?** More model calls, more seconds, and more places for the loop to go wrong.
- **What stops the loop?** A hard step limit, then an honest answer on what was found and what is missing.
- **Is the term standardised?** Anthropic says agent can be defined several ways, so describe what your system does.

## Likely follow-up questions

- Q136 What is GraphRAG? https://designervenkat.online/interview/ai/what-is-graphrag
- Q138 RAG vs long context: which to use? https://designervenkat.online/interview/ai/rag-vs-long-context
- Q143 How do you answer multi-hop questions? https://designervenkat.online/interview/ai/how-do-you-answer-multi-hop-questions
- Q150 How would you design RAG for 10 million documents? https://designervenkat.online/interview/ai/how-would-you-design-rag-for-10-million-documents
- Q133 What are common RAG failure modes? https://designervenkat.online/interview/ai/common-rag-failure-modes
- Q140 How do you enforce access control in RAG? https://designervenkat.online/interview/ai/how-do-you-enforce-access-control-in-rag
