Step Budget
Cap the number of tool calls or loop iterations the agent is allowed within a single request.
Problem
If termination relies on the model saying 'I am done', then a confused, stuck, or over-eager agent will simply never declare itself done, and the loop runs until something else stops it — a timeout, a crash, or an angry invoice at the end of the month. The team has no way to bound the worst-case cost or latency of a single request, and one pathological session can burn through more budget than thousands of normal ones combined. Without a hard numeric cap that the loop respects regardless of the model's opinion, runaway behaviour is always one bad prompt away.
Solution
Define a numeric cap (max_steps=N) in the agent loop. Increment per tool call or per loop iteration. When N is hit, terminate the loop and return the best partial answer with a note that the cap was reached.
When to use
- The agent has any kind of loop (ReAct, plan-execute, debate).
- Cost or latency must have a hard ceiling regardless of the agent's opinion.
- Runaway behaviour must be impossible by construction.
Open the full interactive page →
Diagram, neighbourhood map, code examples, related patterns and full provenance.
Related
- Cost Gating
- Human-in-the-Loop
- Infinite Debate
- Unbounded Subagent Spawn
- Unbounded Loop
- Spec-Driven Loop
- Plan-and-Execute
- Stop Hook
- Stop / Cancel
- Outer-Inner Agent Loop
- Agent-as-Tool Embedding
- Mode-Adaptive Cadence
- Typed Tool-Loop Failure Detector
- Iteration Node
- Demo-to-Production Cliff
- Token-Economy Blindness
- Missing max_tokens Cap
- Compound Error Degradation
- Composable Termination Conditions
- Session-Scoped Payment Authorization