Topic 1 of 5 · 4 min read
The search, read and search again loop
Goal: Design the search tool, its result format and the stopping rule for an agent that answers questions over a document set.
Agentic retrieval turns search into a tool the agent calls in a loop: search, read what came back, decide whether it is enough, and search again with a better query if not.
Check yourself · 1 of 3
What is the main difference between single-pass RAG and agentic retrieval?
Why it matters
A classic RAG pipeline retrieves once and answers with whatever came back. If the first query was phrased badly, or the answer needs two documents, the model answers from the wrong evidence and sounds sure. A loop lets the agent notice a weak result and fix it. This is the reason-act-observe pattern from the ReAct paper, applied to search.
How to build it
- Give the agent one clear search tool. A name such as
search_docs, aquerystring, an optionalfiltersobject and alimit. Describe in the tool description what the index holds and what it does not. - Return compact results. Each hit carries an id, a title, a short snippet, a source and a score. Let the agent open a full document with a second tool such as
read_doc(id). Do not paste whole documents into every search result. - Let the agent judge. After each result the agent writes down what it learned and what is still missing. That note drives the next query.
- Set the stopping rule. Stop when every part of the question is backed by a cited passage, or when a step budget is hit. On budget, the agent must say what it could not find.
- Require citations. The final answer lists the ids it used, so a human can check them.
Before and after
Weak: one call, search("refund policy"), the top 5 chunks pasted into the prompt, answer written. The question was "Can a customer who bought in the EU in March return an opened item?" The chunks cover the US policy.
Better:
Step 1 search_docs("refund policy opened items") -> 5 hits, all US
Note Results are US-only. Need EU rules.
Step 2 search_docs("EU returns", filters={region:"EU"}) -> 3 hits
Step 3 read_doc("eu-returns-2025") -> opened items: 14 days
Note Covers region and opened items. Date rule still unknown.
Step 4 search_docs("returns window purchase date") -> window starts at delivery
Stop All three parts cited. Answer.
What goes wrong
- Weak tool descriptions. If the agent does not know what the index covers, it searches for things that are not there.
- No stopping rule. The agent keeps searching or stops after the first plausible hit.
- Fat results. Full documents in every result fill the context before the second search.
- No written judgement. Without a note on what is missing, query two is just query one reworded.
Examples
A search tool definition
{
"name": "search_docs",
"description": "Search the support knowledge base (articles, policies, release notes). Does not contain customer records or pricing. Returns up to `limit` hits with id, title, snippet and source.",
"input_schema": {
"type": "object",
"properties": {
"query": { "type": "string" },
"filters": { "type": "object", "description": "Optional: region, product, year" },
"limit": { "type": "integer", "default": 5 }
},
"required": ["query"]
}
}
The description names what is out of scope, so the agent does not search for pricing here.
A stop note
At step 4 the agent writes: "Covered: region (EU), item state (opened), window start (delivery). Missing: nothing. Sources: eu-returns-2025, returns-faq-12." That note is the stopping evidence, and it doubles as the citation list.
Key points
- Retrieval becomes a tool the agent calls in a loop: search, read, judge, then search again or stop.
- Search results should be compact (id, title, snippet, source) with a separate tool to open a full document.
- The agent should write down what it learned and what is still missing after each result; that note shapes the next query.
- A stopping rule needs two exits: every part of the question is cited, or the step budget is reached and the gaps are stated.
- The tool description must say what the index contains and what it does not.
Common mistakes
- Writing a one-line tool description, so the agent does not know what the index covers.
- Returning whole documents from the search tool and filling the context after two calls.
- Having no stopping rule, so the agent either loops or stops at the first plausible hit.
- Letting the agent rewrite the query without first stating what the last result was missing.
Check yourself · 2 of 3
Why should a search tool return short snippets and ids instead of full documents?
Check yourself · 3 of 3
An agent has searched twice and the notes show the question's three parts are all backed by cited passages. What should it do?
Practice items, not counted towards your mastery.
Start here
- How we built our multi-agent research system (Anthropic) (opens in a new tab)ArticleFree
How a lead agent plans, fans out parallel search sub-agents and merges results, with the costs and failure modes the team met.
- ReAct: Synergizing Reasoning and Acting in Language Models (opens in a new tab)PaperFree
The original reason-act-observe loop that every search-and-read agent is built on.
- Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection (opens in a new tab)PaperFree
Shows a model deciding when to retrieve and critiquing what it retrieved, the judge step in the loop.
More for this topic
- Writing effective tools for AI agents (Anthropic) (opens in a new tab)ArticleFree
How to design tool names, parameters and result formats an agent can use well, including search tools.