Because the model drives the loop, an agent can run longer, spend more and do more than you planned. Every agent needs three guardrails, always, and all three together.
1. Maximum steps#
Cap the number of iterations. If the agent has not finished after 15 tool calls, something has gone wrong.
- Stop the loop.
- Return what you have so far.
- Surface an error.
Never let an agent run unbounded.
2. Budget cap#
Each iteration is another model call, possibly a tool call, and more tokens. Set a maximum token or cost budget per request. A runaway agent is also a runaway bill.
3. Human approval for risky actions#
Before anything irreversible, that is anything that sends, deletes, pays or publishes, pause and ask the user to confirm.
The model may have misunderstood the intent, and once the action is taken you cannot undo it. A person approving the action is also what stops a prompt injection from turning into a real action.
Why all three#
| Guardrail | What it stops |
|---|---|
| Maximum steps | A loop that never finishes |
| Budget cap | A loop that finishes but costs far too much |
| Human approval | A single wrong step that cannot be undone |
Each one covers a failure the other two miss. A step cap does not stop one expensive step, and neither cap stops an irreversible action on step 2.
These are the same controls as for any tool calling loop: see Limits and Risky actions. With an agent they matter more, because the model, not your code, decides how far the loop goes.
Short line#
Every agent needs three guardrails together: a cap on steps so it cannot run unbounded, a token or cost budget so it cannot run up a bill, and human approval before anything that sends, deletes, pays or publishes.
Key takeaways#
- Always use all three guardrails together.
- Maximum steps: for example 15 tool calls, then stop, return what you have and surface an error.
- Budget cap: a maximum token or cost budget per request.
- Human approval before any irreversible action: send, delete, pay or publish.
- Each guardrail covers a failure the other two miss.