Agentic Pattern Libraryby Vikas Goyal
← All patterns
14

Agentic RAG

Also known as: active retrieval, iterative RAG, retrieval as a tool

The agent decides when and what to retrieve, rewrites queries and checks relevance.

TrackAgentic systems FamilyContext & memory Maturity Established ChangesContext
01

Problem

Classic retrieval-augmented generation runs one search with the user’s exact words and stuffs the top results into the prompt. That fails when the question is vague, needs facts from several sources, uses different wording than the documents, or doesn’t need retrieval at all. The model then answers from whatever came back, relevant or not.

  • User questions rarely match how documents are written.
  • Complex questions need several searches, often in different sources.
  • Irrelevant retrieved text misleads the model and wastes context.
  • Each extra search adds latency and cost.
02

Solution

Make retrieval a set of tools the agent controls instead of a fixed first step. The agent decides whether it needs to retrieve, which source to search (documents, tickets, a database), and how to phrase the query, splitting complex questions into sub-queries. It grades what comes back for relevance, discards weak results, and rewrites the query or tries another source when results are poor. It answers only from passages it kept, with a citation for each claim, and says so when it can’t find support.

03

Diagram

Question Agentplan sub-queries Documents Tickets Database Graderelevant? Answercited claims keep weak results → rewrite query or try another source

Retrieval is a loop the agent controls. Grading results before answering is what separates this from one-shot RAG.

04

When to use

Use it when

  • Questions vary widely in wording and complexity
  • Answers often need facts from more than one source
  • Users need citations they can check
  • Bad answers from irrelevant context are costly

Avoid it when

  • Simple lookups where one search reliably works
  • Strict latency budgets that can't absorb extra searches
  • The whole corpus fits in the context window; just include it
05

Trade-offs

Latency Multiple searches and grading steps
Cost More calls, but less irrelevant context per call
Complexity Retrieval tools, grading and query rewriting
Reliability Grounded, cited answers; admits when it can't find support

Gains

  • Handles vague and multi-part questions far better than one-shot search
  • Citations make answers verifiable
  • Can say "I couldn't find this" instead of guessing

Costs

  • Slower than single-pass retrieval
  • Grading quality limits answer quality
  • Retrieval loops can wander without a step limit
06

Worked example

Scenario
An internal assistant answers employee questions from HR policies, benefits documents and past HR tickets.
  1. Employee“Can I use my learning budget for a conference in Europe, and does the travel count against it?”
  2. AgentSplits this into two sub-queries: learning budget eligible expenses, and conference travel policy. It searches the policy documents first.
  3. GraderKeeps 2 of 6 passages. Drops a 2023 version of the policy, which has a newer replacement, and an unrelated passage on team offsites.
  4. AgentThe travel question isn’t answered by policy text. It rewrites the query and searches HR tickets, finding 3 resolved tickets about the same case.
  5. AnswerYes for the conference fee, up to the $2,000 annual budget. Travel is covered separately by the travel policy and needs manager approval. Each sentence cites a policy section or ticket.
07

Failure modes

FailureSymptomMitigation
Retrieval when not neededSimple questions slowed down by unnecessary searchesLet the agent answer directly when no retrieval is needed; measure it
Stale or conflicting sourcesAnswer mixes an old policy with a new oneStore version and date metadata; prefer the latest; flag conflicts
Weak gradingIrrelevant passages kept and quotedGrade each passage against the specific sub-question
Unsupported claimsAnswer goes beyond what retrieved text saysRequire a citation per claim; check with Draft–Verify