Reflexion Pattern
An agent that fails a task, forgets why, and tries the same approach again is not learning. The Reflexion pattern fixes that by writing the lesson down: after an attempt fails, the agent produces a short verbal explanation of what went wrong and keeps it, so the next attempt begins with the critique in hand.
The cycle
Three components, run over repeated attempts at the same task:
- An actor attempts the task and produces a trajectory of steps.
- An evaluator scores the result — a unit test, a reward signal, a rubric.
- A self-reflection step turns that score into usable text: the query returned nothing because the date filter was inverted.
Those reflections accumulate in an episodic memory that is prepended to the next attempt. Nothing in the model's weights changes; the improvement lives entirely in context.
Why it matters
This is reinforcement learning done in language rather than in gradients, and it is dramatically cheaper — no training run, no labelled dataset, feedback usable after a single failure. The 2023 paper reported large gains on coding and reasoning benchmarks from a handful of retries. The pattern needs two things to work: an evaluator honest enough to tell success from failure, and a task worth retrying. Where Reflection critiques one output and moves on, Reflexion is explicitly about memory across attempts — which also means its reflections consume context, and a bad lesson, once written, is carried into every subsequent try.
The Reflexion pattern is an agent architecture in which a failed or low-scoring attempt is fed back to the model as written criticism, stored in memory, and read before the next attempt. Instead of discarding a bad trajectory, the agent converts it into a lesson it can re-read. It matters because it gives a loop a way to improve across attempts, rather than repeating one mistake until a step limit ends the run.
Imagine a student who gets a question wrong, then writes a short note to themselves about why they slipped up, and keeps that note beside them for the next attempt. The Reflexion pattern works the same way for software. After the program tries a task and the result falls short, it writes down in plain words what went wrong. That reflection goes into its notes and is read back before the next try.
Without it, a program that fails simply fails again in the same way. With it, every fresh attempt starts from an honest account of the last one.