What it is
Agentic RAG replaces the fixed “retrieve once, then generate” pipeline with a loop controlled by the model. The model receives the question and a set of tools (search the knowledge base, query a system, fetch a document) and, at each step, either requests a tool call or writes the final answer. A runtime executes the requested tools and feeds the results back as new messages, until the model answers or a budget runs out.
Why it exists
Single-shot RAG searches once with the user’s wording. That fails for comparisons (two policy versions), chained questions (find the manager, then the approval rule for that manager), vague follow-ups (“and for part-timers?”), and questions whose answer lives in a live system rather than in documents. Letting the model plan queries, inspect results and search again handles these, at the price of more model calls.
How it works
The loop. Runtime sends the conversation plus tool definitions to the model. The model returns either text or one or more tool calls (name and JSON arguments). The runtime validates and executes them, appends the results, and calls the model again. Each step sees everything so far.
Query rewriting and decomposition. Often the first model step: turn the conversation into standalone queries, split compound questions into sub-queries that can run in parallel, add formal terms or filters (year, department). Rewriting is also useful on its own, as one cheap call in front of plain RAG.
Tools beyond search. The same mechanism reaches APIs and databases. The Model Context Protocol (MCP) standardises how tools, resources and prompts are exposed by servers and discovered by clients, so one HR or ticketing integration can serve many agents. Tool results are untrusted input to the model: they can contain wrong data or injected instructions.
Who executes. The model never runs anything. The runtime checks the tool name and arguments against a schema, authorises the call for the current user, applies timeouts and rate limits, executes it, logs it, and returns the result.
Cost. Steps are sequential because each depends on the previous result, so latency is the sum of the model calls. Input tokens grow with every turn as the transcript gets longer. Model load is questions × average calls per question; capacity planning has to use calls and tokens, not questions.
Control. A query router (rules, a classifier or a small model) sends simple questions to single-shot RAG and only hard ones to the agent. Budgets cap tool calls, tokens and wall-clock time per run; when one is hit, the runtime asks for a best-effort final answer. Streaming progress (“searching the 2025 policy…”) keeps users informed during multi-second runs.
When to use it
- Questions that compare, aggregate or chain facts across documents.
- Assistants that mix document knowledge with live data from internal systems.
- Conversational use where follow-ups need rewriting into standalone queries.
- When answer quality on hard questions matters more than latency and cost per question.
When not to
- Simple lookups and FAQs: single-shot RAG is faster, cheaper and more predictable.
- Strict latency budgets (sub-second responses).
- Workflows with a known sequence of steps: write them as code (a fixed pipeline or workflow) and use the model only where judgement is needed.
- When you cannot evaluate or monitor multi-step behaviour yet: start with single-shot RAG plus query rewriting.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Agent loop | Multi-hop, comparison and tool-backed answers | Latency adds per step; tokens grow per turn; less predictable |
| Query rewriting only | Better retrieval for follow-ups and vague questions | One extra model call |
| Router in front | Agent cost only where needed | Misrouted questions; another component to evaluate |
| Tight budgets | Bounded worst-case cost and latency | Some hard questions get incomplete answers |
| Parallel tool calls | Lower latency for independent sub-queries | More concurrent load on tools and model |
Alternatives
- Single-shot RAG with query rewriting and hybrid retrieval: covers many “hard” questions at a fraction of the cost.
- Fixed multi-step pipelines: decompose, retrieve per sub-query, then synthesise, in code with a known number of calls.
- Structured queries: for aggregations over records, let the model call a query API or generate SQL against a read-only view instead of reading many text chunks.
- Precomputed answers or summaries for frequent complex questions.
Failure modes
- Runaway loops: the model keeps searching or retrying tools; cost and latency explode without budgets.
- Capacity multiplication: a traffic increase that single-shot RAG would absorb saturates the model deployment, and questions fail after several calls have already been paid for.
- Wrong tool, wrong arguments: the model calls a tool with invented parameters; schema validation and clear tool descriptions reduce it.
- Excessive agency: tools that write or delete without confirmation, or run with broader permissions than the user has.
- Prompt injection through tool results: retrieved documents or API responses containing instructions the model follows.
- Context bloat: long transcripts of tool results crowd out the question; summarise or truncate intermediate results.
In production
Trace every run as a tree: each model call (tokens, latency, model), each tool call (arguments, duration, result size) and the final answer; OpenTelemetry’s generative AI conventions cover the basics. Track calls and tokens per question, budget hits and tool error rates. Evaluate on multi-hop question sets, not only single-fact lookups. Run tools with the end user’s identity and least privilege, and require confirmation for actions with side effects. In .NET, Microsoft.Extensions.AI supports function invocation over IChatClient, the official MCP C# SDK provides clients and servers, and Semantic Kernel and Microsoft’s agent frameworks add orchestration on top.
Common misconceptions
- "Agents are always smarter." They handle certain question shapes better; for simple ones they are just slower and more expensive.
- "The model calls the API." The model emits a request; your runtime decides whether and how to execute it.
- "Cost scales with the number of calls." It scales faster, because each call re-sends the growing transcript.
- "A prompt instruction limits the loop." Only a budget enforced by the runtime does.
- "More capacity fixes agent overload." It helps, but routing and step limits usually cut model load more cheaply.
Interview angle
When an interviewer extends a RAG design with “what about complex questions?”, describe the agent loop with search as a tool, query rewriting, and when to prefer a fixed pipeline. Quantify: calls per question, latency as the sum of sequential calls, tokens growing per turn, model capacity in calls per second. Then show control: a router, budgets, parallel sub-queries, streaming progress, and a runtime that validates and authorises every tool call, with tracing for debugging.
Model assumptions
The simulation is a simplified model, not a benchmark. Questions arrive randomly (Poisson). The agent runtime calls its dependencies one after another in connection order, so the agent loop is a fixed chain of LLM, search, LLM, search, LLM (separate connections to the same nodes); in reality the model decides the number of steps at run time. The LLM has 16 concurrent slots, ~1.5 s per call (lognormal, cv 0.4) and a short waiting line; every call is modelled as equally long, although real calls grow with the transcript. Search takes ~40 ms. The query router is a weighted balancer with a fixed 30/70 split. Tool-call messages, query rewriting, loop budgets and MCP calls are scripted illustrations. Token counts are illustrative.