Home / Insights / Generative AI and LLMs
Generative AI and LLMs
Agentic RAG: Letting the Model Plan Retrieval Steps, and the Risks That Come With It
Agentic RAG lets a language model decide what to search, where, and when it has enough to answer. That flexibility helps with hard questions, but it adds cost, latency and a larger attack surface. This guide explains when it is worth it and how to keep it under control.
Key takeaways
- A fixed RAG pipeline retrieves once and answers; agentic RAG lets the model plan, search repeatedly, choose tools and check its own results before answering.
- It helps most with multi-part, ambiguous or cross-source questions; for simple look-ups a well-tuned fixed pipeline is cheaper, faster and easier to test.
- Every extra step adds cost, latency and a chance for errors to compound, so cap steps and budgets and measure cost per successful answer.
- Retrieved documents become a route for indirect prompt injection, and retrieval tools can give the agent more access than intended; OWASP lists both prompt injection and excessive agency among its top LLM risks.
- Keep retrieval tools narrow and read-only, enforce permissions outside the model, log every step, and evaluate the full trajectory, not just the final answer.
On this page
The first generation of enterprise knowledge search followed a fixed recipe: take the user’s question, retrieve the most relevant passages, and ask a language model to answer from them. It works well for direct questions. It struggles when a question has several parts, when the right source depends on the answer to an earlier sub-question, or when the first search returns nothing useful and the system has no way to try again.
Agentic RAG addresses this by letting the model plan its own retrieval: rewrite the query, choose which index or tool to search, look at what came back, and decide whether to search again before answering. This article is for CTOs, engineering leads and product owners considering that step. It explains how agentic RAG differs from a fixed pipeline, when it is worth the extra cost, the specific risks it introduces, and the controls and tests to put in place. If you are still building your first retrieval pipeline, our guide to keyword, vector and hybrid retrieval is a better starting point.
What agentic RAG is and how it differs from a fixed pipeline
The survey Agentic Retrieval-Augmented Generation: A Survey on Agentic RAG by Singh and colleagues describes agentic RAG as placing autonomous agents inside the retrieval pipeline so that they can adjust retrieval strategies, refine their understanding of context and adapt the workflow as they go, rather than following a static sequence. The authors identify four recurring design patterns: reflection, planning, tool use and multi-agent collaboration.
Fixed pipeline versus agentic loop
| Aspect | Fixed RAG pipeline | Agentic RAG |
|---|---|---|
| Control flow | Defined in code: retrieve, then answer | Model decides the next step in a loop |
| Number of searches | Usually one (sometimes with query rewriting) | Variable; the model searches until it judges it has enough |
| Sources | One index or a fixed set | Model chooses among indexes, databases, APIs or web search |
| Self-checking | None, or a separate fixed check | Model can critique results and retry |
| Cost and latency | Predictable | Variable, often higher |
| Testing | Test inputs and outputs | Test inputs, outputs and the path taken |
A useful middle ground
Anthropic’s engineering guidance on building effective agents draws a clear line between workflows, where language models and tools are orchestrated through predefined code paths, and agents, where the model directs its own process. Many retrieval problems sit comfortably in between: a routing step that picks an index, a query decomposition step that splits a question into sub-questions, and a fixed check that triggers one retry if no relevant passage is found. These are predictable workflows with some model-driven decisions, and they solve a large share of the problems people reach for agents to fix.
When agentic retrieval is worth the extra cost
The same Anthropic guidance recommends finding the simplest solution possible and increasing complexity only when needed, noting that agentic systems often trade latency and cost for better task performance. That trade-off should be explicit for every agentic RAG decision.
Question types that benefit
- Multi-part questions. “Compare our refund policy in Australia and the UK and tell me which one changed most recently” needs at least two searches and a comparison.
- Dependent questions. “Who owns the system that processes supplier invoices, and what is their escalation process?” requires finding the system first, then the owner, then the process.
- Cross-source questions. Answers that combine a policy document, a record in a business system and a recent ticket need the system to choose which source to query for each part.
- Ambiguous questions. When the first search is weak, an agent can reformulate the query or ask the user a clarifying question instead of answering from poor context.
Question types that do not
- Direct look-ups of policies, procedures or product facts, where one good retrieval is enough.
- High-volume, latency-sensitive features such as in-app help, where variable response times hurt the experience.
- Questions over a single, well-structured collection, where better chunking and re-ranking usually beat more steps.
Decision guide
| Situation | Recommended design |
|---|---|
| Mostly direct look-ups, one corpus | Fixed pipeline with hybrid search and re-ranking |
| Several corpora, questions usually target one | Workflow with a routing step |
| Frequent multi-part questions | Workflow with query decomposition and parallel retrieval |
| Open-ended research across many sources and tools | Agentic loop with step limits, budgets and trajectory logging |
| Questions that lead to actions in other systems | Separate retrieval from action; require human approval for actions |
For example, a 200-person logistics firm with an internal assistant might find that most staff questions are about procedures, handled well by a fixed pipeline, while operations managers ask cross-source questions about shipments, contracts and incident reports. Routing only the managers’ questions to an agentic path keeps costs predictable for everyone else. The split is illustrative.
Some questions are better served by a different retrieval structure rather than more steps. For thematic questions across a whole collection, see our article on when graph-based retrieval beats plain vector search.
The risks agentic RAG introduces
Giving the model control over retrieval changes the risk profile in four ways.
1. Indirect prompt injection through retrieved content
The OWASP Top 10 for LLM Applications entry on prompt injection (LLM01:2025) explains that indirect prompt injection occurs when a model accepts input from external sources such as websites or files, and gives the example of an attacker editing a document in a RAG repository to steer the model’s output. OWASP also notes that RAG and fine-tuning do not fully mitigate the problem. In a fixed pipeline, injected text can distort an answer. In an agentic loop, it can also steer the next search, the choice of tool, or what the agent does with the results. The more autonomy the loop has, the more an injected instruction can achieve.
2. Excessive agency through retrieval tools
OWASP’s LLM06:2025 Excessive Agency entry describes damage caused when a system acts on unexpected, ambiguous or manipulated model output, with three root causes: excessive functionality, excessive permissions and excessive autonomy. Agentic RAG systems often accumulate all three. A “search” tool that can run arbitrary database queries, a connector that uses a service account with access to every document, or a loop that can call write-capable APIs all extend what a compromised or confused agent can do.
3. Compounding errors
Anthropic’s guidance notes that autonomy brings higher costs and the potential for errors to compound across steps. A poor query rewrite leads to irrelevant results, which lead to a confident but wrong intermediate conclusion, which shapes the next search. The final answer can look well researched while resting on an early mistake.
4. Cost and latency variance
A loop that searches until satisfied has no natural upper bound. Some questions trigger many steps, and a small change in prompts or models can shift the average number of steps noticeably. Without limits, cost per question becomes hard to forecast.
| Risk | Fixed pipeline exposure | Agentic RAG exposure |
|---|---|---|
| Indirect prompt injection | Can distort the answer | Can steer searches, tools and actions |
| Permission leakage | Limited to one retrieval path | Multiplied across tools and sources |
| Error propagation | Single step | Compounds across steps |
| Cost and latency | Predictable | Variable without limits |
| Auditability | Input, context and output | Requires full trajectory logs |
Controls that keep agentic retrieval safe
The controls below combine OWASP’s published mitigations with practices we apply in knowledge search delivery.
Constrain the tools
- Offer only the retrieval tools the agent needs, each with a narrow purpose: search policy documents, look up a customer record by ID, list recent tickets for a project.
- Prefer purpose-built tools to open-ended ones. OWASP recommends avoiding open-ended capabilities such as arbitrary shell access; the retrieval equivalent is free-form query access to a database.
- Make retrieval tools read-only. If the assistant must also take actions, put them behind separate tools with human approval.
Enforce permissions outside the model
- Run every retrieval in the end user’s security context, so the agent can only find documents the user is allowed to see. OWASP recommends acting within the user’s own context with scoped, least-privilege authentication.
- Apply permission filters in the search layer and downstream systems, not in the prompt. The model should never be the component deciding what a user may access.
Treat retrieved content as untrusted
- Clearly separate and label retrieved content in prompts, as OWASP recommends, so it has limited influence over instructions.
- Validate tool calls and outputs with deterministic code: allowed tools, parameter formats, result sizes.
- Restrict which sources can be ingested, and monitor for unexpected changes to high-traffic documents.
Bound the loop
- Set a maximum number of steps and a token or cost budget per question, with a graceful fallback such as answering from what was found and saying what is missing.
- Set timeouts for each tool call and for the whole request.
- Route only question types that benefit to the agentic path.
Make every step visible
- Log the plan, each query, each tool call, the documents returned and the final answer with its citations.
- Monitor steps per question, cost per successful answer and failure modes. Our article on observability for AI agents in production covers tracing in detail.
For a broader security review of LLM applications, see our walkthrough of the OWASP Top 10 for LLM applications.
How to evaluate an agentic RAG system
The survey by Singh and colleagues lists evaluation among the main open challenges for agentic RAG, and in practice it is where many teams cut corners. Testing only final answers misses the cases where the system reached a correct answer by an unsafe or wasteful route, or a wrong answer through a single early mistake.
Step-by-step evaluation approach
- Build a test set by question type. Include direct look-ups, multi-part, dependent, cross-source and ambiguous questions, with reference answers and the sources a good answer should use. Our guide to building a knowledge search test set explains the basics.
- Compare against a fixed baseline. Run the same questions through your best fixed or workflow pipeline. If the agentic version does not clearly win on the question types it targets, it is not worth the cost.
- Score the answer. Measure correctness, completeness and faithfulness to cited sources.
- Score the trajectory. Check whether the agent used appropriate tools, stayed within permissions, avoided redundant searches and stopped at a sensible point.
- Measure cost and latency distributions. Report median and worst cases per question type, not just averages.
- Run adversarial tests. Plant documents containing injected instructions in a test corpus and check that the agent neither follows them nor changes its tool use. OWASP recommends adversarial testing and treating the model as an untrusted user.
- Re-run on every change. Changes to models, prompts, tools or indexes can shift behaviour substantially; Anthropic’s guidance recommends extensive testing in sandboxed environments.
Rollout checklist for agentic RAG
Before releasing an agentic retrieval feature to users, confirm each item.
- The question types that need agentic retrieval have been identified and a simpler workflow has been tried first.
- Retrieval tools are narrow, purpose-built and read-only.
- All retrieval runs in the end user’s security context, with permissions enforced in the search layer.
- Retrieved content is labelled as untrusted in prompts, and tool calls are validated in code.
- Any action beyond retrieval is a separate tool requiring human approval.
- Step limits, cost budgets and timeouts are set, with a graceful fallback.
- Every step is logged and traceable, with citations in the final answer.
- The test set covers each question type, with trajectory scoring and adversarial injection tests.
- Cost per successful answer and latency are monitored by question type.
- A named owner reviews logs and evaluation results on a regular schedule.
Our Enterprise Knowledge Search service builds permission-aware retrieval that filters by user, group or document label at query time, with hybrid search, cited answers and ongoing evaluation of retrieval accuracy and faithfulness. Those foundations are what make an agentic layer safe to add when your questions justify it.
Frequently asked questions
Is agentic RAG more accurate than standard RAG?
It can be on multi-part, dependent or cross-source questions, because it can search more than once and check its results. On direct look-ups it often brings no accuracy gain and adds cost and latency. Compare both on your own question set before deciding.
How much more does agentic RAG cost?
It depends on how many steps each question triggers, which varies by question and changes with prompts and models. Set step limits and per-question budgets, and track cost per successful answer by question type rather than relying on an average.
Can an agent leak documents a user should not see?
Yes, if retrieval tools use a broadly privileged account or permissions are enforced only in the prompt. Run every retrieval in the end user’s security context and apply access filters in the search layer, so the model cannot reach documents the user cannot.
How does prompt injection affect agentic RAG?
Instructions hidden in retrieved documents can influence not only the answer but also the agent’s next search and tool choice. OWASP recommends labelling external content as untrusted, validating outputs in code, applying least privilege and testing adversarially.
Should we use a multi-agent design for retrieval?
Usually not at first. Multi-agent collaboration adds coordination and evaluation complexity. Start with a single agent or a workflow with routing and decomposition, and move to multiple agents only if evaluation shows a clear benefit.
What should we log?
The plan, each query and tool call with parameters, the documents returned, the final answer with citations, and cost and latency per step. Without full trajectory logs you cannot audit answers, investigate incidents or improve the system.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- arXiv: Agentic Retrieval-Augmented Generation: A Survey on Agentic RAG (Singh et al., 2025, revised 2026) — accessed 9 November 2026. Supports the definition of agentic RAG, the four design patterns, and evaluation and governance as open challenges.
- Anthropic Engineering: Building effective agents (December 2024) — accessed 9 November 2026. Supports the distinction between workflows and agents, starting simple, the cost and latency trade-off, compounding errors and sandboxed testing.
- OWASP GenAI Security Project: LLM01:2025 Prompt Injection — accessed 9 November 2026. Supports indirect prompt injection through retrieved documents and mitigations including segregating untrusted content, least privilege and adversarial testing.
- OWASP GenAI Security Project: LLM06:2025 Excessive Agency — accessed 9 November 2026. Supports the root causes of excessive functionality, permissions and autonomy, and mitigations such as narrow tools, user-context authentication and human approval.
Related reading
Continue your research
Considering agentic retrieval for your knowledge search?
We can test it against a simpler pipeline on your real questions and design the permissions, limits and logging it needs.
