A beginner-friendly guide to Reflection and Self-Correction in agentic AI systems.
reflection is the process where an agent inspects its own execution history, identifies errors or inefficiencies, and revises its strategy before taking the next step
- The Simple Idea
- How Reflection Works
- Reflection Patterns
- Reflection vs Trial-and-Error
- My Learning Notes
- Common Misunderstandings
- Related Concepts
Without reflection, an agent that encounters an error (e.g., a broken build) blindly retries the exact same command or makes random edits.
Reflection forces a pause in the loop: the agent analyzes the exact error log, identifies why its hypothesis failed, and formulates a revised plan.
Tool Failure -> Reflection Step ("Why did this fail?") -> Revised Hypothesis -> Corrective Action
- Failure Observation: The runtime returns execution error output (e.g.
undefined: compiler.BytecodeVersion). - Causal Analysis: The model inspects the error trace back to find the root cause.
- Plan Revision: The model updates its working plan before making further code edits.
- Self-Critique: Reviewing generated code against repository style guidelines before running build commands.
- Post-Execution Review: Evaluating tool step efficiency after subtask completion.
- Verbal Reinforcement Learning: Recording key learnings into working memory to avoid repeating past mistakes within the same session.
| Dimension | Trial-and-Error | Reflection & Self-Correction |
|---|---|---|
| Action Generation | Reactive / Blind retries | Deliberate hypothesis revision |
| Log Inspection | Skimmed / Ignored | Full root-cause analysis |
| Step Efficiency | High step count | Low step count |
| Success Rate | Low | High |
In coding agents, jumping straight to file edits without reading full error traces causes endless retries.
Reflection rule:
inspect complete error logs and justify the root cause before mutating code
"Reflection requires a separate model."
No. Reflection can be performed by the same model by structuring an explicit self-critique prompt step in the execution loop.
Previous: agentic-security
Next: hallucination-mitigation
Related: loop-engineering, agentic-workflow