A run-level token budget stops a runaway run, but it does not stop one greedy step from eating the whole budget before the useful steps run. A per-step budget fixes that: each step gets its own share, and a step that hits its share stops and reports, leaving the rest of the budget for the steps after it. The OpenAI Agents SDK reports usage per run, which is the raw material for enforcing the split: read the usage after each step and compare it with that step’s share. Set the shares from what each step actually needs, not by dividing the total evenly, because a research step and a formatting step do not cost the same.
What you need
- A run with named steps and a total token budget
- The token usage of each step from an earlier run, or a rough guess to start from
- A named outcome for a step that hits its budget: stop, summarize, or hand over
Step 1: Give each step its own share of the budget
Split the total budget across the steps by what each one needs: the research step gets the largest share, the formatting step the smallest. Write the shares down with the run plan.
Step 2: Check the usage after each step
After each step, read the run’s token usage and compare the step’s spend with its share. A check that only happens at the end of the run is a check that arrives too late.
Step 3: Stop the overspending step and report it
When a step hits its share, stop that step with a clear message naming the step and its spend, and let the later steps run on what is left. Do not silently borrow from the next step’s share.
Worked example: synthetic per-step budget check
The table below is a synthetic example. It shows the expected result of per-step budgets; no agent was run.
| Step | Budget | Spent |
|---|---|---|
| Research | 4,000 | 3,800 |
| Draft | 2,000 | 1,900 |
| Format | 1,000 | 950 |
| No step exceeds its share | Yes | Pass |
Expected result (UNTESTED). every step stays inside its own share, and the run finishes inside the total budget. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Shares set from guesses will be wrong; revise them from real usage after a few runs.
- A step that genuinely needs more than its share will stop early, so watch for cut-off work.
- Usage reporting lags the actual spend, so a fast step can overshoot before the check sees it.
- Per-step budgets bound cost, not quality: a cheap step can still be a wrong step.
