Area 03 · AI Agents · Concept 04 of 20

Planning

Break the goal into steps before acting, and update the plan as results come in.

01–10 · The basePhase 3 · Weeks 11–14≈ 1 hour

The idea

For bigger tasks, an agent that acts immediately tends to wander. Planning asks the model to write a numbered plan first, then execute it step by step, revising the plan when results change the picture.

Two common shapes: plan-and-execute (a planner call writes the plan, an executor works through it) and a living plan (the agent keeps a todo list in its context or in a file and ticks items off). Writing the plan into the context also helps the model remember the goal over long runs.

Plans should be concrete and checkable: "Find three pricing pages and record plan prices" beats "Research competitors".

Why it matters

Planning reduces wasted steps and makes long agent runs understandable to humans reviewing them.

Words to know

  • Plan-and-executeSeparate planning and execution phases or models.

Try it without code

Plan first, then act

  1. Ask a chat app to plan a 3-city trip in steps without answering yet.
  2. Then tell it to execute step 1 only.
  3. Change one fact and ask it to update the plan.

Use it in code

A plan tool the agent uses to write and update its todo list.

python
PLAN = []

def update_plan(steps: list[str], done: list[int] = []):
    """Replace the plan and mark finished step numbers."""
    PLAN[:] = [{"step": s, "done": i + 1 in done} for i, s in enumerate(steps)]
    return "\n".join(f"[{'x' if p['done'] else ' '}] {i+1}. {p['step']}" for i, p in enumerate(PLAN))

plan_tool = {"name": "update_plan",
             "description": "Write or update your step-by-step plan. Call it first, and again whenever you finish a step or learn something that changes the plan.",
             "input_schema": {"type": "object", "properties": {
                 "steps": {"type": "array", "items": {"type": "string"}},
                 "done": {"type": "array", "items": {"type": "integer"}}}, "required": ["steps"]}}
PRACTICE · TICK IT AFTER THIS

Give your agent the plan tool and compare the number of steps used on 5 tasks with and without it.

Common mistakes

  • Plans that are never updated after surprises.
  • Planning for trivial one-step tasks.

Go deeper