Topic 4 of 5 · 4 min read
Search loops, drift and premature stopping
Goal: Find the failure in an agent retrieval trace and name the guard that would have stopped it.
Agentic retrieval fails in a few recognisable ways, and each one has a cheap guard: repeated queries, drift off the question, stopping on a weak first hit, and a context filled with raw results.
Check yourself · 1 of 3
An agent runs the same search query three times in a row and gets the same hits each time. Which failure is this?
Why it matters
An agent that fails does not crash. It returns a fluent answer built on the wrong evidence, or it burns its budget and returns nothing. You find these failures by reading traces, and you prevent them with small checks in the loop.
The four failure modes and their guards
- Loops: the same query again. The agent gets a poor result and issues the identical or near-identical query. Guard: keep a list of past queries and refuse or flag a repeat; tell the agent in the error message to change terms, filters or source.
- Drift: wandering off the question. A side detail in one result becomes the new topic and later searches serve it. Guard: restate the original question in each step's note, and have the agent say how the next query serves it.
- Premature stopping: trusting the first weak hit. The top result is related but does not contain the fact. The agent answers anyway. Guard: require a supporting quote for each claim, and a stop check that asks "does a retrieved passage state this?".
- Context flood: raw results everywhere. Several large reads push the question and instructions far back, and answers get worse. Guard: cap result size, summarise old results, and keep only ids and key facts.
Reading a trace
Q: What is the SLA for priority-1 tickets on the Enterprise plan?
1 search("SLA priority 1 Enterprise") -> blog post about SLAs in general
2 search("SLA priority 1 Enterprise") -> same 5 hits
3 search("SLA priority 1 Enterprise plan") -> same 5 hits
4 answer: "Priority-1 tickets get a response within 1 hour."
Steps 2 and 3 are a loop: the query barely changed. Step 4 states a number that no result contained, which is premature stopping on a weak hit. Two guards would have caught it: a repeated-query check at step 2, and a rule that a number in the answer must have a quoted source.
What goes wrong
- Guards that only log. A warning nobody reads does not stop the run. Make the loop act: change tool, ask the user, or end with a stated gap.
- A budget as the only guard. It caps cost but not wrong answers.
- No traces stored. Without saved traces you cannot see which failure happens most.
- Fixing the prompt first. Often the fix is in the tool: better filters, clearer errors, shorter results.
Examples
Drift
The question is about refund rules for annual plans. A result mentions a billing outage in passing. Two searches later the agent is reading incident reports and the final answer discusses the outage. The fix: each note starts with "Original question: ..." and the agent states how the next query serves it.
A repeat guard
seen = set()
def search(query, **kw):
key = normalise(query)
if key in seen:
return {"error": "You already ran this query. Change the terms, add a filter, or try read_doc on a hit."}
seen.add(key)
return index.search(query, **kw)
The error is written for the agent, so it knows what to do next.
Key points
- Four common failures are repeated queries, drift off the question, stopping on a weak hit and a context flooded with raw results.
- A repeated-query check stops loops: record past queries and tell the agent to change terms, filters or source.
- Restating the original question in each step note and justifying the next query limits drift.
- Require a supporting quote for each claim so a related but empty hit cannot end the run.
- A step budget caps cost only; it does not catch wrong answers, so combine it with evidence checks.
Common mistakes
- Relying on the step budget alone and never checking whether the answer is supported.
- Logging repeated queries without changing the loop's behaviour.
- Tuning the system prompt before reading traces to see which failure actually occurs.
- Letting the agent answer with a number or name that no retrieved passage contains.
Check yourself · 2 of 3
An agent's answer states a figure that none of its retrieved passages contain. Which guard targets this?
Check yourself · 3 of 3
After six large document reads, an agent starts ignoring the formatting rules in its instructions. What is the most likely cause and fix?
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.