Reflexion is an agentic reasoning pattern that converts a language model's own textual critique of its past output into a persistent verbal reinforcement signal. Unlike traditional reinforcement learning that updates model weights, Reflexion stores sparse, linguistic feedback—such as 'the previous plan failed because it lacked error handling'—in an episodic memory buffer. This self-generated critique is injected into the prompt context during the next trial, enabling the model to iteratively refine its reasoning without any gradient-based optimization.
Glossary
Reflexion

What is Reflexion?
An agentic pattern where the model generates a self-evaluation of its previous output, storing a verbal reinforcement signal in an episodic memory buffer to guide and improve subsequent reasoning attempts.
The architecture operates through a cyclical loop of Actor, Evaluator, and Self-Reflection components. The Actor generates a trajectory; the Evaluator scores it against a task-specific heuristic; and the Self-Reflection model produces a natural language summary of the failure mode. This summary is appended to a sliding window of long-term memory, creating a growing corpus of experiential heuristics. By decoupling learning from parameter updates, Reflexion enables rapid adaptation on sequential decision-making tasks, code generation, and reasoning benchmarks where trial-and-error feedback is available.
Key Characteristics of Reflexion
Reflexion is an agentic pattern that converts linguistic feedback into a form of reinforcement learning, enabling language models to learn from their mistakes without weight updates. The following cards break down its core mechanisms.
The Actor-Evaluator Loop
Reflexion operates through a modular feedback loop that separates task execution from self-critique:
- Actor: A language model that generates actions and reasoning traces in an environment (e.g., code generation, tool use, or question answering).
- Evaluator: The same or a separate model instance that inspects the actor's output, comparing it against environmental feedback or internal consistency checks.
- The evaluator produces a verbal reinforcement signal—a structured critique that identifies specific errors, explains why they occurred, and suggests corrective strategies.
- This loop mirrors the actor-critic architecture in reinforcement learning but replaces scalar rewards with semantically rich natural language feedback.
Episodic Memory Buffer
Reflexion stores self-generated critiques in a persistent episodic memory that accumulates across trials:
- After each failed attempt, the verbal feedback is serialized and appended to a sliding window of past experiences.
- On subsequent trials, the actor retrieves this memory and conditions its generation on both the current task and the history of prior mistakes.
- This creates a form of in-context learning from failure—the model sees what went wrong before and adjusts its strategy without gradient updates.
- The memory buffer typically retains the last 3–5 experiences to stay within context window limits while providing sufficient corrective signal.
- This mechanism is distinct from short-term memory (current trajectory) and long-term memory (external vector stores); it is a dedicated trial-level learning cache.
Heuristic-Based Evaluation
The evaluator module relies on heuristic signals rather than human labels to generate feedback:
- Binary Success/Failure: For code generation, unit tests provide an unambiguous pass/fail signal. The evaluator uses the test output to pinpoint which function or line caused the failure.
- Internal Consistency: For reasoning tasks, the evaluator checks for logical contradictions, missing steps, or factual inconsistencies within the generated chain-of-thought.
- Environmental Feedback: In embodied or tool-use scenarios, error messages, API responses, or simulation states serve as grounding signals.
- The evaluator synthesizes these heuristics into a structured critique containing: (1) the identified error, (2) the root cause hypothesis, and (3) a suggested remediation.
- This approach avoids the credit assignment problem by using language to explicitly attribute failure to specific reasoning steps.
Decision-Making via Self-Reflection
Reflexion improves decision-making in sequential environments by adding a reflection token to the action space:
- In the AlfWorld embodied reasoning benchmark, the agent can choose to reflect instead of acting, triggering a self-evaluation of its current trajectory.
- This reflection is stored in memory and conditions future actions, enabling the agent to recover from dead-end states without external intervention.
- The mechanism is particularly effective for sparse reward environments where failure signals arrive only after long action sequences.
- By verbalizing what went wrong, the agent performs credit assignment in natural language, attributing failure to specific earlier decisions.
- This converts a reinforcement learning problem into a language-conditioned policy optimization problem, where the policy is guided by self-generated textual critiques.
Programming Language Generation
Reflexion achieves state-of-the-art results on code generation benchmarks by treating compiler errors and test failures as evaluation signals:
- The actor generates a code solution; the evaluator executes it against a test suite.
- On failure, the evaluator produces a reflection containing: the specific test case that failed, the error traceback, and a hypothesis about the bug's root cause.
- The actor then regenerates the solution conditioned on the original problem statement plus the accumulated reflections from prior failed attempts.
- This creates a self-improving loop where each iteration benefits from the explicit diagnosis of previous mistakes.
- On the HumanEval benchmark, Reflexion with GPT-4 achieves 91% Pass@1 accuracy, surpassing prior methods that required multiple samples or external retrieval.
Reflexion vs. Chain-of-Thought
While both techniques improve reasoning, Reflexion and Chain-of-Thought (CoT) operate at different levels of the agent architecture:
- Chain-of-Thought generates intermediate reasoning steps within a single forward pass, improving the model's ability to solve complex problems through decomposition.
- Reflexion operates across multiple trials, using the output of one trial to improve the next. It is a meta-cognitive wrapper around the base reasoning process.
- CoT addresses intra-episode reasoning; Reflexion addresses inter-episode learning.
- The two techniques are complementary: an agent can use CoT to generate detailed reasoning traces and Reflexion to critique and refine those traces across attempts.
- Reflexion can also be combined with Self-Consistency by sampling multiple reflected trajectories and marginalizing over their outputs.
Reflexion vs. Related Techniques
A feature-level comparison of Reflexion against other agentic reasoning and self-improvement paradigms.
| Feature | Reflexion | ReAct | Chain-of-Verification |
|---|---|---|---|
Core Mechanism | Verbal self-evaluation stored in episodic memory | Interleaved reasoning traces and tool-use actions | Independent verification question generation and fact-checking |
Memory Structure | Episodic buffer storing long-term reflections | Short-term context window only | No persistent memory; stateless verification |
Self-Improvement Loop | |||
External Tool Use | |||
Hallucination Mitigation | Indirect via iterative self-critique | Indirect via grounded tool outputs | Direct via explicit fact-checking step |
Primary Optimization Target | Task success rate over multiple trials | Single-trajectory accuracy | Factual consistency of final output |
Statefulness | Persistent across episodes | Stateless per episode | Stateless |
Typical Latency Overhead | High (multiple trial loops) | Medium (interleaved steps) | Medium (verification pass) |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Explore the mechanics of the Reflexion agentic pattern, a framework for enabling language models to learn from their own mistakes through verbal self-evaluation and episodic memory.
Reflexion is an agentic architectural pattern where a language model generates a self-evaluation of its previous output, storing a verbal reinforcement signal in an episodic memory buffer to guide and improve subsequent reasoning attempts. Unlike gradient-based fine-tuning, Reflexion operates entirely through natural language feedback loops. The process works in three distinct phases: first, an Actor model generates a trajectory (a sequence of actions and outputs) to solve a task. Second, an Evaluator scores the quality of that trajectory, often using heuristics, exact match, or a separate language model. Third, the Self-Reflection model analyzes the failed trajectory and the evaluator's score to produce a diagnostic verbal summary—such as 'I failed to filter by date range'—which is stored in memory. On the next trial, this reflection is retrieved and prepended to the context window, allowing the model to avoid repeating the same logical error without any weight updates.
Related Terms
Explore the core architectural patterns that enable self-correcting, multi-step reasoning in autonomous agents.
ReAct (Reasoning and Acting)
A prompting framework that interleaves discrete reasoning traces with tool-use actions, enabling a language model to dynamically plan, execute, and update its strategy based on external feedback. Unlike Reflexion, ReAct focuses on immediate action-feedback loops rather than long-term episodic memory.
Chain-of-Verification (CoVe)
A hallucination-reduction mechanism where the model generates an initial response, plans a set of verification questions, answers them independently, and revises the original response based on the verified facts. CoVe performs a similar self-check function to Reflexion but executes it as a single-pass correction rather than storing the critique for future trials.
Tree of Thoughts (ToT)
A reasoning framework that generalizes chain-of-thought prompting by exploring multiple reasoning paths simultaneously in a tree structure, allowing the model to look ahead and backtrack from dead ends. Reflexion can be layered on top of ToT to store evaluations of entire branches for future exploration.
Self-Consistency
A decoding strategy that samples multiple diverse reasoning paths for a single problem and selects the final answer by marginalizing over the generated rationales through majority voting. While Self-Consistency aggregates parallel attempts, Reflexion improves sequential attempts by learning from past failures.
Episodic Memory Buffer
The storage mechanism where Reflexion persists verbal reinforcement signals—textual summaries of what went wrong and why—across reasoning episodes. This buffer acts as a growing set of 'lessons learned' that the agent consults before generating new attempts, enabling cumulative improvement over time.
Faithful Reasoning
An approach to generating explanations where the model's logical chain is strictly causally determined by the provided context, ensuring the explanation accurately reflects the model's actual decision process rather than a post-hoc rationalization. Reflexion critiques must themselves be faithful to be useful.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us