1:1 mentoring with Big Tech AI engineers
LLM & Agentic

Reflexion

Reflexion pattern for self-improving AI agents: verbal reinforcement learning where agents turn failures into written lessons and retry — no gradients required.

Last updated

Core6 min readFirst readReAct Pattern

After this section you can

  • Distinguish the two different patterns that both get called Reflexion
  • Implement the episode loop with an evaluator and a written lesson carried into the retry
  • Decide when the retry budget pays for itself and when it just multiplies cost
14

Reflexion: Agents That Learn from Mistakes

Verbal reinforcement learning: the agent fails, writes itself a lesson, and retries with that lesson in context. No gradients, no fine-tuning — learning that happens in plain text, within a session.

THE CENTRAL IDEA

Reinforcement learning improves a policy by turning failures into weight updates. Reflexion (Shinn et al., NeurIPS 2023) does the same thing without touching a single weight: when an attempt fails, a reflection step writes a short natural-language lesson — “I assumed the list was sorted; it isn’t; sort before binary search” — stores it in an episodic memory buffer, and injects it into the context of the next attempt. The feedback signal becomes words instead of gradients. With GPT-4 as the actor, this loop hit 91% pass@1 on HumanEval, beating the same model’s 80% baseline — an 11-point gain purchased entirely with retries and text.

The Reflexion loop — actor, evaluator, self-reflection, memory
ACTOR ReAct-style agent attempt N → trajectory EVALUATOR tests · exact match · judge SHIP IT passed the checks pass SELF-REFLECTION “what went wrong, and what will I do differently?” fail + error signal EPISODIC MEMORY lessons from attempts 1..N plain text, capped list lesson injected into attempt N+1 no gradients anywhere — the “policy update” is a sentence in the prompt

Related

More in LLM & Agentic

Get full access to all 74+ sections with code examples, diagrams, and interactive animations.

Unlock Premium