Agents, Tool Use & MCP·Question 76 of 90Quick-fire

How do you keep an agent from looping forever or running up cost?

Quick-fire answer from the Awesome Generative AI Guide (MIT)

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

Put hard limits in: a maximum number of steps or tool calls, a wall-clock or token budget, and a cost ceiling per task. Add progress checks so the loop stops when it is not advancing (repeated identical actions, no new information). Use cheaper models for routine sub-steps and a stronger one only where needed, cache stable context and tool results, and give the model only as much reasoning budget as the step requires. Design tools so failures return actionable errors the model can recover from rather than triggering blind retries.

Full worked answer

Put hard limits in: a maximum number of steps or tool calls, a wall-clock or token budget, and a cost ceiling per task. Add progress checks so the loop stops when it is not advancing (repeated identical actions, no new information). Use cheaper models for routine sub-steps and a stronger one only where needed, cache stable context and tool results, and give the model only as much reasoning budget as the step requires. Design tools so failures return actionable errors the model can recover from rather than triggering blind retries.

Learn more: Agents topic

What a good answer covers

  • Put hard limits in: a maximum number of steps or tool calls, a wall-clock or token budget, and a cost…
  • Add progress checks so the loop stops when it is not advancing (repeated identical actions, no new…
  • Use cheaper models for routine sub-steps and a stronger one only where needed, cache stable context and…
  • Design tools so failures return actionable errors the model can recover from rather than triggering…

Key terms: Learn more

Quick-fire answer from the Awesome Generative AI Guide (MIT) · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep