Catalog My learning Blog
Build AI Agents with MCP: 30-Day Course · Phase 2 · Lesson 8 · 5 min read

AI Agent Planning, Reflection and Verification

On this page
  1. Learning Objective
  2. Concept Explanation
  3. Worked Example: A Task List Tool That Anchors the Agent
  4. Real-World Examples
  5. Review Questions & Answers

Learning Objective

Understand how agents plan multi-step work, when an explicit plan helps, and how reflection and verification let an agent catch its own mistakes. Implement a plan-then-execute agent that keeps a visible task list and verifies each step.

Concept Explanation

A basic ReAct loop decides one step at a time. That works for short tasks but drifts on long ones: the agent forgets the original goal, repeats work, or declares victory after finishing the first subtask. Planning addresses this by making the agent write down the whole approach before acting, then follow and update it. The plan becomes an anchor in the context that the model rereads on every step.

There is a spectrum of planning styles. At one end, plan-and-execute separates the two: a planner produces a numbered list, an executor works through it, and the planner revises only when a step fails. At the other end, the agent keeps a living task list, adding items as it discovers work and checking them off as it goes. Coding agents such as Claude Code use this second style with a todo list tool, which also shows the user what the agent intends to do. Living lists adapt better to surprises; strict plan-and-execute is easier to audit.

Modern reasoning models also plan internally. With extended or adaptive thinking enabled, the model reasons before answering and between tool calls, which covers much of what explicit planning prompts used to do for short tasks. Explicit plans still earn their place on long tasks, because thinking does not persist across many turns the way a written list in the context does, and because a plan the user can see is a plan the user can correct.

Reflection is the agent looking back at its own output and asking what is wrong with it. The Reflexion paper by Shinn and colleagues (2023) showed that agents which wrote verbal self-critiques after failures and kept them in memory improved on later attempts. In practice, reflection works best when it is grounded in evidence: rerun the tests, reread the requirements, check the numbers against the source, rather than simply asking "are you sure?". Ungrounded self-critique can make a model change a correct answer to a wrong one.

Verification is the most valuable form of reflection. Before an agent reports done, it should check its result against the original goal: did every requirement get addressed, does the code run, do the totals match. Building a verify step into the definition of done, both in the system prompt and in tools that make checking easy, measurably reduces confident wrong answers.

TechniqueWhat it addsWatch out for
Plan-and-executeFull plan before acting, revised on failureRigid when the task surprises you
Living task listPlan updated as work is discoveredLists growing without completion
Adaptive thinkingModel reasons internally between stepsNot persistent across long sessions
ReflectionSelf-critique after attemptsUngrounded critique flipping correct answers
VerificationExplicit check against the goal before doneNeeds tools that make checking cheap

Worked Example: A Task List Tool That Anchors the Agent

Giving the agent a tool to manage its own plan keeps the plan in the context and visible to the user. The final instruction makes verification part of done.

Code
import json

PLAN: list[dict] = []

def update_plan(items: list[dict]) -> str:
    """Replace the task list. Each item: {"task": str, "status": "pending"|"in_progress"|"done"}.
    Keep exactly one item in_progress. Add items when you discover new work."""
    global PLAN
    if sum(i["status"] == "in_progress" for i in items) > 1:
        raise ValueError("Only one task may be in_progress at a time.")
    PLAN = items
    return "Plan saved:\n" + "\n".join(f"[{i['status']}] {i['task']}" for i in PLAN)

UPDATE_PLAN_TOOL = {
    "name": "update_plan", "strict": True,
    "description": update_plan.__doc__,
    "input_schema": {"type": "object", "additionalProperties": False, "required": ["items"],
        "properties": {"items": {"type": "array", "items": {
            "type": "object", "additionalProperties": False, "required": ["task", "status"],
            "properties": {"task": {"type": "string"},
                           "status": {"type": "string", "enum": ["pending", "in_progress", "done"]}}}}}},
}

SYSTEM = """You complete multi-step engineering tasks.
1. Before acting, call update_plan with the steps you expect.
2. Work through the plan, marking items in_progress and done as you go.
3. Before your final answer, verify: rerun the tests or recheck the data, and confirm every
   requirement in the original request is met. If verification fails, add a task and fix it.
Your final answer lists what you changed and how you verified it."""

Combined with the loop from Day 3, this produces runs where the user sees a plan first, watches it progress, and gets a final answer that cites evidence. The single in-progress rule stops the agent from starting many things and finishing none.

The agent writes a task list before acting, works through it, adds tasks as it discovers work, and verifies against the original request with real evidence. A failed check adds a fix task; only a passing check leads to the report.
The agent writes a task list before acting, works through it, adds tasks as it discovers work, and verifies against the original request with real evidence. A failed check adds a fix task; only a passing check leads to the report.

Real-World Examples

  • Claude Code and other coding agents expose a todo list that the agent writes and updates during a task; it keeps long tasks on track and lets the user interrupt when the plan is wrong before any code is written.
  • The Reflexion paper (Shinn and colleagues, 2023) reported large gains on coding and decision benchmarks when agents stored verbal reflections on failed attempts and used them in the next try, an early demonstration that grounded self-feedback helps.
Key TakeawaysExplicit plans anchor AI agents on long tasks, keeping them on track and making their intent visible and correctable before they act. Choose between strict plan-and-execute and a living task list based on how much the task can surprise you. Reflection helps when it is grounded in evidence such as test results, and verification against the original goal should be part of every agent's definition of done.

Review Questions & Answers

They decide one action at a time with no persistent statement of the whole goal, so as the context grows they lose track of requirements, repeat work, or stop after the first subtask. A written plan in the context counteracts this.

Thinking happens per response and does not persist as a stable reference across many turns, while a written plan stays in the context. An explicit plan is also visible to the user, who can correct it before work begins.

Grounding it in evidence, such as rerunning tests or rechecking source data. Ungrounded prompts like "are you sure?" can lead a model to abandon a correct answer.

That every requirement in the original request has been addressed and that the result actually works, for example the code runs and tests pass, or the numbers reconcile with the source data.