Let's talk

Agentic Design Patterns

The Reflection Pattern in AI Agents

The reflection pattern is an iterative design where one step produces a draft and another critiques it against specific criteria to drive revision.

By Divyaprakash JhaUpdated 5 min readTopic: Agentic AI

Photo for The Reflection Pattern in AI Agents

What is the Reflection Pattern?

The reflection pattern is an iterative design where one step produces a draft and another critiques it against specific criteria to drive revision. It uses a loop of generation and evaluation to ensure the final output meets high standards of accuracy and quality.

In the world of agentic AI, reflection is a pattern where an agent produces a draft, a second step critiques that draft against concrete criteria, and the first step revises it based on that feedback. This process is inspired by research concepts like Self-Refine and Reflexion.

For a business owner, think of this like hiring a junior writer and a senior editor. The junior writer (the generator) produces a first draft. The senior editor (the critic) reviews it against a specific checklist, such as "ensure all prices are in INR" or "verify all GST numbers are valid." The junior writer then rewrites the piece to address those specific points.

The effectiveness of this pattern depends entirely on the quality of the instructions given to the critic. The pattern works best when the evaluation criteria are concrete, such as "every claim must cite a source document." Conversely, it is less effective and more costly when the criteria are vague, such as "make this sound better," which can lead to endless, unproductive loops.

How the Reflection Loop Works

The reflection pattern is not a single action, but a cycle. It relies on a "verifier" to check the work of the "generator." This loop is a core component of many agentic architectures, allowing the system to move from an initial, imperfect output to a high-quality final result through self-correction.

The process follows a predictable, iterative loop:

  1. Draft: The agent generates an initial response or performs a task.
  2. Critique: A verifier (which could be a second model or a piece of code) evaluates the draft against specific rules or standards.
  3. Revise: The agent takes the critique and updates the draft to fix errors or improve quality.

This loop continues until the task is completed or a pre-set limit is reached. In a production environment, it is vital to implement a "budget" or a step limit. Without this, an agent might get stuck in an infinite loop, repeatedly trying to satisfy a critique that it is incapable of meeting, which drives up your API costs.

Reflection vs. Other Agentic Patterns

Understanding when to use reflection requires comparing it to other common patterns used in agentic AI. Not every task requires the overhead of a reflection loop.

Pattern Core Mechanism Best Use Case
ReAct Interleaves reasoning with tool calls (Reason + Act). Open-ended research or troubleshooting.
Plan-and-Execute Creates a full plan first, then follows it step-by-step. Predictable tasks like migrating 300 product listings.
Reflection Iterative loop of drafting, critiquing, and revising. High-precision tasks requiring extreme accuracy.

While Plan-and-Execute is excellent for structured, multi-step workflows where the path is relatively known, Reflection is ideal for tasks where the quality of the output is the primary concern. If you are building a system to draft legal contracts or complex technical reports, reflection provides the "second pair of eyes" necessary for high-stakes accuracy.

When to Use Reflection in Production

Reflection is powerful, but it is not a "silver bullet." For builders, the decision to implement reflection should be driven by a cost-benefit analysis of accuracy versus token usage.

Use reflection when:

  • Task quality depends on meeting strict, measurable standards (e.g., "The output must be valid JSON" or "The total must match the invoice sum").
  • The cost of a mistake is high, such as in financial reporting or medical summaries.
  • The task requires a level of nuance that a single pass of a model might miss.

Avoid reflection when:

  • The task is simple and predictable (e.g., "Summarize this email").
  • The cost of the extra model calls outweighs the marginal gain in quality.
  • The criteria for "success" are subjective and cannot be clearly defined.

In production-grade systems, developers often combine reflection with deterministic verifiers. For example, instead of asking a model "Is this math correct?", a developer will use a piece of Python code to check the sum.

Best Practices for Implementation

If you are ready to build a reflection loop, keep these three implementation strategies in mind to ensure your agent is both effective and economical.

1. Use a "Strong" Model for Critique

A common mistake is using the same small, cheap model for both the drafting and the critiquing. For high-quality results, use a high-reasoning, "strong" model for the critique/reasoning phase. This ensures the feedback is actually useful. You can then use a smaller, cheaper model to perform the actual routine steps of the task once the plan is set.

2. Define Non-Vague Instructions

The "verifier" or "critic" role needs instructions that are impossible to misunderstand. Instead of telling the critic to "check for errors," tell it to "identify any sentence that does not have a corresponding citation from the provided text." The more concrete the instruction, the more reliable the revision loop becomes.

3. Implement a "Kill Switch" and Budget

Every agentic loop should have a maximum number of iterations. In a production environment, you should also implement a token budget. If the agent is struggling to satisfy the critic, you want the system to stop and, if necessary, hand the task over to a human rather than burning through your entire API budget in an infinite loop.

Frequently Asked Questions

Does the reflection pattern work for any AI task?
No. It is most effective when you have concrete, measurable criteria for success. It can be wasteful and expensive if the criteria are too vague for the model to evaluate.
How does reflection differ from a simple workflow?
A workflow follows a predefined, linear code path. Reflection is an agentic loop where the model decides how many times it needs to revise based on the critique received.
What is the main risk of using reflection?
The primary risks are increased token costs and the potential for the agent to enter an infinite loop if it cannot satisfy the critique requirements.
Can I use a small model for the reflection step?
It is often better to use a strong model for the planning and critique stages, while using smaller, cheaper models for routine or repetitive steps.
What is the difference between reflection and a verifier?
A verifier is a check (often code-based or a second model) that confirms if a task was done correctly. Reflection uses that critique to actively revise the work.
Yellow robotic arm operating inside a glass enclosure with a monitor above.
Photo: Robot arm works on a small component in a lab setting by Shixart1985, CC BY 2.0

Questions people ask

Does the reflection pattern work for any AI task?

No. It is most effective when you have concrete, measurable criteria for success. It can be wasteful and expensive if the criteria are too vague for the model to evaluate.

How does reflection differ from a simple workflow?

A workflow follows a predefined, linear code path. Reflection is an agentic loop where the model decides how many times it needs to revise based on the critique received.

What is the main risk of using reflection?

The primary risks are increased token costs and the potential for the agent to enter an infinite loop if it cannot satisfy the critique requirements.

Can I use a small model for the reflection step?

It is often better to use a strong model for the planning and critique stages, while using smaller, cheaper models for routine or repetitive steps.

What is the difference between reflection and a verifier?

A verifier is a check (often code-based or a second model) that confirms if a task was done correctly. Reflection uses that critique to actively revise the work.