When the agent itself decides when and how often to ask again
Classic RAG retrieves documents once and answers the question with the context it found. Agentic RAG goes a step further: Claude itself decides whether a first retrieval pass is enough, whether a follow-up query with refined search terms is needed, or whether multiple distinct knowledge sources must be combined. This article shows how to build such pipelines with clean tool definitions, where their limits lie, and how to debug multi-step chains when something goes wrong.
Table of Contents
- 1. The difference from classic RAG
- 2. When classic RAG hits its limits
- 3. Tool definitions for retrieval steps
- 4. The agent loop: how Claude decides on further queries itself
- 5. A concrete multi-step retrieval scenario
- 6. Limits of agentic RAG pipelines
- 7. Debugging multi-step agent chains
- 8. Guardrails: max step count, timeout, and fallback
- 9. Evaluation: measuring the quality of agentic RAG answers
- 10. Summary
- 11. FAQ
1. The difference from classic RAG
Classic RAG follows a fixed sequence: embed the query, retrieve the most similar chunks, insert the result into the prompt, generate an answer. This sequence always runs exactly once, regardless of whether the retrieved chunks actually suffice to answer the question. For simple factual questions this works reliably; for more complex queries with several sub-aspects, a single retrieval pass often delivers only part of the needed information.
Agentic RAG hands control of the retrieval process itself to Claude. Instead of a fixed sequence, the model gets one or more retrieval tools and decides on its own when to call them, with which search terms, and whether another call is needed to formulate a complete answer. The key difference, then, is not the index being used but who controls the flow.
2. When classic RAG hits its limits
Classic RAG typically hits its limits when a query contains several independent sub-questions whose answers come from different documents, for example compare the return policy of product A with product B and explain the difference. A single retrieval step often returns hits for only one of the two products, since both search terms compete for the same top positions.
Classic RAG also fails structurally for queries that require a first rough answer before the actual, more precise search query can even be formed. One example: first determining which product version a customer uses before searching for the matching documentation. Agentic RAG is designed exactly for these multi-step dependencies.
3. Tool definitions for retrieval steps
The quality of an agentic RAG pipeline depends heavily on how precisely the retrieval tool is described. A vague description like searches the knowledge base leads Claude to call the tool either too rarely or with unsuitable search terms. A clear description of the expected input parameters, the available filters, and the return structure noticeably improves retrieval quality.
It also helps to offer several specialized retrieval tools instead of a single generic one, for example separate tools for product documentation, support tickets, and legal text. The model then makes an explicit decision about which source fits which sub-question, instead of everything being blended into one shared, less precise index.
{
"name": "search_product_docs",
"description": "Searches exclusively the technical product documentation for relevant sections. Not suitable for support tickets or legal text. Provide precise, specific search terms, not full sentences.",
"input_schema": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Precise search terms, e.g. 'webhook retry logic'"},
"product": {"type": "string", "description": "Product name to narrow the scope, e.g. 'checkout-api'"},
"max_results": {"type": "integer", "default": 5}
},
"required": ["query"]
}
}
4. The agent loop: how Claude decides on further queries itself
At its core, an agentic RAG pipeline runs as a classic tool-use loop: Claude receives the user query along with the available retrieval tools, decides whether and which tool to call, gets the result back in context, and decides again whether another query is needed or whether enough information is available to answer. This loop can continue over several rounds until the model delivers a final text answer without another tool call.
The system prompt is decisive for reliability here, since it clarifies when another query makes sense and when the model should answer with the information already at hand. Without that guardrail, the model tends either to launch unnecessary further queries when the context already suffices, or, conversely, to answer prematurely with incomplete information.
messages = [{"role": "user", "content": user_query}]
while True:
response = client.messages.create(
model="claude-opus-4-5",
system=AGENT_SYSTEM_PROMPT,
tools=[search_product_docs, search_support_tickets],
messages=messages,
max_tokens=2048,
)
messages.append({"role": "assistant", "content": response.content})
tool_calls = [b for b in response.content if b.type == "tool_use"]
if not tool_calls:
break # Claude decided enough context is available
tool_results = [run_retrieval_tool(tc) for tc in tool_calls]
messages.append({"role": "user", "content": tool_results})
5. A concrete multi-step retrieval scenario
A realistic scenario: a customer asks why a specific API endpoint returns a 429 error in their environment. In the first step, Claude retrieves the general API documentation on rate limiting. The information found is not enough to explain the specific cause, though, since it does not include customer-specific limits.
Claude recognizes this gap on its own and, in a second step, issues a more targeted query to a separate tool that searches support ticket history to find out whether an individual rate limit is configured for this customer. Only with both information sources combined can a complete, correct answer be formed. This exact ability to recognize and close a knowledge gap on its own is what distinguishes agentic from classic RAG.
6. Limits of agentic RAG pipelines
More control over the retrieval process also means more uncertainty in the flow. Every additional query round increases latency and token cost, and without a clear cap, the model could in principle trigger an unbounded number of queries in sequence, for example when search results are consistently unsuitable and the model keeps trying new phrasings.
Another risk is traceability: with a single retrieval step, it is easy to see which documents fed into the answer. With three or four consecutive, model-chosen queries, the chain becomes more complex, and without structured logging it becomes hard to reconstruct afterward why the model reached a particular conclusion.
7. Debugging multi-step agent chains
Debugging starts with complete tracing of every round of the agent loop: which tool call happened with which parameters, what results came back, and what intermediate reasoning extended thinking may have formulated along the way. Without that record, a faulty final answer leaves it unclear whether the problem was in retrieval, in intermediate interpretation, or in the final phrasing.
One practical debugging approach is to isolate each tool-call round individually and afterward ask Claude whether the chosen search query made sense in hindsight and which alternative phrasing would have delivered better hits. This retrospective analysis frequently reveals that the tool description itself was unclear, rather than the model having made a fundamentally wrong decision.
Prompt for a retrospective analysis of a failed run:
Here is the complete trace of an agent loop with 3 tool calls
and the final (incorrect) answer: <insert trace>
Analyze step by step: was each search query phrased sensibly?
At which point would a different phrasing have produced better
hits? Was the tool description precise enough to enable the
right decision?
8. Guardrails: max step count, timeout, and fallback
Every agentic RAG pipeline should have a hard cap on the number of retrieval rounds per query, typically three to five, to avoid uncontrolled cost explosion and excessive latency. When the cap is reached without enough information available, the pipeline should give an honest answer that the question could not be fully resolved, instead of presenting an incompletely researched answer as final.
It is also worth adding a timeout per individual tool call and a clearly defined fallback path, for example escalating to a human support agent when the pipeline still cannot form a sufficiently grounded answer after the maximum step count.
9. Evaluation: measuring the quality of agentic RAG answers
Classic RAG metrics like hit rate per retrieval step are not enough for agentic RAG, since the actual performance lies in the sequence of decisions, not in a single retrieval call. Useful evaluation metrics therefore also include the average number of steps needed per query type, the rate of queries that hit the step limit without a complete answer, and the consistency of the final answer across repeated runs of the same query.
A solid evaluation set consists of queries that deliberately combine several sub-questions, so they can only be answered correctly through multi-step retrieval. Only that way can it be measured whether the agentic pipeline actually delivers the hoped-for benefit over classic, single-pass RAG, rather than just adding cost without measurable quality gain.
| Criterion | Classic RAG | Agentic RAG |
|---|---|---|
| Retrieval flow | Fixed, exactly one pass | Variable, controlled by the model |
| Best suited for | Simple factual questions | Multi-part, dependent questions |
| Latency | Predictable, low | Variable, potentially multiple rounds |
| Cost per query | Constant | Depends on step count |
| Traceability | Simple (one retrieval step) | Requires structured tracing |
| Failure risk | Missing hits in the one step | Runaway loops without guardrails |
Mironsoft
AI-assisted development, agent workflows, and team processes
Using Claude or other AI tools on the team, but without a clear workflow?
We set up AI-assisted development workflows for teams, from CLAUDE.md conventions to subagent strategies to code review processes that combine human oversight with AI speed.
Workflow Setup
Cleanly set up CLAUDE.md, project conventions, and tool permissions for the team.
Agent Strategy
Build subagent and automation workflows for recurring development tasks.
Team Onboarding
Train developers in productive, safe use of AI coding assistants.
10. Summary
Agentic RAG Pipelines: The Essentials
Core difference
The agent decides on further queries itself instead of retrieving once.
Tool design
Specific, well-described retrieval tools instead of one vague search tool.
Limits
Higher latency, higher cost, and risk of uncontrolled query chains.
Safeguards
Fixed step limits, timeouts, and an honest fallback when no answer is found.