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.

Article summary — zh

反思模式:AI Agent在生产环境中的自我修正机制 反思模式是AI Agent四大关键设计模式之一,通过“生成-评估-修正”的闭环机制帮助系统处理复杂任务,捕获错误并提升最终输出的准确度与质量。 反思模式包含草稿生成、预设标准审查和结合批评修正的三阶段循环,必须设置终止条件以避免无限循环与算力浪费。 反思模式主要有三种变体:单模型自我反思、多Agent对等审查,以及引入搜索引擎或数据库的工具增强反思。 该模式适用于内容创作、数据分析及法律和财务摘要等允许延迟且对准确性要求极高的场景。 开发者可以通过n8n等自动化平台的可视化工作流、子流程和条件分支构建反思循环并监控Token消耗成本。 三阶段反思循环与终止条件 在反思模式中,模型首先结合相关资源生成初稿并暂存;接着,相同或不同的模型根据预设标准审查初稿并指出潜在漏洞;最后,原始草稿与审查意见被送回模型进行修正,去除无关信息并纠错。开发者必须设定固定的迭代轮数等终止条件,以防止无限循环耗尽Token或过度修改导致质量下降,从而兼顾延迟和计算成本。 三种主要的模式变体 单模型自我反思由同一模型完成生成和评估,实现最简便但容易受内部知识限制产生自我偏好偏差;多Agent反思通过引入第二个Agent扮演“同行评审”角色,利用不同的推理过程降低幻觉风险;工具增强型反思则在反思阶段调取搜索引擎或数据库等外部工具核实事实,但其效果取决于外部工具的数据质量。 适用场景与平台落地 反思模式常用于内容编辑、数据分析报告、法律及财务摘要等初步生成容易残缺或出错的领域。工程师可以通过n8n等AI原生工作流平台,使用不同的Agent节点分别配置生成与批评的提示词,借助子工作流与条件分支进行模块化搭建,并通过API跟踪Token消耗以控制整体实施成本。

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.