Reflection: let the agent critique its own output
Reflection runs your agent twice — generate, then critique against explicit criteria and feed the fixes back — so a weak first draft becomes a stronger final answer.
What it is
Reflection is when the agent grades its own work before you ship it. You run two passes instead of one:
- Generate: the agent produces a draft answer, plan, or code.
- Critique: a second step reviews that draft against explicit criteria and writes concrete fixes.
- Revise: the generator takes the critique and tries again.
It is often the same model in both roles, just with a fresh prompt. People also call it self-correction or an evaluator-optimizer loop.
When to use it
Reach for reflection when a first draft is rarely good enough and quality matters more than latency:
- Code that must compile, pass tests, or match a spec.
- Long writing where structure and accuracy drift.
- Multi-step plans worth sanity-checking before execution (pairs well with planning).
- Anything you can score against clear criteria — lean on evals to define them.
Skip it for simple, low-stakes, or latency-sensitive calls. Two-plus model passes cost more and add delay — if a single shot is reliably fine, reflection is wasted spend (cost control).
How it works
Split the roles. Give the critic a fresh context so it judges the output, not its own reasoning.
- Generator returns a draft, e.g. a function
parse_dates(s). - Critic gets the draft plus a checklist —
handles empty input?,timezone-aware?,tested?— and returns a verdict plus specific fixes, not vague praise. - If the verdict is
pass, you ship. Ifrevise, the fixes feed back to the generator for another round. - A loop counter caps it: stop after
max_iters(say 3) or when the critic sayspass.
Ground the critic in something real — test results, a schema, a rubric — so the signal is objective.
Watch out for
- No exit condition. Without a
max_iterscap or a clearpasssignal, the loop runs forever or burns budget chasing diminishing returns. - Ungrounded critique. A critic with no rubric, tests, or tool output just rephrases the draft. Give it real criteria or feed it actual results — see tool design.
- Same-context bias. If the critic shares the generator's context, it rubber-stamps its own mistakes. Use a fresh prompt or a separate model.
- Confident regressions. Revisions can fix one thing and break another. Re-check the full criteria each pass, and log the rounds so you can debug (observability).
Related patterns
Evals: gate on recall, not vibes
Make the metric deterministic before you trust any number. Gate releases on recall over a fixed must-handle set; keep the LLM judge off the gate.
Planning: make a plan before acting
Make the agent write an explicit, ordered plan before it acts, execute the steps, and replan when reality breaks the plan.
Learning & adaptation: improve from feedback
Let the agent improve at runtime by storing scored outcomes and retrieving the wins as few-shot examples and the failures as warnings — no retraining required.