Enable agents to evaluate and improve their own outputs through self-critique and iteration
Self-Correction & Iterative Refinement
An agent's initial output is often suboptimal, suffering from inaccuracies, incompleteness, or a failure to meet complex requirements. Basic agentic workflows lack a built-in process for the agent to recognize and fix its own errors. This is solved by having the agent evaluate its own work or, more robustly, by introducing a separate logical agent to act as a critic, preventing the initial response from being the final one regardless of quality.
The Reflection pattern offers a solution by introducing a mechanism for self-correction and refinement. It establishes a feedback loop where a "producer" agent generates an output, and then a "critic" agent (or the producer itself) evaluates it against predefined criteria. This critique is then used to generate an improved version. This iterative process of generation, evaluation, and refinement progressively enhances the quality of the final result, leading to more accurate, coherent, and reliable outcomes.
Use the Reflection pattern when the quality, accuracy, and detail of the final output are more important than speed and cost. It is particularly effective for tasks like generating polished long-form content, writing and debugging code, and creating detailed plans. Employ a separate critic agent when tasks require high objectivity or specialized evaluation that a generalist producer agent might miss.
The Reflection pattern involves an agent evaluating its own work, output, or internal state and using that evaluation to improve its performance or refine its response. It's a form of self-correction or self-improvement, allowing the agent to iteratively refine its output or adjust its approach based on feedback, internal critique, or comparison against desired criteria.
Key Insight: Unlike a simple sequential chain where output is passed directly to the next step, reflection introduces a feedback loop. The agent doesn't just produce an output; it then examines that output, identifies potential issues or areas for improvement, and uses those insights to generate a better version.
A key and highly effective implementation of the Reflection pattern separates the process into two distinct logical roles: a Producer and a Critic. This is often called the "Generator-Critic" or "Producer-Reviewer" model.
The Producer's primary responsibility is to perform the initial execution of the task. It focuses entirely on generating the content, whether it's writing code, drafting a blog post, or creating a plan. It takes the initial prompt and produces the first version of the output.
The Critic's sole purpose is to evaluate the output generated by the Producer. It is given a different set of instructions, often a distinct persona (e.g., "You are a senior software engineer"). The Critic analyzes the Producer's work against specific criteria and provides structured feedback.
Why Separation Works: This separation of concerns is powerful because it prevents the "cognitive bias" of an agent reviewing its own work. The Critic agent approaches the output with a fresh perspective, dedicated entirely to finding errors and areas for improvement.
A goal provides the ultimate benchmark for the agent's self-evaluation, while monitoring tracks its progress. Reflection acts as the corrective engine, using monitored feedback to analyze deviations and adjust its strategy. This synergy transforms the agent from a passive executor into a purposeful system that adaptively works to achieve its objectives.
The effectiveness of the Reflection pattern is significantly enhanced when the LLM keeps a memory of the conversation. This conversational history provides crucial context for the evaluation phase, allowing the agent to assess its output not just in isolation, but against the backdrop of previous interactions, user feedback, and evolving goals. Without memory, each reflection is a self-contained event; with memory, reflection becomes a cumulative process where each cycle builds upon the last.
Every refinement loop requires a new LLM call, making it suboptimal for time-sensitive applications. The iterative process increases both computational costs and response time.
With each iteration, the conversational history expands, including the initial output, critique, and subsequent refinements. This can quickly consume the model's context window.
Multiple sequential API calls in rapid succession may trigger rate limits or throttling from the LLM provider, potentially disrupting the reflection loop.
Iterative loops with multiple agents make it harder to trace errors and understand where issues originated in the refinement process.
Generate → Evaluate → Refine → Repeat until satisfactory
Distinct roles prevent cognitive bias and improve objectivity
Prioritizes output quality at the cost of latency and resources
Enhanced by memory and goal-oriented monitoring