promptdojo_

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

Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Checkpoint: bolt lesson 1 onto lesson 2. Write triage_run(plan, caps) where each plan entry is a call dict ({"tool": ..., "confirmed": ...}), and every iteration goes: step cap → validate → cost gate → spend and run.

Rules, in order per iteration:

  1. Step number over caps["max_steps"] → print stop: step-cap ($X.XX spent) and return.
  2. Look up the tool's spec in TOOLS. If it needs confirm and the call lacks a truthy confirmed → print step N: <tool> reject: needs confirm — the same verdict string your validator returns — and continue to the next call. A rejected call burns a step but spends nothing; the validator said no before anything ran.
  3. If spent + cost exceeds caps["max_cost_usd"] → print stop: cost-cap ($X.XX spent) and return.
  4. Otherwise spend and print step N: <tool> ok $X.XX.

Plan exhausted → stop: plan-complete ($X.XX spent).

Expected output (two runs):

step 1: read_log_tail ok $0.03
step 2: rerun_job reject: needs confirm
step 3: rerun_job ok $0.14
step 4: open_issue ok $0.18
stop: plan-complete ($0.18 spent)
step 1: rerun_job ok $0.11
step 2: rerun_job ok $0.22
stop: cost-cap ($0.22 spent)

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