Lesson 6 / 25

Hard Limits: Steps, Time, Tokens, Money

Choose sensible default limits and decide what happens when each is reached.

Four independent limits

Use several limits because each catches a different failure. Steps catch endless loops. Wall-clock time catches slow or hanging tools. Tokens catch context bloat. Money catches an expensive model used too often. Hitting any one should end the loop with a clear reason.

Defaults in one place

Treat these numbers as a starting point to tune from real runs. A simple task needs far less than a research task.

LIMITS = {
    "max_steps": 15,
    "max_seconds": 120,
    "max_total_tokens": 150_000,
    "max_cost_usd": 1.00,
}

Decide the ending in advance

Per limit, decide: fail loudly, return a partial result, or ask a human. Deciding this at design time is much better than discovering it during an incident.

Quick check: Which limit best catches a tool call that hangs for minutes?

  • Step limit
  • Wall-clock time limit
  • Token limit
  • Cost limit
Answer

Wall-clock time limit — A hanging call uses few steps and tokens but a lot of real time.