0Pricing
Prompt Engineering & LLM Optimization for Developers · Lesson

Agent Reflection & Self-Correction Loops

Make agents smarter by letting them critique and revise their own work. Learn the reflection pattern, when to use it, and how to bound it for production.

Agent Reflection & Self-Correction Loops is a free Prompt Engineering & LLM Optimization for Developers lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Prompt Engineering & LLM Optimization for Developers learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What is Reflection?

Reflection is an agent pattern where the model reviews its own output, identifies flaws, and produces an improved version — without a human in the loop.

It turns a one-shot answer into an iterative draft-then-revise process.

The Generator-Critic Pattern

Two roles drive reflection:

  • Generator: produces a candidate answer
  • Critic: evaluates it against criteria and suggests fixes

They can be the same model with different prompts.

A Basic Reflection Loop

Generate, critique, then regenerate using the critique. Repeat until the critic is satisfied or a limit is hit.

let draft = generate(task);
for (let i = 0; i < maxIters; i++) {
  const fb = critique(task, draft);
  if (fb.ok) break;
  draft = revise(task, draft, fb.notes);
}

Writing the Critic Prompt

A good critic is specific. Give it explicit checklist criteria so feedback is actionable rather than vague praise.

Review the answer for:
1. Correctness
2. Completeness
3. Following the format spec
List concrete problems, or reply DONE.

Reflexion with Memory

The Reflexion technique stores past mistakes as text memory. The agent reads its prior reflections before the next attempt, so it does not repeat errors.

Tool-Grounded Reflection

Reflection is far stronger when the critic can run tests, compile code, or query data — replacing opinion with evidence.

const result = runTests(draft);
if (!result.passed) {
  draft = revise(task, draft, result.failures);
}

Bounding the Loop

Unbounded reflection can loop forever or burn tokens. Always cap iterations and add an early exit when the critic approves.

const MAX_ITERS = 3;
let iters = 0;
while (!approved && iters++ < MAX_ITERS) { /* ... */ }

Diminishing Returns

Quality usually plateaus after 2-3 cycles. Track whether each revision actually improves a measurable score; stop reflecting once gains stall.

Cost vs Quality

Each reflection cycle is extra LLM calls. Reserve reflection for high-value or error-prone tasks (code, planning) and skip it for simple ones.

Avoiding Self-Reinforcing Errors

A model can confidently approve its own wrong answer. Use a different model or external tools as the critic when correctness is critical.

Combining with Planning

In a larger agent, reflection sits after each major step: act, observe, reflect, adjust the plan. This makes long autonomous workflows far more robust.

Quick Check

Test your understanding.

Recap

You learned the reflection pattern: a generator-critic loop where the agent critiques and revises its own work. Use specific critic criteria, ground critiques in tools, store reflections as memory, bound iterations, and use an independent critic for high-stakes correctness.

Frequently asked questions

Is the “Agent Reflection & Self-Correction Loops” lesson free?

Yes — the full text of “Agent Reflection & Self-Correction Loops” is free to read here on the web, and the Prompt Engineering & LLM Optimization for Developers course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Prompt Engineering & LLM Optimization for Developers course, upgrade to CoddyKit PRO.

What will I learn in “Agent Reflection & Self-Correction Loops”?

Make agents smarter by letting them critique and revise their own work. Learn the reflection pattern, when to use it, and how to bound it for production. You practise Prompt Engineering & LLM Optimization for Developers with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Prompt Engineering & LLM Optimization for Developers?

No prior experience is required. Prompt Engineering & LLM Optimization for Developers on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Agent Reflection & Self-Correction Loops” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Prompt Engineering & LLM Optimization for Developers lesson?

Yes. Every Prompt Engineering & LLM Optimization for Developers lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Designing Multi-Agent Systems
  2. Memory & State Management for Agents
  3. Autonomous Workflow Automation
  4. Agent Reflection & Self-Correction Loops
← Back to Prompt Engineering & LLM Optimization for Developers