Reflexión de agentes y ciclos de autocorrección
Haga más inteligentes sus agentes permitiéndoles criticar y revisar su propio trabajo. Aprenda el patrón de reflexión, cuándo utilizarlo y cómo acotarlo para producción.
Reflexión de agentes y ciclos de autocorrección es una lección gratuita de Prompt Engineering & LLM Optimization for Developers en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Prompt Engineering & LLM Optimization for Developers, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Prompt Engineering & LLM Optimization for Developers incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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.
Preguntas frecuentes
¿La lección «Reflexión de agentes y ciclos de autocorrección» es gratis?
Sí — el texto completo de «Reflexión de agentes y ciclos de autocorrección» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Prompt Engineering & LLM Optimization for Developers, actualiza a CoddyKit PRO. El curso de Prompt Engineering & LLM Optimization for Developers incluye 4 lecciones en total.
¿Qué aprenderé en «Reflexión de agentes y ciclos de autocorrección»?
Haga más inteligentes sus agentes permitiéndoles criticar y revisar su propio trabajo. Aprenda el patrón de reflexión, cuándo utilizarlo y cómo acotarlo para producción. Practicas Prompt Engineering & LLM Optimization for Developers con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Prompt Engineering & LLM Optimization for Developers?
No se requiere experiencia previa. Prompt Engineering & LLM Optimization for Developers en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Reflexión de agentes y ciclos de autocorrección»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Prompt Engineering & LLM Optimization for Developers?
Sí. Cada lección de Prompt Engineering & LLM Optimization for Developers incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Diseño de sistemas multiagente
- Gestión de memoria y estado para agentes
- Automatización autónoma de flujos de trabajo
- Reflexión de agentes y ciclos de autocorrección