Agents interview question · Most asked
How do you stop an agent from looping forever or running up a huge bill?
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
- Agents leaf: What is the ReAct pattern?
- How do you evaluate an agent?
- Agents leaf: When should you avoid agents?
- How do you keep humans in control of an agent's risky actions?
- Agents leaf: How do you prevent infinite tool loops?
- Agents leaf: What is structured function calling?
- What is the difference between a workflow and an agent?
- Agents leaf: What is tool hallucination?