| name | reflexion |
| description | After a failed attempt (test fails, command errors, wrong output), write a short reflection on WHY it failed and what to change, then retry with that lesson in context, instead of blindly trying again. Use on the 2nd attempt at any failing task. Trigger with /reflexion or "that failed, rethink", "why did it fail", "learn from this and retry". |
| version | 0.1.0 |
| user-invocable | true |
| metadata | {"emoji":"🔁"} |
reflexion
Blind retry repeats the same mistake. After a failure, turn the failure signal into a written lesson, then retry WITH that lesson in front of you. Verbal self-reflection as memory between attempts.
Why this exists (evidence)
- Reflexion (Shinn et al., arXiv:2303.11366): agents that verbally reflect on failure feedback and keep it as episodic memory across attempts get large gains, e.g. up to 91% pass@1 on HumanEval vs 80% for the prior best at the time, and big jumps on decision-making/reasoning tasks, without finetuning.
- Mechanism: the failure (stack trace, failed test, wrong result) is signal; a concrete "what went wrong + what to change" note steers the next attempt instead of resampling the same path.
When to use
- The 2nd (and later) attempt at any task that just failed: failing test, runtime error, wrong answer, rejected approach.
- A loop that is about to retry: insert a reflection step first.
- NOT on the first attempt (nothing to reflect on yet) and not when the fix is obvious (just fix it).
The loop
- Capture the failure precisely: exact error / failing assertion / wrong output. Quote it, do not paraphrase.
- Reflect (short, concrete): WHY did it fail? What specific assumption was wrong? What is the ONE change that addresses the root cause (not the symptom)?
- Record the lesson as a one-line note kept in context (e.g. "the API returns cents not dollars -> divide by 100").
- Retry with the lesson explicit. Change the approach the lesson implies, do not just rerun.
- If it fails again: add a new lesson; after 2-3 failed reflections on the same root, STOP and escalate (you are stuck in a local minimum) rather than looping.
Persist across sessions
For recurring failures, write the lesson to memory (see recall / memory-persistence) so a future session does not relearn it. That is the "episodic memory" part of Reflexion.
Composes with
systematic-debugging: reflexion is the between-attempts memory; debugging is the within-attempt method.
testsmith / adversarial-verify: produce the failure signal reflexion learns from.
self-consistency: when reflection is uncertain, sample a few candidate root causes and take the consistent one.
Honest limits
- Garbage reflection = garbage retry. The lesson must name a ROOT cause, not "try harder".
- Cap the loop (2-3 reflections); reflexion does not rescue a fundamentally wrong approach, it just stops you repeating one mistake.
- Reported numbers are from the paper's benchmarks; measure your own.