Reflection Pattern
An agent architecture pattern where the AI generates an initial output, then evaluates that output against criteria (accuracy, completeness, safety, style) and iterates to improve it before delivering the final result. Reflection mimics human self-review: write a draft, re-read it critically, fix issues, and submit the polished version. Agents using reflection produce higher-quality outputs on complex tasks—especially code generation, legal analysis, and content creation—at the cost of additional inference time and tokens.
Example
A coding agent generates a function, then reflects: 'Does this handle edge cases? Is it efficient? Does it follow the project's style guide?' It identifies a missing null check, adds it, and re-verifies before submitting the pull request.
Frequently asked questions
- How many reflection iterations are optimal?
- Typically 1–3 iterations. The first reflection catches the most significant issues. Subsequent iterations have diminishing returns and increase cost. Most production agents use 1 reflection pass for routine tasks and 2–3 for high-stakes outputs like legal documents or security-critical code.