# Reflexion: Language Agents with Verbal Reinforcement Learning

Noah Shinn, Federico Cassano, Edward Berman, Ashwin Gopinath, Karthik Narasimhan, Shunyu Yao · arXiv · 2023-3-20

- **Problem** Gradient-based reinforcement learning needs heavy compute and time, so LLM agents have mostly learned from in-context examples.
- **Method** Reflexion keeps the model weights fixed, turns scalar or binary feedback into a verbal reflection, and stores that reflection in a bounded episodic memory for later trials.
- **Results** Reached 91.0 pass@1 on HumanEval Python, against 80.1 for GPT-4.

![Figure 3: (a) AlfWorld performance across 134 tasks showing cumulative proportions of solved tasks using self-evaluation techniques of (Heuristic) and (GPT) fo…](https://refivu.com/papers/a572f458-b121-4d38-bfc9-7a77309a3aba/figures/figure-ede82190f175e4ed6b81632df0802473.png?thumb=512)

**Figure 3** : (a) AlfWorld performance across 134 tasks showing cumulative proportions of solved tasks using self-evaluation techniques of (Heuristic) and (GPT) for binary classification. (b) Classification of AlfWorld trajectories by reason of failure.

[Original paper](https://arxiv.org/abs/2303.11366v4) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Noah Shinn, Federico Cassano, Edward Berman, Ashwin Gopinath, Karthik Narasimhan, Shunyu Yao · Reflexion: Language Agents with Verbal Reinforcement Learning · Original paper figure · Extracted the figure area from page 6 of the original PDF.

## Why weight updates are a poor fit for agents

LLM-based agents generate text and actions that are passed to API calls or executed in an environment. Such agents have so far mostly been taught with in-context examples, because conventional reinforcement learning with gradient descent needs a lot of compute and time for models with very large parameter counts. Reflexion takes a different route.

It leaves the weights alone and turns the feedback from each attempt into text that the agent reads on later attempts.

## Where Reflexion sits among earlier work

Self-Refine improves generations through self-evaluation, but it is limited to single-generation reasoning tasks. Beam search over actions adds self-evaluation to decision-making, yet the authors' comparison table gives it no memory component, which Reflexion adds.

In programming, AlphaCode, Self-Debugging and CodeRL rely on ground truth test cases, which the authors say invalidates pass@1 eligibility. CodeT avoids hidden tests but has no self-learning step that improves code writing.

## How feedback becomes reflective memory

Reflexion uses three LLM roles. The Actor M\_a generates text and actions, the Evaluator M\_e scores what the Actor produces, and the Self-Reflection model M\_sr writes verbal cues that help the Actor improve. The Actor's policy is written \\(\\pi\_\\theta(a\_i\|s\_i)\\) with \\(\\theta = \\{M\_a, mem\\}\\), so the memory is part of what the agent conditions on alongside the model itself.

The trajectory of actions and observations in the current trial serves as short-term memory, while the self-reflection outputs are kept as long-term memory.

The Evaluator turns a trajectory into a reward. For reasoning it uses exact match grading, for decision-making pre-defined heuristics, and an LLM instance can also serve as the Evaluator. On the first trial the reward is computed as \\(r\_t = M\_e(\\tau\_0)\\), a scalar that should rise as task performance improves.

After a trial, the Self-Reflection model reads the trajectory with the sparse success signal and its stored memory, then writes a verbal summary that is appended to the memory. That summary can say which earlier action probably caused later failures and which action should replace it, so the next trial can change its choice without any weight update.

Memory is bounded by \\(\\Omega\\), usually set between 1 and 3 stored experiences, so that prompts stay within context limits.

Algorithm 1 repeats this cycle until the Evaluator accepts the trajectory or a maximum number of trials is reached.

## AlfWorld: reflection across repeated trials

The agent runs on 134 AlfWorld environments spanning six task types, such as finding hidden objects, moving objects and manipulating objects with other objects. ReAct generates the actions, and the environment signals only task completion, so self-evaluation comes from either an LLM classifier or a hand-written heuristic. In baseline runs a suggested self-reflection is skipped and the environment is reset.

In Reflexion runs the agent reflects first, then starts a new trial with its memory truncated to the last 3 self-reflections.

ReAct with Reflexion completed 130 of 134 tasks and kept gaining over 12 consecutive trials, while ReAct alone stopped improving between trials 6 and 7. The headline result is an absolute 22% improvement over strong baselines on AlfWorld within 12 iterative learning steps. Figure 3 plots the cumulative proportion of solved environments over trials for ReAct alone and for ReAct with Reflexion under the heuristic and GPT classifiers.

A typical baseline failure is an agent that believes it holds an item it does not have, then runs a long chain of actions without backtracking to the mistake. The authors say reflection removes almost all of these cases by distilling failed trajectories into experiences that act as self-hints later. ReAct alone converged at a hallucination rate of 22%, with no sign of long-term recovery.

## HotPotQA: reasoning with a binary signal

HotPotQA is a Wikipedia-based dataset of 113k question-and-answer pairs that require reasoning over several supporting documents. One setup gives the model the ground truth context and uses Chain-of-Thought with 6-shot prompting, while the other uses ReAct with 2-shot prompting and a Wikipedia API to retrieve context. Self-reflection uses 2-shot prompting, and between trials exact match grading gives the agent a binary success signal.

The baselines were ReAct-only, CoT-only and CoT (GT)-only. None of them improved on any task that failed in the first trial, at a temperature of 0.7. Reflexion runs retried a failed question until it produced 3 consecutive failed attempts. The CoT (GT) agent still fails 39% of questions, and Reflexion raised its accuracy by 14% without access to the ground truth answer.

Figure 4 shows the success curves for these settings across 100 HotPotQA questions.

To isolate the reflective step, the authors add episodic memory of the most recent trajectory to CoT (GT), then add the standard self-reflection pass on top. In this comparison self-reflection gives an 8% absolute boost beyond the benefit of episodic memory. The authors read this as evidence that refinement without self-reflection is less effective than self-reflection-guided refinement.

## Code generation with self-written tests

HumanEval and MBPP are used in Python and, through the MultiPL-E compiler, in Rust, which the authors use to show the approach is language-agnostic. LeetcodeHardGym contains 40 hard-rated Leetcode questions released after October 8, 2022, the pre-training cutoff of GPT-4. Test suites are produced by Chain-of-Thought prompting, filtered by building a valid abstract syntax tree for each test, and then sampled to at most 6 unit tests.

Because the tests are self-generated, pass@1 remains eligible for reporting, and the learning loop uses a memory limit of 1 experience.

Reflexion reached 91.0 pass@1 on HumanEval Python against 80.1 for GPT-4, and 68.0 on HumanEval Rust against 60.0 for GPT-4. On LeetcodeHardGym Python it reached 15.0 against 7.5 for GPT-4, and on MBPP Rust 75.4 against 70.9. MBPP Python is the exception, with Reflexion at 77.1 against 80.1 for GPT-4, a result the authors investigate further.

Table 1 lists these pass@1 values for each benchmark and language.

Table 2 breaks test-generation and solution outcomes down for HumanEval and MBPP in both languages. A false positive is a case where all tests pass but the solution is wrong, and the authors say a false negative is the safer error because reflection can then find the incorrect test and keep a correct solution. The baseline pass@1 is 82% for HumanEval Python and 80% for MBPP Python, yet the false positive test-execution rate is 16.3% for MBPP Python against 1.4% for HumanEval Python.

The authors link the weaker MBPP Python result to this gap.

Table 3 studies Reflexion on the 50 hardest HumanEval Rust problems, comparing the full method with variants that omit parts of it. Removing test generation lowers pass@1 to 0.52 from a 0.60 baseline, while the full Reflexion reaches 0.68. Removing the natural language self-reflection step leaves pass@1 at the baseline's 0.60. The authors say that without unit tests the agent cannot tell whether its implementation is correct, so it makes harmful edits.

Figure 3 is not this table, but Table 3 is the ablation the paragraph describes, and the authors argue that blind trial-and-error debugging without self-reflection is ineffective on harder tasks such as complex Rust programs.

## Limitations

Long-term memory is a sliding window with a maximum capacity, and the authors suggest vector embedding databases or SQL databases as future extensions. Because Reflexion is a form of policy optimization in natural language, the authors note that it may settle in non-optimal local minima. Reflexion also depends on the LLM's self-evaluation or on heuristics, and it has no formal guarantee of success.

For code, test-driven development is hard to specify for non-deterministic generator functions, impure functions that call APIs, outputs that depend on hardware, and concurrent behaviour.

## Paper info

- **Authors**: Noah Shinn, Federico Cassano, Edward Berman, Ashwin Gopinath, Karthik Narasimhan, Shunyu Yao
- **Venue**: arXiv · Preprint
- **First published**: 2023-3-20
- **Added**: 2026-10-20
- **Updated**: 2023-10-10
- **Version**: v4
- **arXiv**: 2303.11366
- **Category**: cs.AI · cs.CL · cs.LG
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2303.11366v4) · [PDF ↗](https://arxiv.org/pdf/2303.11366v4)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

Large language models (LLMs) have been increasingly used to interact with external environments (e.g., games, compilers, APIs) as goal-driven agents. However, it remains challenging for these language agents to quickly and efficiently learn from trial-and-error as traditional reinforcement learning methods require extensive training samples and expensive model fine-tuning. We propose Reflexion, a novel framework to reinforce language agents not by updating weights, but instead through linguistic feedback. Concretely, Reflexion agents verbally reflect on task feedback signals, then maintain their own reflective text in an episodic memory buffer to induce better decision-making in subsequent trials. Reflexion is flexible enough to incorporate various types (scalar values or free-form language) and sources (external or internally simulated) of feedback signals, and obtains significant improvements over a baseline agent across diverse tasks (sequential decision-making, coding, language reasoning). For example, Reflexion achieves a 91% pass@1 accuracy on the HumanEval coding benchmark, surpassing the previous state-of-the-art GPT-4 that achieves 80%. We also conduct ablation and analysis studies using different feedback signals, feedback incorporation methods, and agent types, and provide insights into how they affect performance.

## Quote from the paper

Noah Shinn, Federico Cassano, Edward Berman, Ashwin Gopinath, Karthik Narasimhan, Shunyu Yao (2023). Reflexion: Language Agents with Verbal Reinforcement Learning. arXiv:2303.11366v4. https://arxiv.org/abs/2303.11366v4

**BibTeX**

```
@misc{shinn2023reflexion,
  title = {{Reflexion: Language Agents with Verbal Reinforcement Learning}},
  author = {Noah Shinn and Federico Cassano and Edward Berman and Ashwin Gopinath and Karthik Narasimhan and Shunyu Yao},
  year = {2023},
  eprint = {2303.11366},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2303.11366v4}
}
```

## Other paper commentary

- [A Generalist Agent](https://refivu.com/en/papers/890475cb-e797-43df-8de3-0d0eb9ed882e-a-generalist-agent.md)
- [Implicit Intelligence - Evaluating Agents on What Users Don’t Say](https://refivu.com/en/papers/46a3027e-e7cd-4c3e-be85-2fe588fd1675-implicit-intelligence-evaluating-agents-on-what-users-don.md)
- [Escaping Whack-a-Mole: Optimizing Documentation as Repo-Specific Playbooks for Coding Agents](https://refivu.com/en/papers/52e2d558-711f-4753-af6e-c88268527a9b-escaping-whack-a-mole-optimizing-documentation-as-repo.md)
- [VeriLadder: A Multi-Agent Specification Refinement System for Tool-Verified Verilog Datasets](https://refivu.com/en/papers/f3a3ce4f-fd41-462e-8bb7-f3e5263ba827-veriladder-a-multi-agent-specification-refinement-system-for.md)
- [AutoPILOT: A Visual Agent Harness for Real-Time Gameplay](https://refivu.com/en/papers/610b7c6f-2c3b-4308-bb50-b139b48fceb7-autopilot-a-visual-agent-harness-for-real-time.md)
- [LesionAgent: Training-Free Agentic Tumor Tracking and Response Assessment in Longitudinal CT](https://refivu.com/en/papers/aad1fd25-45a9-4d0f-bd6b-86f8fce045bc-lesionagent-training-free-agentic-tumor-tracking-and.md)
- [SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot](https://refivu.com/en/papers/98e70bdf-a832-4686-b3f8-e3eefd5887c4-sparsegpt-massive-language-models-can-be-accurately-pruned.md)
- [GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints](https://refivu.com/en/papers/11792bcd-8c73-4a2d-8b43-c855c3d7ad48-gqa-training-generalized-multi-query-transformer-models-from.md)
- [Fast Transformer Decoding: One Write-Head is All You Need](https://refivu.com/en/papers/65f892e7-2a21-4ce7-9e89-c75f7ec6b23c-fast-transformer-decoding-one-write-head-is-all.md)
- [Finetuned Language Models Are Zero-Shot Learners](https://refivu.com/en/papers/3dedf278-64d7-4653-93ff-bf4504ae70ac-finetuned-language-models-are-zero-shot-learners.md)
- [Dynamic Routing Between Capsules](https://refivu.com/en/papers/a4e87f62-36cc-47df-991e-87dd01b1a4ef-dynamic-routing-between-capsules.md)
- [Neural Machine Translation of Rare Words with Subword Units](https://refivu.com/en/papers/0950e659-f6cc-4852-b244-bbb2742bf059-neural-machine-translation-of-rare-words-with-subword.md)

## Terms in this paper

- [pass@1](https://refivu.com/en/terms/0b5f8fd75383-pass-1)
- [ReAct](https://refivu.com/en/terms/420780a0fd8c-react)
- [HotPotQA](https://refivu.com/en/terms/16cb986b71c1-hotpotqa)
- [Reflexion](https://refivu.com/en/terms/ae549dc1c40e-reflexion)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/a572f458-b121-4d38-bfc9-7a77309a3aba-reflexion-language-agents-with-verbal-reinforcement-learning)
