Reflexion: Language Agents with Verbal Reinforcement Learning
Read first: ReAct: Synergizing Reasoning and Acting in Language Models
TL;DR. Reflexion wraps an agent, often a ReAct actor, in a retry loop. After each trial an evaluator scores the trajectory. A self-reflection model turns that score into a few sentences about what went wrong, and the next trial runs with those sentences in context. The paper calls this “verbal reinforcement learning”, but no weights are updated. What improves is the context, within a single task.
Key idea
Section titled “Key idea”There are three LM components:
- an Actor that acts;
- an Evaluator that returns a reward, such as unit-test results, exact match or a heuristic;
- a Self-Reflection model that writes a verbal diagnosis.
The reflections go into a bounded memory, , with = 1–3 entries. The policy is written with . The loop is: act, evaluate, reflect, append to , retry. It stops when the evaluator passes or a trial limit is reached. For code, the actor also writes its own unit tests: up to 6 per problem, filtered for syntactic validity. Those tests are the evaluator.
Results.
- ALFWorld (134 tasks, ReAct actor): Reflexion solves 130 tasks within 12 trials. A ReAct-only baseline plateaus around trials 6–7. Reflection is triggered by a heuristic that detects repeated action–observation cycles or very long episodes.
- HotpotQA (100 questions): the abstract reports +20%. The trial signal is exact match with the gold answer, so read this as retry-with-oracle-feedback.
- Code, pass@1 (vs the GPT-4 baseline the paper reports):
- HumanEval-Python 91.0 (vs 80.1) and HumanEval-Rust 68.0 (vs 60.0).
- MBPP-Rust 75.4 (vs 70.9) and LeetcodeHardGym-Python 15.0 (vs 7.5).
- MBPP-Python is the one loss: 77.1 vs 80.1. The authors tie it to a 16.3% false-positive rate of self-generated tests there, vs 1.4% on HumanEval-Python.
- WebShop: no improvement (Appendix B.1); the agent gets stuck without useful diagnoses.
Connections
Section titled “Connections”- Before: ReAct, the actor in the decision-making experiments.
- Contrast: GEPA (persistent reflective prompt evolution); PPO (actual weight updates from reward).
- Related risk: a weak evaluator turns the loop into a way to satisfy the checker, the same failure as reward over-optimisation.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Mechanism
Reflexion writes its policy as π_θ with θ = (actor LM, memory) and calls the method verbal reinforcement learning. Explain what plays the role of the reward, the update and the parameters, why the actor's weights never change, and how this differs from GEPA, which also turns feedback into text.
What a strong answer covers
- Reward: a scalar or binary signal from the evaluator (tests passed, exact match, or a heuristic). The self-reflection model turns it into a short natural-language diagnosis.
- Update: append that reflection to a bounded memory (1–3 entries). The "parameters" that change are the context, not the LM weights.
- This is in-context adaptation within one task across trials. Nothing carries over to a new task, and nothing is optimised by gradient.
- GEPA also reflects in text, but it evolves a persistent prompt for a whole program, selected on a validation set and reused across tasks. Reflexion's memory is per-task episodic memory that is discarded afterwards.
- A policy-gradient method such as PPO would change weights from many episodes; Reflexion needs no rollouts batch and no gradient, but cannot improve the base policy.
- Critique
On HotpotQA, Reflexion decides whether a trial failed by exact match against the gold answer, then retries. Argue what the reported +20% gain measures under that protocol, and design the experiment that would tell you how much survives without the oracle.
What a strong answer covers
- The binary signal leaks the label: the agent learns that its answer is wrong without seeing the right one, and can keep trying until it passes. This is closer to pass@k with guided retries than to single-shot accuracy.
- Comparisons with baselines that get no feedback are therefore not like-for-like; the paper's own baselines at temperature 0.7 never fix a task that failed in trial 1.
- Experiment: replace exact match with a self-evaluation (an LM judge or self-consistency check) and with a noisy evaluator of known accuracy. Report accuracy against number of trials.
- Also report a pass@k baseline with the same number of attempts and an oracle stop, so the value of the written reflection is isolated from the value of retrying.
- What if…
In the HumanEval-Rust ablation (50 hardest problems), the base model scores 0.60; adding self-generated tests without reflection gives 0.60; reflection without tests gives 0.52; both give 0.68. Separately, self-generated tests have a 16.3% false-positive rate on MBPP-Python vs 1.4% on HumanEval-Python. Explain what each number says about which component carries the gain.
What a strong answer covers
- Tests alone do not help: knowing a test failed, without a diagnosis, does not change the next attempt.
- Reflection alone hurts (0.52): without grounded feedback the model rationalises and can rewrite correct code into wrong code.
- The gain needs both: grounded failure signals plus a written diagnosis that conditions the next attempt.
- False-positive tests stop the loop early on wrong code. That explains why Reflexion improves HumanEval-Python (91.0 vs 80.1) but loses on MBPP-Python (77.1 vs 80.1).
- The evaluator's precision is the bottleneck: a weak verifier makes the loop worse, which is the same lesson as reward hacking in RL.