By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Planning becomes much simpler once you accept that execution is code, not model calls in a loop. The model produces the plan; a plain executor walks it.
def execute(plan, tools, budget=8):
done, results = set(), {}
for step in topological_order(plan):
if len(done) >= budget:
return results, "STOPPED: step budget"
args = resolve_args(step, results) # pull values from earlier steps
status = validate(step["action"], args, tools)
if status != "OK":
return results, f"STOPPED: {status} at {step['id']}"
results[step["id"]] = tools[step["action"]](**args)
done.add(step["id"])
return results, "OK"The model decides what the steps are, and handles ambiguity when a step's result is unexpected. It should not decide the order, whether a dependency is satisfied, or whether the budget is exhausted — those are deterministic.
Key takeaways
Execution is a deterministic loop over a validated plan.
A results map gives you checkpoints, resumability and testability.
Budget enforcement belongs in the executor.
The model plans; code orders, validates and counts.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.