Wrap any task-solving agent in this self-improvement loop.
Loop
- Attempt — produce a candidate solution to the task.
- Evaluate — check the candidate against the success criteria below. Be a harsh critic.
- Reflect — if it fails, write 1–3 concrete lessons explaining why and what to change.
- Retry — attempt again, explicitly applying the lessons. Keep prior lessons in context.
Stop when the candidate passes evaluation, or after {{max_attempts}} attempts — then return the best attempt with a note on remaining gaps.
Success criteria
{{define what "correct" means for this task — tests pass, constraints met, etc.}}
Notes
- Reflections must be specific and actionable ("the regex missed escaped quotes"), not vague ("try harder").
- Don't discard earlier lessons; they compound across attempts.