Inferensys

Glossary

Reflexion

An agentic 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 without updating model weights.
AI evaluator reviewing output quality on laptop, comparison metrics visible, casual evaluation session.
VERBAL REINFORCEMENT LEARNING

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.

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.

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.

VERBAL REINFORCEMENT IN LLM AGENTS

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.

01

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.
91%
Pass@1 on HumanEval (Reflexion + GPT-4)
02

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.
3–5
Optimal Episodic Window Size
03

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.
No Human Labels
Feedback Source
04

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.
130%
Improvement over ReAct on AlfWorld
05

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.
91%
HumanEval Pass@1 (GPT-4 + Reflexion)
06

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.
Intra-episode
CoT Scope
Inter-episode
Reflexion Scope
COMPARATIVE ANALYSIS

Reflexion vs. Related Techniques

A feature-level comparison of Reflexion against other agentic reasoning and self-improvement paradigms.

FeatureReflexionReActChain-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)

REFLEXION PATTERN

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.

Prasad Kumkar

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.