Lesson 06.06 · Phase 06 · Planning & Reasoning
Reflexion: learning from failures
Try, get a verdict from something outside the model, write down what to do differently, and try again with every lesson written so far. Retrying with only the latest error forgets the earlier ones.
Learning objectives
- Implement the Reflexion loop: attempt, external evaluation, verbal reflection, and an attempt that sees all reflections so far.
- Evaluate generated code safely: a separate interpreter with isolation flags and a timeout, never exec in the agent's own process.
- Compare one attempt, retry-with-latest-error, and Reflexion, and explain why retry oscillates.
- Distinguish Reflexion (within one task) from episodic memory (across tasks, Phase 4 · Lesson 6).
An agent writes parseduration("1h30m"). Unit tests say it fails on minutes, on spaces, and on invalid input. The obvious loop is "show it the error and retry". It fixes minutes. The next run fails on invalid input; it fixes that, and forgets minutes, because the prompt now only mentions invalid input. Two steps forward, one back.
Loading the full lesson…