Skip to content

Latest commit

 

History

History
69 lines (47 loc) · 2.76 KB

File metadata and controls

69 lines (47 loc) · 2.76 KB

reflection

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

Table of Contents

The Simple Idea

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

How Reflection Works

  1. Failure Observation: The runtime returns execution error output (e.g. undefined: compiler.BytecodeVersion).
  2. Causal Analysis: The model inspects the error trace back to find the root cause.
  3. Plan Revision: The model updates its working plan before making further code edits.

Reflection Patterns

  • 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.

Reflection vs Trial-and-Error

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

My Learning Notes

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

Common Misunderstandings

"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.

Related Concepts

Previous: agentic-security
Next: hallucination-mitigation
Related: loop-engineering, agentic-workflow