Plans and Budgets for Multi-Step Agents
Compare plan-first and reactive agents under step and cost budgets, and design limits that stop an agent cleanly and hand over what it found.
In this lesson you will
- Compare plan-first and reactive agents
- Set step, cost and per-tool limits
- Spot a run that spends its budget early
- Hand over cleanly when a limit is hit
About 25 minutes
The agent that kept searching
Ravi lets an assistant handle a tricky customer question using three tools: look up the order, search the shop notes and write a draft. The first time, it takes four tidy steps. The second time, the notes search returns something vague, so the assistant searches again, then again, and each search costs money. By the time it writes a draft, the budget is gone. In lesson 7 you met the step limit. Here you will look at plans and budgets together, because an agent that wanders is an agent that spends.
Plan first, or react?
- Plan first. The agent writes the list of steps it intends to take before taking any. A person or a check can read the plan, compare it with the budget and approve it. Predictable, but a plan can be wrong once reality differs.
- React. The agent picks each next step after seeing the last result. Flexible, but it can wander, repeat itself or go down a long path.
- Both. Many designs write a short plan, then allow limited changes to it, each checked against the budget.
Budgets that bite
A budget needs more than one limit, because agents can overspend in different ways. A step limit stops endless loops. A cost limit stops expensive steps adding up. A time limit stops long waits, and a limit on the number of calls to one tool catches the agent that keeps repeating itself. What matters is what happens when a limit is hit: the agent should stop cleanly, say which limit it hit and hand over to a person with what it has found so far.
Compare plans with reactive runs
The program below gives each tool a made-up cost and sets two limits: at most six steps and at most nine cost units. It runs three tasks twice. First it follows the plan exactly. Then it follows a reactive version in which extra calls happen after the first step, as they would if the agent were not satisfied with a result. Before each step the program checks whether the step would go over the budget, and if so it stops there.
cost = {"lookup": 1, "search_notes": 2, "draft": 3, "check": 1}
max_steps, max_cost = 6, 9
def run(seq):
spent = 0
for n, tool in enumerate(seq, 1):
if n > max_steps:
return n - 1, spent, "step limit"
if spent + cost[tool] > max_cost:
return n - 1, spent, "cost limit"
spent += cost[tool]
return len(seq), spent, "finished"
# the plan an agent could write first, and what really happens when it
# reacts to each result and sometimes searches again
tasks = {
"A": (["lookup", "draft", "check"], []),
"B": (["lookup", "search_notes", "draft", "check"], ["search_notes", "search_notes"]),
"C": (["search_notes", "draft", "check"], ["lookup"]),
}
stopped = 0
for name, (plan, extra) in tasks.items():
p = run(plan)
# reactive: extra calls happen right after the first search or lookup
reactive = plan[:1] + extra + plan[1:]
r = run(reactive)
stopped += r[2] != "finished"
print(f"{name} plan: {p[0]} steps, cost {p[1]}, {p[2]}")
print(f"{name} reactive: {r[0]} steps, cost {r[1]}, {r[2]}")
print("reactive runs that hit a limit:", stopped)
A plan: 3 steps, cost 5, finished
A reactive: 3 steps, cost 5, finished
B plan: 4 steps, cost 7, finished
B reactive: 4 steps, cost 7, cost limit
C plan: 3 steps, cost 6, finished
C reactive: 4 steps, cost 7, finished
reactive runs that hit a limit: 1
Task A needed no extra work, so the plan and the reactive run were the same. For task B, the plan used 4 steps at a cost of 7, and it finished. The reactive version of the same task wanted two extra searches. It managed 4 steps and 7 cost units, then hit the cost limit, because writing the draft would have pushed it over the budget. The expensive step, the draft, never ran, so the agent spent its money on searching and had nothing to show for it. Task C, with only one extra call, still finished within its limits. Altogether 1 reactive run hit a limit.
Look at what the failure teaches. The wasted spending came early, in the repeated searches, and the budget only bit at the end. A good design therefore also limits the repeats of any single tool, such as two searches per task, so that the agent must choose between searching again and moving on to the draft.
Handing over well
- State which limit was reached and how much was used.
- Pass the person what was found, including any partial draft, so work is not lost.
- Log the run, so you can see which tasks tend to run out and why.
- Never raise a limit silently to let a stuck run finish. Look at why it was stuck.
Setting only an overall step limit. An agent can burn its budget on one costly tool inside the limit, so cap each tool as well as the whole run.
The tools, costs and limits are made up, and the reactive extra calls are scripted, not decided by a real model. Real agents and their pricing differ by product, plan and region, so none are quoted, and agents can behave unpredictably.
Practice for this lesson
Check what you learned
Five quick questions. Pick an answer and you will see straight away whether it is right and why.
What is a plan-first agent?
- One that never stops
- One that writes its steps before taking any
- One with no tools
- One that only reads
The plan can be read and checked against the budget first.
Why use more than one limit?
- One limit is illegal
- Limits make steps faster
- Logs need them
- Agents can overspend in different ways
Steps, cost, time and repeats each need a cap.
What stopped the reactive run for task B?
- The step limit
- The cost limit, before the draft step
- A missing tool
- A person
Writing the draft would have gone over the budget.
What should an agent do when it hits a limit?
- Raise the limit quietly
- Delete its work
- Start again
- Stop cleanly, say which limit, and hand over what it found
A clean stop with partial results keeps work.
Why cap each tool as well as the whole run?
- An agent can burn its budget on one costly tool
- Tools are slow
- Caps hide errors
- It removes logging
Repeated searches spent the budget in task B.
Summary
- Plans can be checked before steps run.
- Use several limits: steps, cost, time and repeats per tool.
- A run that wanders spends its budget on the wrong steps.
- Stop cleanly and hand over what was found.
Questions
Is a plan always better than reacting?
No. Plans are predictable but can be wrong once reality differs. Many designs plan briefly and allow limited, checked changes.
How do I choose the limits?
Start with saved tasks, look at what normal runs use and set limits a little above that. Review them as you learn.
Do these costs match real tools?
No. They are made-up units. Real costs depend on the tool, plan and region.
