---
title: "Teaching AI Agents to Catch Their Own Mistakes: Reflection vs. Reflexion"
url: https://shakeebkhan.com/reflexion-agent-pattern/
type: post
date: 2026-09-29
modified: 2026-09-29
markdown_url: https://shakeebkhan.com/reflexion-agent-pattern.md
author: "Shakeeb Khan"
---

# Teaching AI Agents to Catch Their Own Mistakes: Reflection vs. Reflexion

Ever watched an AI agent fail at a task, then turn around and fail at the exact same task the exact same way? I have, more times than I'd like to admit. You re-run the prompt, cross your fingers, and — nothing changes. The agent has no idea it screwed up last time, because it never actually "knew" in the first place.

That's the gap the **Reflexion agent pattern** (and its simpler cousin, basic Reflection) is trying to close. And once you see it, you can't unsee it: most AI agents today are running on pure instinct. They read a prompt, generate a response, and move on. No pause, no second-guessing, no "wait, did that actually work?" It's the AI equivalent of talking before you think.

![AI agent thought process flowchart showing perception reasoning planning act evaluate reflect learning loop on black background](https://shakeebkhan.com/wp-content/uploads/2026/09/image_20260929_091013-1024x576.jpg)

## The problem with instinct-only agents

Researchers sometimes describe this as the difference between System 1 and System 2 thinking — fast, reactive gut reactions versus slower, deliberate reasoning. Left on their own, large language models default to System 1. They're great at producing a plausible-sounding answer on the first try, but they have no built-in habit of checking their own work.

For simple tasks, that's fine. But the moment you ask an agent to write working code, plan a multi-step task, or answer something that requires real precision, "good enough on the first attempt" starts to fall apart. So how do you get an agent to slow down and actually evaluate itself? That's where the Reflection and Reflexion agent patterns come in.

## Reflection: the basic version

The simplest form of this is called Reflection, and it's refreshingly straightforward. You run two LLM calls instead of one. The first call, the "generator," attempts the task like normal. The second call, the "reflector," is prompted to act like a critical teacher looking over the generator's shoulder — pointing out what's weak, what's missing, what could be tightened up. LangChain has a [good writeup on basic reflection agents](https://www.langchain.com/blog/reflection-agents#basic-reflection) if you want to see the pattern laid out step by step.

You feed that critique back into the generator, let it try again, and repeat for a fixed number of rounds. It's a cheap way to get a second opinion baked into the process. The catch? The critic is still just another LLM call with no access to ground truth. It's judging the answer based on vibes, not verified facts. So the improvement from round to round tends to be modest.

## The Reflexion Agent Pattern: Reflection With Receipts

The Reflexion agent pattern takes the same core idea and gives it something to actually check against. Instead of one model critiquing another model's guess, you get a proper three-part loop, nicely broken down in this [agent-patterns documentation](https://agent-patterns.readthedocs.io/en/stable/patterns/reflexion.html):

An **Actor** attempts the task. An **Evaluator** scores whether it actually succeeded — using something concrete like a unit test, an exact match, or a defined heuristic, not just a feeling. And a **Self-Reflection** step turns that failure signal into a specific, written note: "I got this wrong because X, next time I should try Y."

Here's the part I find genuinely clever: that note gets stored in memory and carried into the next attempt. No weights get updated, no fine-tuning happens. The agent is learning the same way you'd jot something in a notebook after a mistake, so you don't make it again tomorrow. It's learning in plain language, not in gradients.

Researchers first formalized the Reflexion agent pattern in a [2023 paper by Shinn et al.](https://arxiv.org/pdf/2303.11366), and it works better than you'd expect. In their experiments, this approach pushed household task completion up by 22% over the baseline, boosted multi-hop question answering by 20%, and on a coding benchmark it hit a 91% pass rate — beating GPT-4's own unguided score of 80% on the same test. Code generation in particular is a great fit here, because you get a free, objective evaluator for almost nothing: just run the code and see if the tests pass.

## Why this matters if you're building agents

If you're building anything with LangGraph or a similar framework, the Reflexion agent pattern is worth having in your back pocket. You don't need a fancy setup to get value from it. Even a simple version — generate, evaluate against something concrete, reflect in plain text, retry — can meaningfully cut down on repeated mistakes, especially for tasks like generating code, filling out structured data, or multi-step planning where "close enough" isn't actually close enough.

The honest caveat: this only pays off when you have a real way to evaluate success. Vague, subjective tasks don't give the Evaluator much to work with, and you end up back at basic Reflection's problem — critique without grounding. So before you reach for the Reflexion agent pattern, ask yourself what your "unit test" actually is. If you can answer that clearly, you're most of the way there already. It's the same instinct I wrote about in [what actually makes a company AI-native](https://shakeebkhan.com/what-does-ai-native-actually-mean-my-answer-after-someone-asked-me-at-a-meetup/) — it's never the model alone, it's the feedback loop you build around it.

I'll probably dig into an actual LangGraph implementation of the Reflexion agent pattern in a future post, complete with the retry loop and memory wiring. For now, next time your agent flubs a task, ask yourself: does it even know it failed? If not, that's your starting point.

Happy building, and may your agents actually learn from their mistakes.
