The Reflection Pattern in AI Agents
Table of contents
- Key takeaways
- What is reflection in an AI agent?
- How do self-critique and output revision work?
- What do Reflexion and Self-Refine propose?
- When does reflection improve results and when not?
- What does it cost in tokens and latency?
- Frequently asked questions
- How is reflection different from the ReAct pattern?
- Do I need two different models to reflect?
- Does reflection eliminate hallucinations?
- Conclusion
- Sources
The reflection pattern makes an agent critique its own output and rewrite it before accepting it. One model generates, a second step evaluates and flags mistakes, and a third revises, in a loop of one or two rounds. It improves quality on tasks with clear criteria, but each cycle adds model calls, tokens and latency.
The reflection pattern is the technique that makes an agent review its own work before accepting it. Instead of answering in one shot, the agent produces a first draft, critiques it as a reviewer would, and rewrites it in light of that critique, sometimes over several rounds. In this guide you will see what reflection is, how it is implemented with a generate-and-critique loop, what the two papers that popularised it propose (Reflexion and Self-Refine), when it genuinely improves results, and what it costs in tokens and latency. The same explanation is available in Spanish.
Key takeaways
- Reflection is a design pattern in which the model itself evaluates its output and corrects it, without changing its weights or retraining.
- Reflexion (arXiv 2303.11366[1], March 2023) introduced verbal reinforcement: the agent writes a reflection on its error and stores it in memory for the next attempt; it reached 91% pass@1 on HumanEval, versus GPT-4’s 80%.
- Self-Refine (arXiv 2303.17651[2], 2023) uses a single model as generator, critic and refiner, and achieved a ~20% average absolute improvement across seven tasks.
- Anthropic calls this flow the evaluator-optimizer and warns that it only pays off when there are clear evaluation criteria and iteration adds measurable value.
- Reflecting has a cost: each round adds at least two more model calls, so it can triple or more the tokens and latency of a single response.
What is reflection in an AI agent?
Reflection is an agentic design pattern in which the model examines its own output, spots problems and produces a better version. It rests on an empirical observation: a language model is often better at judging an answer than at generating it on the first try. Asking it to "review this code and flag the mistakes" triggers a different kind of reasoning from "write this code", and that second pass surfaces errors the first generation missed.
It helps to place reflection inside the reason-act-observe agentic loop. Whereas that loop is about acting on the world (calling tools, querying data), reflection is an inner loop that acts on the agent’s own text: it does not fetch new information outside, it improves what the agent has already produced. That is why it fits at the end of a generation task (writing code, drafting a report, solving a reasoning problem) rather than in exploring an environment.
How do self-critique and output revision work?
In its simplest form, reflection is two roles taking turns over the same text. The generator produces a draft. The critic (the same model with a different instruction, or a second model) evaluates it against some criteria and returns a list of concrete defects. With that critique, the generator rewrites. The cycle repeats until the critic finds no faults or a maximum number of rounds is reached. This is the skeleton of the pattern:
def agent_with_reflection(task, max_rounds=2):
draft = generate(task) # first version
for _ in range(max_rounds):
critique = evaluate(task, draft) # the model critiques itself
if "APPROVED" in critique:
break # criterion met: stop
draft = revise(task, draft, critique)
return draft
The key is the critic’s prompt. A vague critique ("make this better") barely helps; an actionable critique demands explicit criteria: "check that the code handles the empty list, that names are descriptive, and that there is a test for each branch". The more objective the criterion, the more reliable the reflection, because the model can actually verify whether it is met. When an external signal exists (a passing or failing test, a JSON validator, a compiler), feed it to the critic: it stops opining and starts checking.
What do Reflexion and Self-Refine propose?
Two 2023 papers formalised the idea and named it. Self-Refine (arXiv 2303.17651[2]) presents the purest case: a single model generates, gives itself feedback and corrects over successive iterations, with no training data and no weight tuning. Across seven different tasks (from optimising code to rewriting text) it obtained a roughly 20% average absolute improvement with GPT-3.5, ChatGPT and GPT-4, and human evaluators preferred its outputs. Its conclusion is blunt: even a model as capable as GPT-4 can improve at inference time simply by critiquing itself.
Reflexion (arXiv 2303.11366[1]) goes a step further with what it calls verbal reinforcement. After failing an attempt, the agent writes a natural-language reflection on what went wrong and stores it in an episodic memory; on the next attempt it starts from that learned lesson. It is reinforcement learning, but without touching the weights: the "gradient" is text. With this technique, a coding agent reached 91% pass@1 on the HumanEval benchmark, above GPT-4’s 80% without reflection. That same idea of saving and reusing lessons links reflection with the agent’s long-term memory and planning.
Anthropic captures the pattern in its guide Building effective agents (December 2024) under the name evaluator-optimizer workflow, describing it as "particularly effective when we have clear evaluation criteria, and when iterative refinement provides measurable value".
When does reflection improve results and when not?
Reflection is neither free nor universal. It helps when the two conditions Anthropic stresses hold: a clear evaluation criterion exists and iterating adds measurable value. It fits squarely in code generation (tests pass or fail), writing against a rubric, reasoning problems with verifiable steps, and translation where a critic catches lost nuance.
It pays off far less, or even backfires, in three situations. First: when there is no objective criterion, the critic invents problems or approves anything. Second: when the model cannot recognise its own error (if it does not know the subject, critiquing itself adds no knowledge it lacks). Third: over-reflection, going round in circles until a good answer is spoilt or the loop stalls. That is why the pattern caps the number of rounds: in practice, one or two capture almost all the gain, and extra rounds yield diminishing returns. If you have an external signal (a test, a validator), use it as the stopping criterion rather than the model’s own opinion, and measure the result with a tool like DeepEval before assuming reflection improves anything.
What does it cost in tokens and latency?
This is the big counterweight. A direct answer is one model call; an answer with one round of reflection is three (generate, critique, revise), and with two rounds, five. On top of that, each critique and revision call resends the draft and the context, so token usage grows faster than the number of calls. Overall, it is easy to triple or more the cost and latency compared with answering on the first try.
The decision is therefore economic as well as technical. It is worth it when the value of getting it right is high (code going to production, a report being published) and there is time to spare. It is not worth it in interactive answers where the user is waiting and a mistake is fixed by hand. Two adjustments cut the bill: limit the rounds to one or two, and use a smaller, cheaper model for the critique step when the evaluation is simple, reserving the large model for generating and revising.
Frequently asked questions
How is reflection different from the ReAct pattern?
In the goal of the loop. ReAct alternates reasoning and action to interact with the world: it calls tools, observes the result and decides the next step. Reflection is an inner loop that improves the agent’s own output without fetching new information outside. They are complementary: a ReAct agent can add a reflection step at the end to review its answer before delivering it.
Do I need two different models to reflect?
No. In the most common version, the same model acts as generator and critic, only the instruction changes. Using a second model (or the same one with a different configuration) can help when you want a more independent look or want to make the critique cheaper with a smaller model, but it is not essential to get started.
Does reflection eliminate hallucinations?
It does not eliminate them; it reduces them when there is a way to check the output. If the critic has an objective signal (a test, a validator, a source to cross-check) it can detect and correct factual errors. If it relies only on the model’s own opinion about a subject it does not master, it can even reinforce a mistake. Reliable reflection needs a verifiable criterion.
Conclusion
The reflection pattern turns a model that answers on the first try into an agent that reviews its work: it generates, critiques against a criterion and rewrites, in one or two rounds. Reflexion and Self-Refine showed that the technique improves results measurably (up to 91% on HumanEval, ~20% on average in Self-Refine) without retraining the model, and Anthropic recommends it when evaluation criteria are clear. The price is multiplying calls and latency, so save it for tasks where getting it right matters and you can measure the improvement. The next step is to wire an external signal (a test or a validator) as the stopping criterion and confirm, with a real evaluation, that reflection delivers what it promises.
Sources: [1] Reflexion, language agents with verbal reinforcement (arXiv)[1], [2] Self-Refine, iterative refinement with self-feedback (arXiv)[2], [3] Anthropic, building effective agents[3], [4] LangChain, reflection agents[4].