promptdojo_

The loop with a meter — budget caps, stop reasons, and the trace — step 7 of 8

Write run_loop(plan, caps) — the metered loop, as a function you can point at any plan with any budget. Per iteration, in order:

  1. If the step number exceeds caps["max_steps"] → print stop: step-cap and return.
  2. If spent + COST[tool] exceeds caps["max_cost_usd"] (strictly) → print stop: cost-cap ($X.XX spent) and return.
  3. Otherwise spend, then print step N: tool $X.XX with the running total.

If the plan runs out naturally, print stop: plan-complete ($X.XX spent).

All money is $ + two decimals. Three runs exercise all three exits:

step 1: get_failing_jobs $0.02
step 2: read_log_tail $0.05
step 3: open_issue $0.09
stop: plan-complete ($0.09 spent)
step 1: get_failing_jobs $0.02
step 2: rerun_job $0.13
step 3: rerun_job $0.24
step 4: rerun_job $0.35
stop: step-cap
step 1: rerun_job $0.11
step 2: rerun_job $0.22
stop: cost-cap ($0.22 spent)

full-screen editor opens — close anytime to keep reading.