Module 5 — Planning Before Acting
To this point, the agent has selected each action incrementally. This is adequate for short tasks, but for a goal comprising multiple parts — "brief me on my trip: weather, population, and country" — proceeding step by step risks losing coherence, repeating work, or terminating prematurely. A more reliable approach adopts the standard practice in formal problem-solving: plan first, then execute. The full sequence of subtasks is written out in advance and then executed in order.
Goal decomposition followed by ordered execution
The planning paradigm comprises two phases:
- Decompose — break the big goal into a numbered list of small, concrete subtasks, each one a single tool call the agent knows how to do.
- Execute — work down the list in order, doing one subtask at a time and checking it off, until the plan is complete.
An explicit plan provides the agent with a structured representation of the task: it can track remaining work, ensure no component of the request is omitted, and, in more advanced implementations, detect when a step has failed and revise the plan accordingly. The "plan-then-execute" pattern distinguishes an agent that proceeds coherently through a structured task from one that proceeds opportunistically and may fail to complete it.
Observe planning followed by execution
Select a goal. The agent first generates a plan — a numbered list of subtasks. Click Execute next to execute one subtask at a time and observe each being marked complete as its tool returns a result, or Run plan to execute the full sequence.
This activity needs JavaScript. The lesson below still covers everything.
# phase 1: the model writes a plan — a list of subtasks plan = decompose(goal) # e.g. ["weather(Tokyo)", "population(Tokyo)", "lookup(Tokyo country)"] # phase 2: execute each subtask in order, collecting results results = [] for step in plan: results.append(run_tool(step)) # do one subtask, check it off answer = summarize(goal, results) # combine into the final reply
Some agent architectures re-plan after every step (greater flexibility at the cost of additional model calls); others generate a single plan and execute it (lower cost, more predictable behavior). Both approaches begin by converting an unstructured goal into an explicit list of executable subtasks.
When a step fails, re-plan
Plans don't always work on the first try. A step's observation can come back an error — and a good agent reads that error and revises the step instead of barreling on with bad information. Execute the plan below: the first step is phrased in a way the calculator can't parse, so it fails. Re-plan it and watch the run recover.
This activity needs JavaScript. The lesson below still covers everything.
Check your understanding
Answer a short set of questions on planning.
This activity needs JavaScript.