Agents and Tool Use · Making It Safe · lesson 5 of 7
Limits, budgets and stopping
about 20 minutes · free · runs in your browser
Three ways to stop, and you want all of them
A step limit alone is not enough. An agent can burn a large budget inside a small number of steps, or loop between two tools that keep undoing each other while making perfect progress by its own account.
| Guard | Stops |
|---|---|
| step limit | an unbounded loop |
| cost budget | expensive steps inside the step limit |
| no-progress detector | a loop that repeats the same call forever |
The third is the one people leave out. An agent calling search("refund policy") for the
fourth time is not working, however confident its reasoning sounds, and the cheapest
detector is simply noticing the repeat.
Your turn: build Guard with max_steps, max_cents and a repeat limit.
check(tool_name, args, cents) records a step and returns None to continue or a
string naming which limit was hit.
You start from this, and edit it in the browser:
class Guard:
def __init__(self, max_steps=6, max_cents=50, max_repeats=2):
self.max_steps = max_steps
self.max_cents = max_cents
self.max_repeats = max_repeats
self.steps = 0
self.cents = 0
self.seen = {}
def check(self, tool_name, args, cents):
"""Record a step. Return None to continue, or the reason to stop."""
return None