Your AI assistant answered confidently. The answer was wrong. The fix is letting it check its own work
Your AI assistant answered confidently. The answer was wrong. The fix is letting it check its own work A manager asks the staff help assistant a simple question: "Does the new parental leave apply to contractors, and w
Your AI assistant answered confidently. The answer was wrong. The fix is letting it check its own work
A manager asks the staff help assistant a simple question: "Does the new parental leave apply to contractors, and what changed since last year?"
The assistant searches once. It finds three pages about leave. None mention contractors. It writes a calm, confident answer anyway. The answer is wrong.
One search was never going to be enough. A person would have looked in a second place. The question is whether an assistant can learn to do that too.
Basic RAG is a single shot. Documents are cut into chunks, a question is searched by meaning, and the model writes the answer from the best chunks. Search once, then answer, even when the search was poor. The manager's question has two parts, who the leave applies to and what changed, and the first search covered only the second. A single-shot system has no way to notice.
Give the assistant a loop, not a single shot
Agentic RAG changes one thing. The model gets to make some of the choices instead of following one fixed path. Think of a research assistant who checks the first shelf, says "this is not it", and walks to a different shelf.
The loop has five moves:
Decide whether to search at all. A "hello" needs no lookup. A company policy does. Skipping needless searches saves time and money.
Pick a source. The handbook, the ticket history, a database, or the web. Staff leave rules live in the handbook. Contractor terms live in a separate contractor guide. Choosing the right shelf first is called routing.
Grade what came back. A grader is a check, often another model call, that asks one question: "Do these pages answer the question?" This is the step a single-shot system skips, and it is the whole point. The grader is not magic: one more model call with a short, strict prompt, replying with one verdict only, ENOUGH or NOT ENOUGH, with one line naming what is missing. The prompt forbids answering the question. A grader that answers instead of judging hides the very gap it exists to catch.
Rewrite and retry when the grade says not enough. The model turns "Do contractors get it?" into "contractor eligibility for parental leave", and tries a different source. A retry should change the question or the source. Retrying the same search is wasted money.
Stop with a sourced answer, or with an honest "I could not find it".
What the extra loops cost
Every box in the loop is a search or a model call, so every loop adds wait and money. The chapter works it out with made-up numbers, so you can talk about cost with a customer.
One search takes 0.3 seconds and costs 0.0005 dollars. One grading call takes 1.0 second and costs 0.001 dollars. The final answer call takes 1.5 seconds and costs 0.002 dollars.
Basic RAG, one search and one answer: 1.8 seconds, 0.0025 dollars. Agentic RAG with one loop: 2.8 seconds, 0.0035 dollars. Agentic RAG that runs all three loops to the cap: 5.4 seconds, 0.0065 dollars. Three times slower, 2.6 times costlier.
That is why the cap matters. Three tries is a common starting point. When the tries are used up, the model stops. "I could not find this. Here is what I did find." An honest gap beats a confident guess, and the cap is the dial that decides how much a hard question is allowed to cost.
Four ways the loop breaks
A loop that does not tire is a loop that can run away. Four failures to plan for:
It never ends. The model keeps trying. Fix: a hard step cap, for example 3.
The grader is too trusting. It says "good enough" for weak pages. Fix: check the grader against human judgement on a sample, for example 50 real questions you check by hand. A grader is a model too, and it can be wrong.
The agent reads what the asker may not. Fix: the agent may only search what the asker may read. Enforce it in the search tool, not in the prompt.
You cannot see what happened. Fix: log every step, the source, the query, the pages, and the grade. With a log like that, a bad answer stops being a mystery.
When to skip it entirely
Agentic RAG is not always better. For simple lookups, it is slower and costlier, with no gain. "What is the office wifi password policy?" needs one good search. A live voice call often cannot wait through three loops. And when basic RAG is already failing, fix the chunks and the search first. A loop on a weak search just fails more slowly.
A useful middle path: run one search, grade it, and only loop if the grade says "not enough". Easy questions then stay fast, and only the hard ones pay for extra tries.
The same question, two ways
One search, no loop: "Yes, the new parental leave applies to contractors, and it rose from 12 to 16 weeks." Confident, calm, and wrong. The pages behind it never mentioned contractors.
With the loop: "Parental leave for staff rose from 12 to 16 weeks (staff handbook, 'Parental leave'). Contractors are not covered by the staff policy; a different process applies (contractor handbook, page 4)." Slower, and a reader can check every claim.
One limit to keep in mind. The loop can judge whether it has enough pages. It cannot judge whether its final answer is actually right: a smooth answer can still misread good pages. Checking the answers themselves is a separate job, and later chapters in the course teach it.
The full interactive chapter is free at https://deployedlab.dev/lessons/50-agentic-rag, with a clickable picture of the loop, a role-play where you make the choices yourself, and the worked cost sums. 11 chapters are free with no signup, and the full course is $5/month or $39/year at deployedlab.dev.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.