Agent reflection self correction is a technique where an AI agent critiques its own work and tries again. Instead of thinking about it as human-like introspection, it's more useful to see it as a simple control loop: generate, get feedback, critique, and revise.

This process can improve an agent's output, but it is not a universally effective solution. Its success depends heavily on the quality of the feedback. Without a reliable, external signal to ground it, an agent can reinforce its own mistakes.

Key takeaways

  • Reflection is a control loop. An agent generates a response, gets feedback on that response, critiques its attempt, and then uses that critique to revise its output.
  • Feedback is critical. Self-correction is most reliable when grounded in external signals like test results or tool output, not just the model's own opinion (When Hindsight is Not 20/20...).
  • Results are mixed. Evidence shows reflection can improve results on some tasks but harm them on others (When Hindsight is Not 20/20...). It is not a universal solution for accuracy.
  • It has a cost. Each reflection cycle adds latency and token usage, so these loops must be bounded. Gains often diminish after just a few iterations (Self-reference in large language models...).
  • Agents have a 'blind spot' for their own errors. Because the critic and generator share the same flawed knowledge, an agent can reinforce its own mistakes during reflection, a failure sometimes called metacognitive hallucination (Self-reference in large language models...).

How Does Agent Reflection Work? The Core Loop

Agent reflection and self-correction is a multi-step process where an agent refines its work based on feedback. Rather than a single action, it is a loop that repeats until a goal is met or a limit is reached.

Here is a step-by-step breakdown of the mechanism:

  1. Generate. The agent produces an initial answer, plan, or piece of code. This is its first attempt at solving the given task.
  2. Evaluate. The system obtains an evaluation signal. This is the most important step. A strong signal comes from an external source, like a unit test failure, an error message from a tool, or a comparison against a correct answer. A weaker signal is an internal self-critique, where the same model is simply asked to judge its own work.
  3. Critique. The agent interprets the evaluation signal. It then generates a natural-language explanation of what went wrong, why it failed, and what a better approach might be.
  4. Revise. The agent uses the critique from the previous step to generate a new, corrected attempt. The goal is to produce a new output that avoids the identified error.
  5. Retry & Stop. The loop repeats from Step 1 with the revised output. The process terminates when a success condition is met (e.g., all tests pass), a budget is exhausted (e.g., a maximum of three retries), or the output stops changing.
  6. Memorize (Optional). In some systems like Reflexion, the critique from a failed trial is stored in an episodic memory. The agent can then retrieve these "lessons" to guide its attempts on different, future tasks, which helps it avoid repeating past mistakes (Reflexion: Language Agents with Verbal Reinforcement Learning).

Crucially, the success of the entire loop is judged by its ability to improve final task outcomes, not just the quality of the critique or the reasoning trace along the way.

A Worked Example: Correcting a Coding Error

To make the process concrete, here is an illustrative example of an agent using a reflection loop to fix a bug in a Python function. The key is the external verifier—a unit test—which provides an objective signal of failure or success.

An agent is asked: "Write a Python function sum_of_squares that takes a list of numbers and returns the sum of their squares."

Attempt 1 (Failure)

The agent generates code with a logical bug. It multiplies by two instead of squaring.

Python
def sum_of_squares(numbers):
  """Calculates the sum of the squares of a list of numbers."""
  total = 0
  for num in numbers:
    total += num * 2  # This is the bug
  return total
  • Illustrative Token Cost: 150 tokens

Evaluation (External Signal)

The system runs a predefined unit test against the code. This is a form of LLM tool calling where the tool is a code interpreter.

assert sum_of_squares([2, 3]) == 13

The test fails because the function returns (2*2) + (3*2) = 10, not the expected (2**2) + (3**2) = 13. The system receives a clear, external failure signal.

Critique (Reflection)

The agent receives the test result and is prompted to reflect on the failure. It generates a critique.

"The test failed. Expected 13 but the function returned 10. The code is multiplying each number by 2 instead of raising it to the power of 2. The error is on the line total += num * 2. It should be corrected to total += num ** 2."

  • Illustrative Token Cost: 75 tokens

Attempt 2 (Success)

The agent uses the critique to generate corrected code.

Python
def sum_of_squares(numbers):
  """Calculates the sum of the squares of a list of numbers."""
  total = 0
  for num in numbers:
    total += num ** 2  # Bug fixed
  return total
  • Illustrative Token Cost: 155 tokens

Verification

The unit test assert sum_of_squares([2, 3]) == 13 is run again. This time, it passes. The loop terminates.

Cost Analysis

The successful answer required a total of 150 + 75 + 155 = 380 tokens, plus the computational cost of running the test twice. This is more than double the token cost of the first attempt, highlighting the trade-off between accuracy and resource usage.

Does Self-Critique Actually Improve Results?

The effectiveness of agent reflection and self-correction is mixed and highly dependent on the task and feedback mechanism. It is not a guaranteed fix for model errors. The most crucial factor is the reliability of the evaluation signal. Unaided self-critique, where a model judges itself, is often unreliable.

Evidence shows that reflection can be beneficial in certain contexts. One study found a statistically significant improvement (p < 0.001) in problem-solving when using self-reflection (Self-Reflection in LLM Agents...). The same research noted that the benefits were larger when the model's initial answer was more likely to be wrong. However, this doesn't mean it works everywhere. Other research found that reflection improved scores on the TruthfulQA benchmark but actually harmed performance on HotpotQA (When Hindsight is Not 20/20...).

The core issue is that a model often cannot see its own mistakes because the evaluator shares the same weaknesses as the generator. This can lead the agent to repeat its misconceptions (Large Language Models cannot self-correct reasoning). This is why reflection is most useful when grounded by a dependable external signal (When Hindsight is Not 20/20...). Furthermore, any gains from reflection tend to saturate quickly, usually after just one to three iterations (Self-reference in large language models...).

Reflexion vs. Self-Refine vs. External Verification

Different methods for agent reflection and self-correction have emerged, each with a different approach to generating feedback. The main difference lies in the source of the critique: the model itself, a memory of past events, or an objective external tool.

Approach Feedback Source Memory Mechanism Key Idea
Self-Refine The same model critiques its own output. Contextual working memory within an episode; no long-term episodic memory across trials. Generate, get self-feedback, and refine in a tight loop (Self-Refine: Iterative Refinement...).
Reflexion An external signal (e.g., environment reward, test result). Verbal critiques are stored in an episodic agent memory to be used across different trials (Reflexion: Language Agents with Verbal...). Learn from past mistakes on a task by reflecting on what went wrong.
External Verifier A deterministic tool, test suite, or different (often stronger) model. None typically required, as feedback is immediate and objective. Use an independent source of truth to validate each attempt.

A third approach, multi-agent reflection, extends these concepts by using multiple agents to generate critiques. For instance, one agent might propose a solution, while several other agents with different "personas" critique it, and a final "judge" agent synthesizes the feedback. This method seeks to introduce diversity into the critique process to overcome the blind spots of a single agent, though diversity alone does not guarantee a correct outcome (Large Language Models cannot self-correct reasoning).

What Are the Common Mistakes and Limits?

Implementing reflection loops can be powerful, but it's easy to make mistakes that increase cost without improving results. Believing that a model's critique of itself is always correct is the most common error. An agent can confidently "correct" a right answer into a wrong one.

Here are some common pitfalls to avoid:

  • Trusting the Critic: Never assume a self-generated critique is accurate. A model can hallucinate a flaw in a correct answer just as easily as it can miss a real one.
  • Allowing Infinite Loops: Always set a maximum number of retries or a token budget. Without a stopping condition, an agent can get stuck in a loop, wasting resources and increasing latency.
  • Ignoring External Signals: Relying only on a model's self-judgment is risky, as the agent often repeats its own misconceptions because the critic shares the same flaws as the generator (Large Language Models cannot self-correct reasoning).
  • Accepting Superficial Revisions: Watch for cases where the model rewrites its explanation to sound more confident without actually fixing the underlying logical error. The quality of the reasoning trace is not a substitute for final task accuracy.
  • Focusing on the Critique, Not the Outcome: Evaluating the quality of the reflection or explanation instead of the final task accuracy. A useful reflection loop is one that improves concrete outcomes, not one that just produces a plausible-sounding critique.
  • Overstating Learning: Confusing an in-context correction with true learning. Reflection does not update the model's weights; the model is not permanently "learning" from its mistakes (Reflexion: Language Agents with Verbal Reinforcement Learning).

When Is Reflection Not Worth the Cost?

Reflection is not always the right choice, as each cycle adds cost and latency. You should avoid it when speed is paramount, feedback is unreliable, or the task is simple. It is a tool for improving quality on complex tasks where correctness justifies the extra processing time.

Do not use a reflection loop in these situations:

  • When latency is critical. For real-time applications like chatbots, the delay from one or more reflection cycles is usually unacceptable. A fast, good-enough answer is often better than a slow, slightly-more-perfect one.
  • When you lack a reliable verifier. If you have no objective way to tell if the revised answer is better than the original, reflection is a gamble. Unaided self-critique can be counterproductive, leading the model to reinforce its own errors (Self-reference in large language models...).
  • For simple, low-stakes tasks. If the model is already highly accurate on a task, adding a reflection loop provides diminishing returns and adds unnecessary cost.
  • When the budget is tight. Every cycle of generating a critique and a revision consumes tokens and compute time. If you are operating under a strict budget, the cost of reflection may outweigh its benefits.

What to learn next

  • AI Agent Planning: Explore how agents break down complex goals into smaller, manageable steps before they even begin to act or reflect.
  • AI Agent Memory: Learn more about the different types of memory agents use, including the episodic memory central to patterns like Reflexion.
  • Multi-Agent Systems: Discover how multiple agents can collaborate, sometimes with one agent acting as a critic for another, to solve problems that a single agent cannot.

Sources and further reading