Agents interview question · Most asked

How do you stop an agent from looping forever or running up a huge bill?

Create a free account to save this page, take notes and track your progress. Sign in

Summary

Bound the loop in code: a maximum number of steps per task type, a token or cost budget, detection of repeated identical tool calls, and a wall-clock limit, with a graceful ending (summary and handoff) when a limit is hit. Also make tool results informative so the model has a better next action than retrying.

Longer Answer

The naive loop stops only when the model stops asking for tools, which a confused model may never do. Empty results like [] invite retries; "no orders match; order numbers have 8 digits" guides the next step. Track steps and cost per conversation and alarm on outliers.

Key Points

  • Step, cost and time budgets in code.
  • Detect repeated calls.
  • Informative tool results.
  • Graceful ending and alerts.

Deep dive: The Agent Loop and the Runaway Bill

Explanation

What interviewers look for

Limits enforced in code rather than in the prompt, and a plan for what the user sees when a limit is hit.

More most-asked Agents questions

← All Agents questions

Was this page helpful?