智能体反思与自我纠正循环
让智能体批评并修改自己的工作,从而变得更加智能。学习反思模式、适用场景,以及如何在生产环境中限制其运行范围。
智能体反思与自我纠正循环 是 CoddyKit 上的免费 Prompt Engineering & LLM Optimization for Developers 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 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.
常见问题解答
「智能体反思与自我纠正循环」课时是免费的吗?
是的 — 「智能体反思与自我纠正循环」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Prompt Engineering & LLM Optimization for Developers 课程的其余内容,请升级到 CoddyKit PRO。 Prompt Engineering & LLM Optimization for Developers 课程共包含 4 节课。
「智能体反思与自我纠正循环」这节课中我会学到什么?
让智能体批评并修改自己的工作,从而变得更加智能。学习反思模式、适用场景,以及如何在生产环境中限制其运行范围。 你通过在浏览器中直接运行的动手代码来练习 Prompt Engineering & LLM Optimization for Developers,全天候 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 反馈 — 无需本地设置。
此课程中的所有课时
- 设计多智能体系统
- 智能体的记忆与状态管理
- 自主工作流自动化
- 智能体反思与自我纠正循环