/pattern/agentic-rag/

04 · ProductionTool IntegrationAgent-driven RAGAutonomous RetrievalAdaptive RAGSelf-RAGCorrective RAG (CRAG)GraphRAGRAPTOR

Agentic RAG.
Retrieve only when it helps — and decide that yourself.

The agent decides autonomously whether, when, and how to retrieve — issuing and reformulating queries, selecting among sources, grading the relevance of returned passages, and iterating or skipping retrieval — instead of unconditionally retrieving once before generation. Named variants: Self-RAG (reflection tokens gate retrieval), Corrective RAG / CRAG (an evaluator scores evidence and triggers re-retrieval or a web fallback), GraphRAG (a knowledge graph for multi-hop questions), and RAPTOR (hierarchical tree-structured retrieval for long material).

In practiceA product-support agent re-queries its policy corpus with a refined term when the first retrieval scores below a relevance threshold, rather than answering from the weak hit.

When to reach for it

  • Some queries need external knowledge and others do not.
  • A single retrieval pass returns noisy or insufficient context.
  • The corpus spans multiple sources or tools that must be chosen per query.
  • Answer quality depends on iterative query refinement.

When it backfires

  • Every query needs the same single lookup — naive RAG is cheaper and more predictable.
  • Latency or cost budgets forbid the extra calls the retrieval decision adds.
  • The relevant knowledge already fits directly in the context window.

The tradeoff

Higher relevance and recall are bought with extra LLM calls, added latency, and a larger failure surface (mis-decided retrieval, query-reformulation loops).

The effect

What it actually does.

Relevant passages are retrieved before generation.

rewriteretrievegradegenerate
Pitfalls

Two ways this pattern will hurt you.

The retrieve-grade-rewrite loop never terminates

When no passage clears the relevance bar, the agent keeps reformulating and re-querying. Without a ceiling it burns tokens and latency chasing context that may not exist in the corpus.

Fix · Bound the loop: cap reformulation rounds, and on exhaustion fall back to answering from what was retrieved (or declaring the gap) rather than looping again.

The relevance grader passes a similar-but-unsupporting passage

A passage scores high on embedding similarity yet does not actually contain the answer. The grader waves it through, and the agent grounds a confident answer on evidence that never supported it.

Fix · Grade for answerability, not similarity: require the passage to actually support the claim (an entailment / does-it-contain-the-answer check), and cross-check across sources before generating.

Framework support

Where Agentic RAG is native.

LangGraphretrieve → grade → rewrite graph (canonical)Native
LlamaIndexrouter + agentic query enginesNative
OpenAI Agents SDKretrieval exposed as a toolAdaptable
CrewAIas custom retrievalAdaptable
Microsoft Agent Frameworkas custom graphAdaptable

Search

Search patterns, frameworks, and pages.