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".
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
- Ask a chat app to plan a 3-city trip in steps without answering yet.
- Then tell it to execute step 1 only.
- 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.
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"]}}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.