Best Practices for Building LLM Apps

Chapter 4 · Practice 4 of 5

Cap agent steps, time and spend per task

From Tools, agents and least privilege

Why it matters

Agents can loop: retrying a failing tool, re-reading the same document, or calling each other. Unbounded consumption is on the OWASP list for a reason.

Set a limit on every dimension a task can grow along:

  • a maximum number of model calls and tool calls per task;
  • a wall-clock timeout;
  • a token or cost budget.

When any one is hit, stop cleanly with a useful message and record which limit stopped the task.