TL;DR
Verbal reinforcement learning improves a language-model agent by having it reflect in words on each failed attempt. The reflection is stored in a short memory that is placed in the prompt of the next attempt. The model's weights never change. The reward signal is turned into text, and the text is what carries the lesson forward.
Where you'll see it: LLM agents that fix their own code after failing unit tests, web or household agents that retry a multi-step task with notes from the last failure, and self-correcting question answering.
Intuition
A coach's notes, not a new brain
Think of a student who keeps failing a driving test at the same roundabout. Each time the examiner says "you failed", which is a bare signal. A better examiner says "you cut in front of the bus at the second exit, check the mirror before you turn". The second message is useful because it names the mistake and the fix. The student writes it on an index card and reads it before the next test. The brain is the same, but the card changes what happens.
Reinforcement Learning normally improves an agent by changing its parameters, using many trials and a scalar reward. A large language model is expensive to retrain on every mistake, and a scalar like "0" tells it little. Verbal reinforcement keeps the parameters fixed. It turns the failure into a short piece of text that explains what went wrong, and it keeps that text in the agent's context, the way In-Context Learning puts examples into the prompt.
The paper's authors describe the reflection as acting like a "semantic" gradient signal. A gradient tells a parameter which way to move. A reflection tells the agent which decision to change, in ordinary words.
flowchart LR A["Actor runs a trial with memory"] --> B["Evaluator scores the trajectory"] B -->|success| D["Stop"] B -->|failure| C["Self-reflection writes a note"] C --> M["Memory keeps the latest notes"] M --> A
The math
The usual setup
In standard reinforcement learning an agent follows a policy , a probability of taking action in state , with parameters . A trajectory is the sequence of states and actions in one episode. The reward is a number, and the learning goal is to choose so that the expected reward is high. Methods such as Policy Gradient do this by moving along the gradient of expected reward.
The verbal version
Verbal reinforcement keeps fixed and adds a memory , a list of text notes. Let be the actor (a language model with a prompt), the evaluator, and the self-reflection model, which is also a language model. One trial runs as follows.
- The actor produces a trajectory from the task and the current memory: .
- The evaluator scores it: . This is a scalar, or a binary success flag.
- If the attempt failed, the reflection model writes a note from the trajectory and the score: .
- The note is appended to memory, and only the most recent notes are kept: .
The loop repeats until the evaluator accepts an attempt. The paper gives as usually 1 to 3, because the notes must fit in the model's context window.
Read this as an optimisation. The "parameter" being improved is the memory, and the "update rule" is an LLM writing a note. The actor's policy is , so changing the memory changes the policy without touching .
Why a bounded memory is enough
Each note summarises one failed trial. Keeping the last notes gives the actor the most recent lessons at a fixed prompt cost. The paper also names a limitation of this choice: the window forgets older lessons, and a lesson that matters only much later can be lost. Longer memories would need retrieval, such as a vector store.
Worked examples
The paper runs an ablation on the 50 hardest HumanEval problems translated to Rust, using GPT-4 as the base model. The numbers below are the pass@1 accuracies from the paper's ablation table.
- Base model, no test generation and no reflection: problems solved.
- Full Reflexion, with generated tests and reflection: problems solved.
- Reflexion without internal test generation, so the agent reflects without checking its code: problems solved.
- Gain from reflection with tests: more problems, an 8 point gain.
- Dropping test generation loses problems relative to full Reflexion, which leaves it problems below the base model.
Interpretation: reflection alone with no reliable signal does not help. The reflection needed the test outcomes to know what went wrong. Without them the agent made harmful edits, and accuracy fell below the baseline.
This trace is hand-written to show the mechanism. It is not output from the paper. Suppose the task is to find an object in a house, the memory size is , and the evaluator returns 0 for failure and 1 for success.
- Trial 1. Memory is empty. The agent opens the wrong drawer, searches the fridge, and reports failure, . The reflection says: "I searched the fridge before checking the countertop, where the object was likely to be."
- Trial 2. Memory holds that note. The agent checks the countertop first, finds nothing, then searches a drawer, and fails again. The reflection says: "Check the drawer near the sink before the bedroom, because I skipped it."
- Trial 3. Memory now holds both notes, since allows two. The agent starts at the sink drawer, finds the object, and succeeds, .
- If a fourth failure happened, the oldest note would be dropped to make room.
Interpretation: no weights moved. Each failure changed what the actor saw next, and only the two most recent lessons were kept.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| The task has a reliable check, such as unit tests or an exact-match answer | Reflection works best with a clear signal | Use this method, with the check as the evaluator |
| The only feedback is "failed" with no detail | The reflection has little to work from | Give richer feedback, such as compiler errors or environment messages |
| Long tasks with many lessons | The bounded memory drops early lessons | Add retrieval over a store of past notes |
| The model is weak at self-critique | Reflections can be wrong, and then they mislead the next attempt | Use a stronger reflection model, or check reflections against the evaluator |
| Fine-tuning is possible and the task recurs at scale | Prompt memory costs context on every call | Use Fine-Tuning or a policy-gradient method such as Proximal Policy Optimization (PPO) |
Failure modes to watch for:
- Reflection drift. A wrong note persists in memory and steers later attempts the wrong way, because nothing forces the note to be checked.
- Context cost. Every stored note is read on every trial. The bound on keeps this under control, but it is a hard limit on how much can be learned.
- Overfitting to the task. Notes written for one environment may not apply to another. The memory is specific to the task it was written for.
- Missing signal. The paper reports that self-reflection without the test-generation step did worse than the base model. A reflection with no check can make the agent edit correct code into wrong code.
History
Shinn and colleagues (2023) introduced Reflexion, which the paper describes as reinforcing language agents through linguistic feedback rather than by updating weights. Their experiments covered three areas: sequential decisions in household text environments, multi-hop question answering, and code writing.
In the sequential decision task, the paper reports that ReAct with Reflexion completed 130 of 134 tasks, against a ReAct-only baseline whose performance stopped improving after a few trials. On a 100-question HotPotQA ablation, the paper reports an 8% absolute boost from the self-reflection step over an episodic-memory-only variant that keeps the most recent trajectory. On HumanEval in Python, the paper reports 91% pass@1 for Reflexion, against a previous best of 80.1% for GPT-4 as reported in the same table.
The paper frames Reflexion as an alternative to policy or value-based RL that needs no fine-tuning of the language model, and the loop that carries a lesson from one attempt to the next is its central mechanism.
Check yourself
QuestionWhat plays the role of the parameter update in verbal reinforcement learning, and what stays fixed?Show answer
The memory of reflection notes plays the role of the update. The model weights stay fixed. Each failed trial adds a note, and that changes the prompt, which changes the policy without any change to .
QuestionIn the Rust ablation, the base model has accuracy 0.60 and full Reflexion has 0.68 on 50 problems. How many more problems are solved, and what is the percentage point gain?Show answer
and , so 4 more problems are solved. The gain is , which is 8 percentage points.
QuestionAn agent has memory size and has failed five trials. Which notes are in memory before trial six?Show answer
Only the three most recent reflections, from trials three, four and five. The reflections from trials one and two were dropped when newer notes were added, because the memory keeps the last items.
QuestionWhy did removing the test-generation step make Reflexion worse than the base model on the Rust subset?Show answer
Without generated tests, the agent cannot tell whether its current code is correct, so its reflections are not grounded. It keeps making edits, some of which break working code. The paper reports 52% accuracy for this variant, against 60% for the base model.
QuestionA team wants an agent to improve on a task that recurs thousands of times a day, and the prompt memory is costing too much context. What are two options and their tradeoffs?Show answer
Fine-tuning or a policy-gradient method changes the weights, so the memory is no longer needed in every prompt. The cost is the training effort and the need for a reliable reward signal. Keeping the prompt memory costs context on every call but needs no training. A reasonable choice depends on how often the task recurs and how stable it is.