Agents, Tool Use & MCP·Question 51 of 90Advanced

Your agent gets stuck in loops or gives up too early. Diagnose and fix both.

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

These are opposite ends of one spectrum - miscalibrated persistence - and both are harness problems as much as model problems.

Full worked answer

These are opposite ends of one spectrum - miscalibrated persistence - and both are harness problems as much as model problems.

Loops. Signatures in traces: identical tool calls repeated (same name + args), A/B oscillation between two actions, or "productive-looking" cycles that never converge (edit → test fails → same edit). Root causes: the model can't see it's repeating (context too polluted to notice), an error message gives no direction to change (so the retry is identical), or the task is actually impossible with the available tools and the model has no way to conclude that.

Fixes, harness-side first: duplicate-call detection - hash recent tool calls; on a repeat, don't execute, return "you already ran this; the result was X; identical retries will not differ - try a different approach" (this one intervention kills most loops). Add a no-progress counter that triggers a forced reflection step ("summarise what you've learned and list approaches not yet tried"), then escalation or clean abort with a partial-results report. Fix the tool side: error messages that suggest a different next action, since directionless errors are loop fuel.

Giving up early. Signatures: "I don't have access to X" when a tool provides X, offering a partial answer three steps in, or asking the user for information it could retrieve itself. Root causes: timid default personas, tool descriptions that don't make capabilities obvious, prior errors in context creating learned helplessness ("everything I try fails"), and genuinely ambiguous task specs.

Fixes: explicit persistence policy in the system prompt ("attempt at least N distinct approaches before reporting failure; exhaust available tools before asking the user"), paired with an explicit boundary: blocked tools, auth walls, rate limits and permission denials mean stop and escalate, never route around them. State the task's scope and permitted actions, because persistence without a boundary is how agents end up working round a restriction instead of stopping, a cause Anthropic named in its October 2026 report on unintended real-world agent actions. Beyond that: tool descriptions that advertise capability clearly, clearing failed-attempt debris from context so past errors don't cast a shadow, and - importantly - verification requirements on claims of impossibility, symmetric with verifying claims of success.

Both directions need eval coverage: seed tasks that require persistence, and impossible tasks (including tasks impossible by policy, where the only way through is a workaround) where the correct behaviour is a clean, early, well-explained stop. Calibration means passing both.

What a good answer covers

  • These are opposite ends of one spectrum - miscalibrated persistence - and both are harness problems as…
  • Signatures in traces: identical tool calls repeated (same name + args), A/B oscillation between two…
  • Root causes: the model can't see it's repeating (context too polluted to notice), an error message gives…
  • Fixes, harness-side first
  • Add a no-progress counter that triggers a forced reflection step ("summarise what you've learned and…

Key terms: Loops · duplicate-call detection · Giving up early

Interviewer follow-ups to expect

  1. How do you distinguish a productive retry from a loop programmatically?

  2. What's the right behaviour when the agent correctly determines a task is impossible?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep