Skip to content

All lessons

Area 03 // AI AgentsLesson 50 / 14013 min read

Planning and reflection

Planning means the agent writes down the steps before acting and keeps the plan updated, and reflection means it checks its own work (or has it checked) and revises, both of which make long, multi-step tasks far more reliable.

Think of it like this

Analogy

A good builder doesn't start laying bricks immediately. They plan: foundations, walls, roof, wiring, in order, with a checklist. Halfway through, they find a pipe in the way and update the plan. And at the end of each stage, an inspector checks the work; anything that fails gets redone. That inspection is reflection.

The problem it solves

Agents that act step by step without a plan tend to drift on long tasks: they forget part of the request, repeat work, or declare victory early. And a single attempt at a complex output (a report, code, an analysis) often has mistakes the model could have caught if it had looked again with fresh eyes.

Planning and reflection are the two cheapest, most effective upgrades for agents doing real multi-step work.

How it works: planning

  1. Ask for a plan first: "Before acting, write a numbered plan of the steps you'll take." Keep it short and concrete.
  2. Store the plan where the agent will see it every turn: in the conversation, or as a to-do list tool / file the agent updates (many coding agents keep a visible checklist).
  3. Execute step by step, marking items done.
  4. Re-plan when results change the picture (a file doesn't exist, a step is unnecessary, a new sub-task appears).
  5. Plan-and-execute variant: a strong model writes the plan; cheaper models or plain code execute each step; the planner reviews at the end. Cheaper and more controllable.
  6. Show the plan to users for long tasks; it builds trust and lets them correct course early.

How it works: reflection

  1. Draft: the agent produces an output (code, an answer, a plan).
  2. Critique against explicit criteria. Best critics, from strongest to weakest:
    • Objective checks: run the tests, validate the schema, check the numbers add up.
    • A separate judge: another model call with a rubric (LLM as a judge).
    • Self-critique: the same model reviewing its own work (useful, but tends to approve itself).
  3. Revise using the specific feedback.
  4. Stop when the check passes or after a small number of rounds (two or three usually capture most of the gain).
  5. This is the evaluator-optimizer pattern from workflows, and the core of loop engineering's maker-checker loops.
Plan, act, check, revise.

See it in code

Needs
Nothing: plain Python 3. The drafts are scripted; the critic is real code.

A plan tracked as data, then a reflection loop where a code-based critic rejects a vague draft and accepts the revision.

plan_and_reflect.py
# PLANNING: write the plan as data first, then execute step by step and track status.
plan = [
    {"step": "Find last month's sales file", "done": False},
    {"step": "Compute total per region", "done": False},
    {"step": "Write a 3-line summary", "done": False},
]
for item in plan:
    item["done"] = True                          # a real agent would call tools here
print("plan:", [f"{'x' if i['done'] else ' '} {i['step']}" for i in plan])
 
# REFLECTION: draft -> check -> revise, until the check passes or the budget runs out.
def draft_v(n: int) -> str:                      # stand-in for the model's drafts
    return ["Sales grew a lot.",
            "Sales grew 12% to 4.2m GBP, led by the North region.",
           ][min(n, 1)]
 
def critique(text: str) -> list[str]:
    """A checker. Could be code (like here), tests, or a second LLM call with a rubric."""
    problems = []
    if not any(ch.isdigit() for ch in text):
        problems.append("no numbers")
    if "region" not in text.lower():
        problems.append("no region named")
    return problems
 
for attempt in range(3):
    text = draft_v(attempt)
    problems = critique(text)
    print(f"attempt {attempt + 1}: {text!r} -> {problems or 'OK'}")
    if not problems:
        break
Output
plan: ["x Find last month's sales file", 'x Compute total per region', 'x Write a 3-line summary']
attempt 1: 'Sales grew a lot.' -> ['no numbers', 'no region named']
attempt 2: 'Sales grew 12% to 4.2m GBP, led by the North region.' -> OK

In a real agent the critique's list of problems is sent back to the model ("Your summary has no numbers and names no region. Revise."), which is far more effective than "try again".

A real example

Example

A data-analysis agent that stopped skipping steps

An analytics agent answered questions like "why did churn rise in March?". Without planning, it often jumped to the first plausible cause and stopped. The team added: (1) a required plan ("list hypotheses, the data needed for each, then check each"), shown to the analyst; (2) a reflection step where a second model call checked the conclusion against a rubric ("Is every claim backed by a query result? Were alternative causes ruled out?").

Analysts rated conclusions "correct and complete" 71% of the time before and 88% after, at about 1.6× the cost, which they judged worth it for this task.

The easy way

Start here

Add two sentences to your agent's system prompt: "Before acting, write a short numbered plan and keep it updated as you go." and "Before finishing, check your result against the request and fix anything missing." Then, where possible, replace self-checks with real checks (tests, validators).

When you grow: the production setup

Production agents keep plans in structured state (a to-do tool or a file in the workspace), surface them in the UI, let users edit them, use objective verifiers wherever they exist, separate maker and checker models, cap reflection rounds, and evaluate whether each added step improves outcomes enough to pay for itself.

Trade-offs

What you gain

  • Plans keep long tasks complete and on track, and are visible to users.
  • Reflection catches many errors before the user sees them.
  • Objective critics make agents dramatically more reliable on code and data tasks.

What it costs you

  • Extra tokens and time per task.
  • Self-critique often approves flawed work.
  • Rigid plans can stop an agent from adapting.

When not to use it

  • Short, single-step tasks: planning and reflection just add cost.
  • No meaningful criteria exist to check against.

Common mistakes

  • Planning once and never updating the plan.
  • "Are you sure?" as the only reflection: models usually say yes.
  • Unlimited reflection rounds.
  • Vague critiques ("make it better") instead of specific feedback.
  • Hiding the plan from users on long tasks.

Interview questions

Try answering out loud first, then open the model answer.

How do planning and reflection improve agents?

Model answer

Planning decomposes a goal into explicit steps the agent tracks and revises, reducing drift, omissions and repeated work on long tasks, and giving users visibility. Reflection adds a critique-and-revise cycle against explicit criteria, catching errors before output; it's most effective with external verifiers (tests, schemas, rules) or an independent judge, and capped at a few rounds.

What's the plan-and-execute pattern and why use it?

Model answer

A capable planner model produces a structured plan; an executor (smaller models, tools or code) carries out each step; the planner re-plans when results deviate and synthesises at the end. It reduces cost (expensive model called rarely), improves controllability (the plan is inspectable data), and makes steps parallelisable, at the cost of less flexibility than a single agent re-deciding every turn.

Why is self-reflection weaker than external verification?

Model answer

A model critiquing its own output shares the same blind spots and tends to rate its work favourably, so it misses the errors it made. External checks (running code, validating against data, a different model with a strict rubric, human review) introduce independent signal. Use self-reflection where nothing better exists, but prefer verifiable checks.

Quiz

Pick an answer to see whether it’s right and why.

  1. 01Why ask an agent to plan before acting?
  2. 02What should happen to the plan when a step reveals new information?
  3. 03What is reflection in agents?
  4. 04Which critic is most reliable?
  5. 05Why cap the number of reflection rounds?

0 of 5 answered

Key terms

Planning (agents)
The agent writing down the steps of a task before acting, and updating that plan as it learns.
Reflection (agents)
Checking a draft against criteria (with tests, rules or a judge) and revising it before finishing.
To-do list (agent)
A plan stored as a checklist the agent updates as it works, often visible to the user.
Agent
A system where a model decides, in a loop, which tools to call and what to do next until a task is done.

Before and after

Progress is saved in this browser only.