← All AI Agents & Tool Use modules

Module 5 — Planning Before Acting

Reasoning across steps · hands-on · about 30 minutes.

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:

  1. 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.
  2. 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.

Plan-then-execute expressed in code
# 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.

AI anchor — from chain-of-thought reasoning to explicit planning The transition from a single-turn chatbot to an agent capable of multi-step task completion is largely attributable to explicit planning. Research assistants that produce an outline before retrieving sources, coding agents that enumerate the files to be modified before editing, and "deep research" modes that articulate a research plan before execution are all implementations of decompose-then-execute. A well-formed plan maintains task coherence across an extended sequence of actions and enables the agent to detect and recover from individual step failures rather than continuing without correction.

Check your understanding

Answer a short set of questions on planning.

This activity needs JavaScript.

Why this matters next Each subtask in the plan corresponded to a tool invocation — but how does the agent determine which tool is appropriate for each subtask? Module 6 introduces the routing mechanism: the decision that directs each request to the appropriate tool — calculator, data lookup, calendar, or search.
Summary: for a multi-component goal, a reliable agent first generates an explicit plan — decomposing the goal into a numbered sequence of single-tool subtasks — and then executes the plan in order, marking each subtask complete. This ensures coherence across the task, complete coverage of the original request, and recoverability when an individual step fails.

Next: Routing to the Right Tool →