Every run carries a step budget and a token budget. The first bounds actions, the second bounds input size and hosted-service cost.
Both are set before the run and checked before each step. A run stops with a named reason when either budget is reached.
Budget | What it bounds | Stated example value |
|---|---|---|
Step budget | Tool calls and loop turns | At most 10 steps. |
Token budget | Total input tokens read | At most 10000 tokens. |
Stop reason | Which budget stopped the run | One of done, step-budget, or token-budget. |
Cost follows tokens times a stated example rate. The calc block shows the formula with substituted numbers, result, and units.
assume 1 million input tokens cost 3 units (stated EXAMPLE parameter)
run = 5 steps x 2000 tokens per step = 10000 tokens
cost = 10000 / 1000000 x 3 units = 0.01 x 3 units = 0.03 units
per step = 0.03 / 5 = 0.006 unitsReal rates differ between services and change over time. Substitute the current figures before deciding.
Least privilege applies to budgeted runs. Keep credentials and secrets out of prompts; share proprietary material only through an account and deployment approved for its data class and task, and require human approval before risky actions such as writes outside the task directory.
The program below is a small controller model, not a model itself. It checks both budgets before each synthetic step and records the stop reason.
import sys
def run_budget(costs, max_steps, max_tokens):
used_steps = 0
used_tokens = 0
stopped = ""
cutoff = 0
for i, c in enumerate(costs):
if used_steps >= max_steps:
stopped = "step-budget"
cutoff = i
break
if used_tokens + c > max_tokens:
stopped = "token-budget"
cutoff = i
break
used_tokens += c
used_steps += 1
else:
stopped = "completed"
cutoff = len(costs)
return used_steps, used_tokens, stopped, cutoff
def check(cond, msg):
if not cond:
print("FAIL: " + msg)
sys.exit(1)
costs = [800, 1200, 900, 1500, 700]
s1, t1, r1, k1 = run_budget(costs, 4, 4000)
check(s1 == 3 and t1 == 2900 and r1 == "token-budget" and k1 == 3, "case 1 got different stop point")
s2, t2, r2, k2 = run_budget(costs, 3, 100000)
check(s2 == 3 and t2 == 2900 and r2 == "step-budget" and k2 == 3, "case 2 got different stop point")
s3, t3, r3, k3 = run_budget(costs, 10, 100000)
check(s3 == 5 and t3 == 5100 and r3 == "completed" and k3 == 5, "case 3 got different totals")
print("PASS: budget enforcer stopped at step 3 with 2900 tokens and completed 5 steps with 5100 tokens")The three cases cover a token stop, a step stop, and completion. Totals of 2900 and 5100 tokens follow from the listed per-step costs and loop bounds.
It stops before the fourth step with 2900 tokens. 800 plus 1200 plus 900 is 2900, and adding 1500 would reach 4400.
After 3 steps with 2900 tokens for a step-budget stop. The fourth step is refused because 3 steps are already used.