Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

~7 min readNortheastern / MIT · 2023

Reflexion,
explained.

Reinforcement learning improves an agent by nudging millions of weights — slow, expensive, and impossible if the model is behind an API. Reflexion found a shortcut hiding in plain sight: when the agent fails, have it write down why, keep the note, and let it read its own advice before trying again. No gradients. No fine-tuning. The agent gets better the way people do — by remembering what went wrong.

The delta

What changes against ReAct: a failure becomes an instruction

Rungs 1 and 2 get one attempt. If the agent fails, it fails; retrying it gives you a fresh sample from the same distribution, which fails in much the same way. The obvious fix is to learn from the failure, and the obvious way to learn is a gradient step — expensive, slow, and impossible if you do not own the weights.

The change is to learn in words instead of weights. After a failed attempt, the agent is shown the trajectory and asked to write a reflection on why it failed — a short, specific diagnosis, not a score. That reflection is stored and placed in the context of the next attempt. The policy has changed, in the only sense that matters for behaviour, with no parameters touched.

Stated in the units the ladder compares on: the loop is actor, evaluator, reflector — something acts, something determines that the outcome was bad, and something converts that into an instruction the next attempt can use. The reported result on a code benchmark is in the region of 91%, from repeated attempts where a single attempt is far lower. And the cost is a few extra model calls, which against any form of training is close to nothing.

01

Agents that make the same mistake twice

A ReAct-style agent can act, observe, and adapt within one attempt. But let it fail the whole task and try again, and something embarrassing happens: it repeats the same mistake. Nothing carried over. The standard fixes were both bad — fine-tune on failures (expensive, impossible via API, and one task's lessons overwrite another's) or just replay the failed attempt in context (raw trajectories help some, but a short written lesson distilled from the failure is a stronger and more compact signal).

What's missing is what humans do between attempts: compress the failure into a lesson. Not "here are the 4,000 tokens of my failed attempt" but "I forgot to handle the empty-list case."

02

Actor, Evaluator, Reflector

Reflexion splits the retry loop into three roles. The Actor attempts the task — writing code, navigating a household simulator, searching for answers. The Evaluator grades the attempt: unit tests for code, task success for environments, an LLM judge where nothing crisper exists. And the Self-Reflection model turns the graded failure into a short, specific verbal lesson.

The Reflexion loop — reinforcement through words
Actor attempts
→
Evaluator grades
tests · env · judge
→
Reflector writes
why it failed
→
Episodic memory
lessons persist
↺
Retry with lessons
in context

The lessons accumulate in an episodic memory buffer that's prepended to every new attempt. Attempt three doesn't just know the task — it knows exactly how attempts one and two died.

03

Why words beat scalars

Classic RL compresses feedback into a single number — reward 0. Everything about why is discarded, and the algorithm spends thousands of episodes rediscovering it through trial and error. A verbal reflection keeps the why: which assumption was wrong, which edge case was missed, what to try instead. It's credit assignment in prose — precise, immediate, and executable by the very next attempt.

Test failed: merge_intervals([[1,4],[4,5]]) → expected [[1,5]]
Reflection: "I treated touching intervals as disjoint. Boundary equality must merge — use start <= prev_end, not <."
Attempt 2: passes.
The key idea

The model already contains the machinery to diagnose failures and follow advice — it's a language model. Reflexion routes the learning signal through that machinery instead of through the weights. Policy improvement becomes a context update.

The whole loop is one line of state that survives between attempts — the memory of what went wrong:

Delete that memory arrow and every retry is attempt one again. The runnable version below shows it fix the boundary bug on attempt two — and a memoryless retry failing forever.

05

The limits

Reflexion learns nothing durable — lessons live in a context buffer, bounded by the window, gone when the episode ends (unless you persist them into real memory). It leans on the Evaluator: crisp signals like unit tests make it soar; fuzzy self-evaluation can reinforce confident nonsense. And reflection quality is capped by the model's own diagnostic ability — an agent that misunderstands why it failed writes itself bad advice and then dutifully follows it.

It's also, quietly, a test-time method: multiple attempts cost multiple rollouts. Like self-consistency and ToT, it buys capability with inference compute.

06

Why it still matters

Reflexion named and validated the pattern that now lives inside nearly every serious agent: try → check → diagnose in words → retry with the diagnosis. Every coding agent that reads its own test failures and patches, every harness with a critique-then-revise step, every eval loop that feeds errors back as guidance — that's the Reflexion loop, productionized.

Its deeper claim aged even better: a model's language channel is a legitimate substrate for learning. That idea threads through self-critique training, agent post-mortems written to memory, and the whole self-improvement research line. Weights are one place to store lessons; words, it turns out, are another.

Read next

The within-attempt loop it extends: ReAct. Where the lessons should live: MemGPT. The evaluator side: Agent Evals.

How it works

How a Reflexion run works, trial by trial

Reflexion is a loop around an existing agent, built from three prompted models and a short memory. Nothing is trained; every component is a language-model call.

Problem + signature Write up to 6 tests Actor writes code CoT prompt, AST-valid only Run its own tests All pass? Submit to hidden tests yes Write a reflection Memory: last Ω notes no pass on wrong code = false positive MBPP 16.3%, HumanEval 1.4% 1 note for code, 3 for ALFWorld
Reflexion's programming loop with GPT-4: the agent writes its own tests, and a failure becomes a written reflection kept in a one-entry memory for the next attempt. If wrong code passes the agent's own tests, the loop submits it without reflecting, which is what hurt MBPP.
  1. Choose the actor. The actor Ma is whatever agent suits the task: ReAct for the ALFWorld household games and for HotpotQA with a Wikipedia API, chain of thought for HotpotQA with the supporting paragraphs supplied, and a code writer for programming. Its policy is πθ(ai | si) with θ = {Ma, mem}: the frozen model plus whatever is in memory.
  2. Run one trial. The actor produces a trajectory of actions and observations, conditioned on the task and on the memory.
  3. Score it. The evaluator Me returns a sparse signal, usually pass or fail. On HotpotQA it is exact match against the answer. In ALFWorld, where the environment only reports completion, it is either an LLM classifier or a hand-written heuristic that flags failure when the agent repeats the same action and gets the same response more than three times, or takes more than 30 actions. For code it is a test suite the agent writes itself: chain-of-thought prompting proposes tests, any that do not parse into a valid syntax tree are dropped, and up to six are sampled.
  4. Reflect. The self-reflection model Msr reads the signal, the trajectory and the current memory and writes a short diagnosis with a plan: in one ALFWorld example, that it should have found the desk lamp first and then the mug, not the other way round.
  5. Store it, within a cap. The reflection is appended to an episodic memory that keeps only the last Ω entries, usually 1 to 3 so the prompt fits the context window: three for ALFWorld and HotpotQA, one for programming.
  6. Retry. The next trial starts with the memory in the prompt. The loop stops when the evaluator passes or the trial budget runs out. ALFWorld ran for 12 trials; on HotpotQA an agent retried a question until it failed three times in a row.
  7. Submit once. For code, only the final program is scored against the benchmark's hidden tests. All the iteration happens against the agent's own tests, which is what keeps the reported number a pass@1.

The baselines are the same agents without the reflection step. In ALFWorld, a baseline run that trips the heuristic simply resets and starts a new trial with nothing learned. On HotpotQA, sampling at temperature 0.7, the baselines solved none of their first-trial failures on any later trial.

The models differ by task: GPT-4 for the programming results, a GPT-3 model with ReAct's two few-shot trajectories for ALFWorld, and text-davinci-003, gpt-3.5-turbo and GPT-4 compared on 100 HotpotQA questions. HotpotQA prompts used 6 examples for chain of thought, 2 for ReAct and 2 for self-reflection.

The math

Reflexion's policy, loop and stopping rule

πθ(ai | si), θ = {Ma, mem}
τt ~ πθ → rt = Me(τt) → srt = Msr(τt, rt, mem) → mem ← last Ω of [mem, srt]
stop when Me(τt) = pass or t = Tmax · ALFWorld trigger: same action and observation more than 3 times, or more than 30 actions
  • θ — the parameters of the policy. Reflexion's move is that one of them is text: updating mem changes behavior without touching Ma.
  • rt — the evaluator's reward, usually binary: exact match, task success, or all self-written tests passing.
  • srt — the verbal reinforcement: a few sentences naming what went wrong and what to do instead.
  • Ω — the memory cap, 1 to 3 reflections.

The extremes map onto the failure modes. With Ω = 0 every retry is a fresh sample from the same policy, and on HotpotQA such retries fixed nothing. If Me passes a wrong answer, the loop stops early and never reflects, which is how false-positive self-tests hurt MBPP. If Msr cannot diagnose its own errors, the memory fills with useless advice: with the smaller starchat-beta model, HumanEval pass@1 stayed at 0.26 with or without Reflexion.

The evidence

Reflexion on HumanEval, MBPP, ALFWorld and HotpotQA, including the misses

The programming runs use GPT-4 with self-generated tests and report pass@1; each baseline is the same model's single attempt.

BenchmarkBaselineReflexion
HumanEval, Python (pass@1)80.191.0
HumanEval, Rust60.068.0
MBPP, Python80.177.1
MBPP, Rust70.975.4
LeetcodeHardGym, Python7.515.0
ALFWorld, 134 tasks, ReAct actorstops improving after trial 6 or 7130 of 134 solved within 12 trials
HotpotQA, ReAct actor, GPT-4, 100 questions0.390.51

Plain GPT-4 at 80.1 was the state of the art Reflexion had to beat; the best earlier method the authors list, CodeT with GPT-3.5, scored 65.8. LeetcodeHardGym is the authors' own set of 40 hard Leetcode problems released after GPT-4's pretraining cutoff, to avoid contamination. On ALFWorld the ReAct-only agent settled at a 22 percent hallucination rate with no sign of recovering; a common baseline error was believing it held an item it did not.

Two ablations isolate what does the work. On the 50 hardest HumanEval Rust problems the full method scored 0.68 against a 0.60 baseline. Keeping the self-written tests but dropping reflection stayed at 0.60. Keeping reflection but dropping the tests fell to 0.52, below the baseline, because an agent that cannot tell when its code is correct never stops early and keeps editing working programs. On HotpotQA with the supporting paragraphs given, reflection added 8 points over episodic memory alone, which simply replays the last trajectory.

The misses are as informative. MBPP Python got worse, 80.1 to 77.1, because the self-written tests were unreliable there: 16.3 percent of submissions that passed the agent's own tests failed the hidden ones, against 1.4 percent on HumanEval Python, and a false positive ends the loop on wrong code. On WebShop, two-shot ReAct plus Reflexion showed no improvement after four trials across 100 environments, and its reflections were unhelpful, which the authors read as a limit on tasks needing diverse exploration. And the method needs a strong model: with starchat-beta, HumanEval pass@1 was 0.26 with and without reflection.

Since then

What the authors admit, and what happened next

The loop needs an evaluator, and that is where it is strong or hopeless with nothing in between. Where failure is detected by running tests — code, as in the headline result — the signal is reliable and the method works well. Where the agent must judge its own success, the loop inherits a known weakness: models are poor at recognising their own errors, and an agent that believes it succeeded will not reflect at all.

The second failure mode is that a reflection can be wrong. A confident, incorrect diagnosis of the failure is now in the context, actively steering the next attempt away from the answer, and nothing removes it. Verbal lessons accumulate without being validated, which is a different risk profile from a gradient step that at least moved in the direction of a measured loss.

How it held up: retry-with-reflection is in every agent framework, because it is the cheapest self-correction available and it needs no infrastructure. The framing — natural language as the medium of policy improvement — is the durable idea, and rung 4's answer to the wrong-reflection problem is to store something that can be executed and tested rather than merely read.

SOLVE IT YOURSELF

Watch an agent learn from its own failure

Reflexion's loop is small enough to run — using the paper's own merge_intervals boundary bug. The Actor writes code, the Evaluator runs unit tests, and the Reflector turns the failing case into a specific lesson ("touching intervals must merge — use <=") that persists in memory. Watch it fail attempt one, reflect, and pass attempt two. Then watch a memoryless retry repeat the same mistake five times. The only difference is whether the lesson is remembered.

YOUR TASK

Write the body of actor. Everything else in the file is already written; this is the function the paper is about. Press ▶ Run to check it against the 5 assertions below — they start red.

WHAT IT HAS TO SATISFY — 5 ASSERTIONS
  1. Attempt one, with no lessons, fails the touching-intervals test
  2. With the reflected lesson the actor passes
  3. The reflexion loop succeeds on attempt two
  4. A memoryless retry never succeeds
  5. The reflection targets the real boundary bug
CPython · WebAssembly
Questions

Questions people ask about Reflexion

How is Reflexion different from ReAct?

ReAct works inside a single attempt: the agent alternates thoughts, actions and observations until it finishes. Reflexion works across attempts. It wraps an agent, often ReAct itself, with an evaluator that judges each finished trial and a self-reflection model that writes a short diagnosis of a failure into memory for the next trial. In the paper's ALFWorld runs, ReAct alone stopped improving after six or seven trials, while ReAct plus Reflexion went on to solve 130 of 134 tasks within 12 trials. Neither method updates the model's weights. ReAct changes what the agent does within a trial; Reflexion changes what it knows at the start of the next one.

How did Reflexion reach 91 percent on HumanEval?

By letting GPT-4 test and critique its own code before submitting. For each problem the agent wrote candidate unit tests with chain-of-thought prompting, kept only the syntactically valid ones and sampled up to six. It wrote a solution, ran its own tests, and on any failure wrote a reflection on what went wrong, held in a one-entry memory for the next attempt. Only the final program was scored on HumanEval's hidden tests, so the result counts as pass@1: 91.0 percent against 80.1 for GPT-4 alone and 65.8 for CodeT with GPT-3.5, the best earlier method the authors list. The self-tests on HumanEval were reliable, with only 1.4 percent of passing submissions actually wrong.

Why did Reflexion score lower than GPT-4 alone on MBPP?

Because its own tests misled it. Reflexion stops as soon as a solution passes the tests it wrote, so a weak test suite that passes wrong code ends the loop early and submits the mistake without any reflection. On MBPP Python, 16.3 percent of submissions that passed the agent's internal tests failed the real ones, against 1.4 percent on HumanEval Python. The result was a drop from 80.1 to 77.1 percent pass@1, while HumanEval rose from 80.1 to 91.0. The authors note that a false negative does less harm, since a reflection can conclude that a failing test, not the code, is the thing that is wrong.

What does verbal reinforcement learning mean?

It is the paper's name for improving an agent's policy with words instead of gradient updates. In reinforcement learning the policy changes by adjusting parameters toward higher reward. In Reflexion the policy is a frozen language model plus a memory, and learning means adding a sentence to that memory: after a failure, a reflection model turns the sparse reward, often just pass or fail, into an explanation of which step went wrong and what to try instead. That text is placed in the context of the next attempt. The authors frame it as policy optimization carried out in natural language, which also means it can settle into local minima like any optimizer.

How many reflections does Reflexion keep in memory?

Very few. The episodic memory is a sliding window capped at a maximum number of stored experiences, usually one to three, so the prompt stays within the model's context limit. The ALFWorld and HotpotQA agents kept their last three reflections; the programming agent kept one. Older lessons are simply dropped, which is why the paper lists the bounded memory as a limitation and suggests future versions use vector databases or SQL stores. The small cap is also why reflections have to be specific: a few sentences of advice are all the agent carries from one attempt to the next.

Does Reflexion work with smaller open models?

Not in the paper's test. Run with starchat-beta, an open code model, Reflexion left HumanEval Python pass@1 unchanged at 0.26 across eight trials, and the authors conclude that writing useful self-corrections is an emergent ability of stronger, larger models. The method also failed on WebShop with a capable model: after four trials across 100 shopping requests there was no sign of improvement and the reflections were unhelpful, which the authors attribute to tasks that need very diverse exploration and precise search queries. Reflexion amplifies an agent that can already diagnose its own mistakes; it does not create that ability.

Check yourself

4 questions to test what you just read

Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.

On the 50 hardest HumanEval Rust problems, dropping the self-written tests took Reflexion from 0.68 to 0.52, below the 0.60 baseline. Why would reflection without tests be worse than no reflection at all?

Show answer

Without tests the agent cannot tell when its code is already correct, so it cannot stop early. It runs every trial and keeps reflecting and editing, which damages implementations that were right. Dropping reflection but keeping the tests scored 0.60: errors were caught, but the fixes did not follow from them.

Reflexion's self-tests had a false-positive rate of 16.3 percent on MBPP Python and 1.4 percent on HumanEval Python. Which benchmark should Reflexion help more, and through what mechanism?

Show answer

HumanEval. A false positive means wrong code passes the agent's tests, so the loop ends with no reflection and submits it. MBPP's unreliable tests let many wrong solutions out early, and Reflexion fell from 80.1 to 77.1 there while HumanEval rose from 80.1 to 91.0.

An ALFWorld agent repeats the same action and sees the same response four times. Under the paper's heuristic, what happens next in a Reflexion run, and what does the baseline do instead?

Show answer

Four repeats exceed the limit of three, so the evaluator flags a failure. Reflexion writes a reflection, keeps it in its last-three memory, resets the environment and starts a new trial with the lesson in context. The baseline skips the reflection: it resets and retries with nothing learned.

Why are Reflexion's HumanEval scores pass@1 even though the agent attempts each problem several times?

Show answer

Every intermediate attempt is checked against tests the agent wrote, never against the benchmark's hidden tests. Only the final submission is graded, once, so one solution per problem is scored. A method that debugs against the ground-truth tests would not qualify as pass@1.

Where this sits

Agents that act

Give the model a tool, then a loop, then a memory, then a world. Ends on the 2026 paper measuring how badly the whole stack degrades over many turns.

  1. 1ReAct2023
  2. 2Toolformer2023
  3. 3Reflexion2023
  4. 4Voyager2023
  5. 5Generative Agents2023
  6. 6MemGPT2023
  7. 7LLMs Get Lost in Multi-Turn Conversation2026

All 110 papers, in 19 ladders →

Finished this one? 0 / 110 Paper Breakdowns done
NextVoyager Next on the “Agents that act” ladder · rung 4 of 7

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns