Zenaique

Flashcard: how does Reflexion let an agent learn from failed runs?

Flashcard·Easy·4.0 · 0·~30s·Asked atC3 AiLangChainSiemens·Relevant atAnthropic
Attempt it
TL;DR

Reflexion has the agent attempt a task, fail, write a natural-language post-mortem to episodic memory, and prepend that reflection on the next attempt. The agent learns from failure without any weight updates.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine a student who fails a coding test, then sits down and writes a one-paragraph note to their future self: I used the wrong loop, I forgot the base case, next time check the edge cases first. They paste that note on their desk. The next time they take a similar test, they read the note before starting. They are not any smarter in the brain sense, but they are smarter in the context sense because the note tells them what to avoid. Reflexion does exactly that for an AI agent. After a failed attempt, the agent writes a short reflection about what went wrong, stores it, and reads it before the next attempt. No retraining, just self-written notes that make the next try better.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Reflexion is a pattern that lets an agent improve across attempts by writing a natural-language post-mortem after each failed trial and prepending that reflection to the prompt on the next attempt. Introduced by Shinn et al. in 2023, it adds a meta-layer on top of an inner agent loop (typically ReAct).

The surprising property is that the agent improves without any weight updates. The 'learning' lives entirely in self-written text that becomes input on the next run. This is what makes Reflexion a model-agnostic pattern that works on any LLM with reasonable in-context learning, from open-weight models like Llama 4 Maverick to frontier models like Claude Opus 4.7.

This explanation walks through Reflexion's four components, how the outer loop runs in practice, why no weights need to change for the agent to improve, the failure modes that show up in production, and where the pattern fits in the broader 2026 agent stack.

The four-component anatomy

A clean Reflexion implementation has four distinct components.

The actor is the inner agent that attempts the task. In most modern implementations this is a ReAct loop: Thought, Action, Observation, repeat, until the agent emits a final answer or hits a turn cap. The actor produces a trajectory: the full transcript of the attempt.

The evaluator scores the outcome. For a coding task it can be a unit-test runner returning pass/fail with the failing test name. For a question-answering task it can be a ground-truth checker. For open-ended tasks it can be an LLM-as-judge scoring the answer against a rubric. The evaluator must return a signal richer than just a binary; the reflection step needs enough detail to figure out what went wrong.

The self-reflection module is an LLM prompted to read the trajectory plus the evaluator signal and produce a short reflection. The prompt typically looks like: 'You attempted this task. Here is what you tried. Here is the result. In two to four sentences, explain what went wrong and what you would do differently next time.' The output is plain text, no special structure.

The episodic memory store is a key-value store of reflections, keyed by task type or task signature. On the next attempt, the relevant reflections are retrieved and prepended to the actor's prompt as context. Selective retrieval is essential; dumping every past reflection into context floods the prompt and surfaces irrelevant lessons.

The outer loop in motion
Why no weights change, and why that matters
Failure modes and how to defend against them
Where Reflexion fits in 2026
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Cursor and Cline coding agents store a per-task scratchpad of what they tried; on a failed test, the next iteration reads the scratchpad to avoid repeating the mistake.
  • Anthropic claude-code uses a Reflexion-style outer loop when running a long refactor: failed test output becomes a reflection that informs the next edit attempt.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow does Reflexion differ from self-refine, in one sentence?
A

Self-refine critiques and rewrites the model's own draft answer in a single attempt, with no external observations. Reflexion learns across attempts by storing a reflection in episodic memory and feeding it back on the next try.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Calling Reflexion a fine-tuning method or a weight update. The whole point is that no weights change; the learning lives in a self-written reflection that is fed back as in-context input.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • State that Reflexion is an outer loop on top of an inner agent loop like ReAct.

  • Name the three steps: attempt, reflect on failure, retry with the reflection in context.

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is the Model Context Protocol (MCP) and what problem does it solve?
MCQ·Easy