Reflexion: Verbal Reinforcement Learning

Gradient-based RL needs thousands of trials and a GPU cluster to fix a failure mode. Reflexion (Shinn et al., NeurIPS 2023) does it in natural language: after each failed trial, the agent writes a reflection, stores it in episodic memory, and conditions the next trial on that memory. This is the pattern behind Letta's sleep-time compute, Claude Code's CLAUDE.md learnings, and pro-workflow's learn-rule.

Build 1 hr Python (stdlib)

Prerequisites: Phase 14 · 01 (Agent Loop), Phase 14 · 02 (ReWOO)

#Learning Objectives

  • Name the three components of Reflexion (Actor, Evaluator, Self-Reflector) and the role of episodic memory.
  • Implement a stdlib Reflexion loop with binary evaluator, reflection buffer, and fresh re-attempts.
  • Choose between scalar, heuristic, and self-evaluated feedback sources for a given task.
  • Explain why verbal reinforcement catches errors that gradient-based RL would need thousands of trials to fix.
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.