Article summary — original
Reflection Pattern Enables AI Agents to Self-Correct in Production
The reflection pattern is an agentic AI architecture where models generate an initial output, evaluate it against predefined criteria, and revise it before delivering a final response to improve accuracy and quality.
The reflection pattern follows a three-stage cycle: draft generation, evaluation against predefined criteria, and revision based on the critique.
Developers must establish stopping criteria, such as iteration caps, to avoid infinite refinement loops, increased latency, token waste, or degraded outputs.
Pattern variations include single-model self-reflection, multi-agent peer review to mitigate self-preference bias, and tool-augmented reflection that accesses external tools like databases or search engines.
The architecture is applied across domains like content editing, data reporting, customer support, and legal summaries, and differs from 'Reflexion', which learns across independent trials.
Three-Stage Workflow and Stopping Criteria
When executing a reflection pattern, an agent first drafts an initial output using available internal resources or documentation. Next, the generation is reviewed by either the original model or an alternate model based on developer-defined criteria and potential external tool inputs. The critique and draft are then fed back into the generative model to correct errors and purge irrelevant information. To prevent unbounded loops that consume tokens and degrade response quality, developers implement stopping conditions such as fixed iteration limits.
Architectural Variations: Single-Model, Multi-Agent, and Tool-Augmented
Single-model reflection is the simplest approach, but relying on internal knowledge alone exposes the system to self-preference bias and uncorrected hallucinations. Multi-agent designs mitigate this risk by assigning generation to one agent and evaluation to another, functioning as a peer-review mechanism. Tool-augmented reflection allows models to invoke external search engines or databases during evaluation, improving factual verification provided the underlying external data is accurate.
Use Cases and Implementation
The pattern is deployed in tasks requiring high accuracy, such as customer support, content creation, data analysis, and legal or financial summarization. Visual workflow automation tools like n8n allow teams to link generative and critique agent nodes through sub-workflows and conditional branching, enabling modular oversight and token consumption tracking.
Saved original article
The reflection pattern is one of four key agentic AI design patterns (alongside tool use, planning, and multi-agent collaboration) that enable AI systems to handle complex tasks. It allows an AI agent to generate an output, critique it, and amend it. This feedback loop makes it easier for the agent to catch errors and improve output quality.
Let’s say a team has built a business process automation solution, such as a customer support agent chat, that uses a reflection pattern. Once the agent is triggered, it follows a three-stage loop.
First, the agent’s attached AI model creates an initial response to the prompt, which in this case is a customer’s question. It accesses its resources, such as product documentation or company policies, to create a “first draft” response. It then holds the output in a temporary state for self-evaluation.
Next, the agent prompts either the same or a different model to critique the initial generation based on predefined criteria a developer has built into the pattern design. In this case, it may ask itself questions like “Did I consider all company policies?” and “Did I provide an answer that could be harmful or incorrect?” If the agent developer has opted to use a tool-augmented reflection pattern, the model may access external systems, such as a search engine, to complete its evaluation. The model catches and catalogs potential flaws that need to be fixed before responding to the customer.
The agent feeds its original draft and critique back into the generative model. It uses the additional context to revise its response. It corrects errors and removes irrelevant information to produce a higher-quality output.
It’s important for the agent’s developer to establish stopping criteria, such as a fixed number of iterations, to stop the agent from getting stuck in an indefinite refinement loop. Without stopping criteria, the agent might burn through model tokens or iterate past the optimal response and reduce its quality. Setting the right stopping point can reduce computational cost and latency while preserving output quality.
Once the agent has reached its stopping point, it returns the refined output to the customer, answering their question.
Agent developers should choose a reflection pattern variation that meets their needs for output quality and latency tolerance. This is particularly important as the agent parses multiple sources of feedback.
Single-model self-reflection is the simplest reflection pattern design strategy. In this setup, the model that the agent uses is both the generator and the evaluator. The model critiques its generative output based on predetermined criteria. The agent then feeds the model’s critique back into its generation prompt. This design pattern is straightforward and can improve an agent’s output. But the model is limited to its own internal knowledge and reasoning processes to evaluate its work. It may fail to recognize its errors and possibly reinforce hallucinations in its final output, which is often called a self-preference bias.
Agent developers may choose to design reflection patterns with multiple agents to reduce the quality risks associated with single-model reflection. In this approach, one agent controls the model’s generation and sends the first draft to a second agent to oversee the reflection. Think of it as a type of peer review. An agent or model with a distinct reasoning process can catch errors or hallucinations the original model may overlook.
This design pattern introduces external tools into the reflection stage. If the model determines that its internal knowledge and reasoning is insufficient to correct an error, it can invoke an external tool, such as a search engine or database. This process often improves the model’s ability to validate factual claims, but it depends on the accuracy of the external tool or data used.
AI architects and engineers can use workflow automation tools like n8n to run [multi-step reasoning agents](https://n8n.io/workflows/7066-create-multi-step-reasoning-ai-agents-with-gpt-4-and-reusable-thinking-tools/) or [agentic Retrieval-Augmented Generation (RAG](https://blog.n8n.io/agentic-rag/)). Engineers can work with SDKs. However, when using workflow automation tools with a visual interface, they can iterate more quickly and better track the progress of each stage. n8n is a source-available, AI-native automation platform, where engineers and nontechnical users alike can create AI agents and [agentic workflows](https://blog.n8n.io/ai-agentic-workflows/). Users can chain multiple AI agent nodes with a distinct system prompt for generation and another for critique. These nodes are connected [via sub-workflows](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflowtrigger) to manage complex modular processes.
Choosing the right design pattern can have a significant impact on the performance and cost of your AI task automation. The reflection pattern can improve output quality, but it may not be the best choice for your project.
You might want to use a reflection pattern if your project meets the following criteria:
You might want to use a different design pattern if your project meets the following criteria:
If you’re interested in using the reflection pattern but are worried about cost, n8n can help. You can use the platform to track AI agent token consumption and costs with an API, easily swapping between models. If reflection ends up being too expensive for your use case, you can adjust your workflow.
If you need to improve the accuracy and quality of an AI agent’s output, the reflection pattern may be a good design pattern to try. You can use n8n’s sub-workflow architecture, AI agent nodes, and [conditional branching](https://docs.n8n.io/build/flow-logic/split-with-conditionals) to implement reflection loops visually. [Get started](https://app.n8n.cloud/register) with a free trial today.
In addition to software development, the reflection pattern is used in areas such as content creation and editing, data analysis and reporting, as well as legal and financial summaries. In all these cases, the initial result may be incomplete or contain inaccuracies, so a single cycle of automatic review and correction often helps improve the results.
A reflection pattern is a specific design strategy for models to iterate their way to better answers. Reflexion is a general research approach that helps AI systems learn from mistakes across multiple independent trials.