LearnQuestion bank

Traces show your agent calling the same search tool 15 times with near-identical queries before timing out. What’s going on and how do you fix it?

Applied LLMTechnicalMedium

Answer it yourself first, out loud or on paper, then compare.

Answer

Model answer, written in a candidate's voice

In short

  • Likely a retry loop, not a search problem: the tool returns empty or unhelpful results and the agent has no clear stop rule.
  • Earlier results may be truncated from context, so the agent cannot see it already tried the same query.
  • The goal may be ambiguous, so the agent keeps re-searching instead of deciding what would count as done.
  • Fix the tool contract: return useful empty-state guidance and distinguish no-results from errors.
  • Add loop detection, a step budget with forced summarise-or-answer, and a planning step before searching.
  • If the goal is still unclear, ask the user rather than burning the budget.
  • Replay recorded failing traces as regression tests so the same loop fails fast in CI.

In full

The core issue is that the agent is stuck in a retry loop: the search tool is returning empty or unhelpful results without guidance, the errors are opaque, and there is no stopping criterion, so it keeps issuing near-identical queries until the timeout. Context truncation can make it worse by dropping earlier results, and an ambiguous goal can make ‘keep searching’ look like progress. I would fix the tool contract first: empty results should say what happened and what to try next, and errors should be distinguishable from genuine no-results. Then I would add loop detection for repeated queries, a step budget that forces a summarise-or-answer instead of another call, and a short planning step that defines what success looks like before searching. If the goal is still ambiguous after that, I would ask the user rather than burn the budget. Finally, I would replay the recorded failing traces as tests so this exact loop is caught before it reaches production.

Checked against sources by an independent AI reviewer.

What a strong answer covers

  • Causes: empty or unhelpful tool results without guidance, opaque errors, no stopping criterion, earlier results truncated from context, an ambiguous goal
  • Fixes: informative tool outputs (“no results; try X”), loop detection, step budget with forced summarise-or-answer, planning step, ask the user
  • Replay recorded failing traces as tests

Common mistakes

  • Raising the step limit
  • blaming the model without reading the tool outputs it saw