エージェントのリフレクションと自己修正ループ
エージェント自身に作業を批評・修正させて、より賢くします。リフレクションパターンの使い方、適用場面、本番環境での制限方法を学びます。
「エージェントのリフレクションと自己修正ループ」はCoddyKit上の無料Prompt Engineering & LLM Optimization for Developersレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはPrompt Engineering & LLM Optimization for Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Prompt Engineering & LLM Optimization for Developersコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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.
よくある質問
「エージェントのリフレクションと自己修正ループ」レッスンは無料ですか?
はい。「エージェントのリフレクションと自己修正ループ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Prompt Engineering & LLM Optimization for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Prompt Engineering & LLM Optimization for Developersコースには全4レッスンが含まれています。
「エージェントのリフレクションと自己修正ループ」で何を学びますか?
エージェント自身に作業を批評・修正させて、より賢くします。リフレクションパターンの使い方、適用場面、本番環境での制限方法を学びます。 ブラウザで直接実行するハンズオンコードでPrompt Engineering & LLM Optimization for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Prompt Engineering & LLM Optimization for Developersを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのPrompt Engineering & LLM Optimization for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「エージェントのリフレクションと自己修正ループ」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このPrompt Engineering & LLM Optimization for Developersレッスンでコードを書いて実行できますか?
はい。すべてのPrompt Engineering & LLM Optimization for Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- マルチエージェントシステムの設計
- エージェントのメモリと状態管理
- 自律型ワークフローの自動化
- エージェントのリフレクションと自己修正ループ