05. Design Patterns
Reflection and Planning Patterns
Reflection looks back at an output or trajectory and critiques it so the agent can revise or learn. Planning looks ahead: decompose the goal into ordered steps, execute, and replan when observations drift.
What you will learn
- Define reflection and planning clearly
- Design a reflection loop with stop rules
- Write a plan schema agents can execute
- Know when to replan vs push through
- Answer interview questions with short, solid answers
Definition
Reflection is a pattern where the agent (or a critique hop) inspects a draft, action, or full episode against a rubric or goal, produces feedback, then revises β or stores a lesson for later runs.
Planning is a pattern where the agent first emits a structured plan (steps, dependencies, tools), then executes step-by-step. When tools return unexpected results, it replans instead of blindly continuing.
Introduction
This lesson (#4 in Design Patterns) follows Orchestrator-Worker and Evaluator-Optimizer. Reflection overlaps evaluator loops; planning overlaps orchestrator decomposition β here the focus is single-agent control shapes.
Next: Tool-Use Pattern β how plans and reflections attach to concrete tool calls.
Why these patterns matter
- Catch errors before they ship or compound
- Reduce aimless tool thrash with an explicit plan
- Make long tasks auditable (plan + critique logs)
- Support learning from failed episodes without full fine-tuning
Reflection pattern
Prefer structured critique (checklist JSON) over vague βbe betterβ prose so the revise hop has actionable constraints.
- Produce - draft text, code, or a tool trajectory summary
- Reflect - score vs rubric, list gaps, risks, missing evidence
- Revise - apply critique; do not ignore failed checks
- Stop - pass threshold, max rounds, or escalate
- Optional memory - store lesson for similar future tasks
Planning pattern
A plan is a contract: ordered steps with preconditions, tools, and success criteria β not free-form wishful thinking.
- Goal - normalize user intent into a measurable objective
- Plan - emit numbered steps + tools + expected outputs
- Validate - reject illegal/unsafe steps before execution
- Execute - run one step; record observation
- Replan - if drift/fail; else next step until done
Reflection vs Evaluator-Optimizer
- Same family of critique loops
- Evaluator-Optimizer stresses a separate evaluator role/model
- Reflection often means self-critique inside one agent loop
- Both need rubrics, budgets, and exit paths
Plan vs Orchestrator decomposition
- Planning - one agent owns the plan and usually executes it
- Orchestrator - assigns subtasks to other workers/agents
- Hybrid - plan first, then orchestrate high-cost steps
- Keep plans short enough to replan cheaply
Failure modes
- Shallow reflection - praise without failing checks
- Reflection thrash - endless polish; no ship criteria
- Overplanning - huge plans that expire before step 2
- No replan - sticking to a dead plan after tool failure
- Unsafe plans - missing validation of tools/side effects
Program / implementation notes
Store plan and critique as typed objects in agent state. Drive the loop from code (counters, validators), not only from free-form LLM prose.
- Schema: PlanStep { id, action, tool?, success_criteria }
- Schema: Critique { scores, gaps[], must_fix[] }
- Log plan_version and reflection_round for traces
- Next: Tool-Use Pattern
Advantages and limitations
- Advantage: higher quality via structured self-check
- Advantage: clearer long-horizon control via plans
- Advantage: better debugging (plan + critique artifacts)
- Limitation: extra latency and tokens per loop
- Limitation: bad rubrics create confident wrong fixes
- Limitation: brittle plans in highly dynamic environments
Key points
- Reflection critiques recent work and drives revision or learning.
- Planning emits executable steps before acting; replan on drift.
- Use structured critique and plan schemas, not vague prose.
- Hard-cap reflection rounds and plan size.
- Reflection β evaluator loop; planning β single-agent orchestration.
- Validate plans for safety before tool execution.
FAQs
Is reflection the same as chain-of-thought?
No. CoT reasons before/during an answer. Reflection critiques after an attempt and usually triggers a revise hop.
When should I force a plan first?
Multi-step tool jobs, high-cost actions, or tasks needing approval of the step list before side effects.
Should reflection always write to long-term memory?
Only when the lesson is reusable and sanitized. Ephemeral tasks can reflect without persisting.
Plan-and-execute vs ReAct?
ReAct interleaves short thoughts and acts. Plan-and-execute commits to a step list first, then runs it with optional replan β better for longer, auditable jobs.
Interview questions
- What is the reflection pattern in Agentic AI?
Answer After producing an output or episode, the agent critiques it against a rubric and revises (or stores a lesson) under a stop budget.
- What is the planning pattern?
Answer The agent creates a structured step plan for a goal, executes steps, and replans when observations invalidate the plan.
- How does reflection differ from Evaluator-Optimizer?
Answer Same critique-loop idea; Evaluator-Optimizer emphasizes a separate evaluator role, while reflection often self-critiques inside one agent.
- When do you replan?
Answer When a step fails, tools return unexpected data, preconditions break, or remaining steps are no longer valid.
- Name a risk of naive reflection.
Answer Rubber-stamp praise or infinite polish loops without pass criteria β fix with structured rubrics and max rounds.
- Give a combined example.
Answer Plan a research brief in 5 steps; after the draft step, reflect against a checklist, revise once, then continue the plan.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- Write a 4-item reflection rubric for a customer-email agent (pass = all true).
- Design a plan schema with 5 steps for βsummarize a PDF and email the boss.β
- List 3 observation events that must trigger a replan.
- Define max reflection rounds and what happens if still failing.
- Answer interview questions 1, 2, and 4 in two sentences each.