Agents and Tool Use · The Loop · lesson 3 of 7
Planning and decomposition
about 18 minutes · free · runs in your browser
Steps you can check beat steps you can only watch
A model handed "migrate the database and email everyone" will attempt it in one leap and you will have no idea which part failed. Decomposition — asking for a list of steps first, then executing them one at a time — buys three things:
- Inspectability. You can read the plan before anything happens.
- Recoverability. Step 4 failing does not mean re-running steps 1 to 3.
- A stopping condition. A plan has a length; a vibe does not.
The plan is data, so treat it as data: parse it, validate it, and refuse a step that names a tool you never provided — before executing anything, not partway through.
Your turn: write validate_plan(steps, allowed_tools) returning (ok, problem).
A plan is bad if it is empty, longer than eight steps, or names an unknown tool. Check the
whole plan up front — discovering step 6 is invalid after running five is the failure this
prevents.
You start from this, and edit it in the browser:
MAX_STEPS = 8
def validate_plan(steps, allowed_tools):
"""Return (ok, problem). problem is None when the plan is fine."""
return (True, None)