Agents, MCP and skillsLoading progress…

Stopping and budgets

Design a bounded observe-act loop with explicit state, stopping conditions and a verifiable task outcome.

Stopping and budgets

A loop that can run forever eventually will. Set limits on steps, time, tokens and cost, and stop repeating the same failing call. When a limit is reached, stop with a clear partial-result state: what was done, what was not, why it stopped. For a job that never completes, a step budget of 4 uses 2,400 tokens and, at toy prices, $0.008. Announcing success instead would be worse than the cost it saved.

step budget4token budgetoffcost budget ($)off
a job that is always pending; each check = 500 input + 100 output tokens (toy prices $2 / $10 per million) stopped by: steps limit after 4 steps, 2400 tokens, $0.008 result: PARTIAL. The agent reports where it got to and that the job is still pending; it does not claim success

Limit steps, time, tokens and cost, and stop repeating an unchanged failed call. A clean stop with a partial result is a success of the control system, not of the task.

Change the budgets and see which one stops the run.

Predict first. Should an unchanging failed tool call repeat without a bound?

Chapter context

An agent chooses actions based on a task and observations, often over several model calls. Useful autonomy requires bounded resources, explicit feedback and a stopping rule that recognizes both success and inability to continue.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

Represent a run as states s0,s1,... and actions a0,a1,... with observed transitions. A budget constraint can bound the sum of measured call costs. History-dependent token growth means a constant per-step estimate is only a simplifying model.

Worked example

A simulated agent may take at most three actions. It moves from room A to B, inspects a clue, then moves to C. The trace contains three actions. If the objective still is not satisfied, the correct result is budget exhausted with partial progress, not a fourth unapproved action or a fabricated success.

Reference code

The following example uses the Python standard library and does not call a remote service.

actions=['move:A->B','inspect:clue','move:B->C']
budget=3
assert len(actions) == budget
objective_satisfied=False
status='complete' if objective_satisfied else 'budget-exhausted'
assert status == 'budget-exhausted'
assert len(actions)*.002 == .006

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

A plan is not execution evidence. Reflection can repeat the original mistake. A step budget is useful only if every executed action is counted consistently.