Reflection agents
Reflection is a simple but powerful technique for improving the quality of LLM responses by prompting the LLM to reflect on its own output to identify gaps or possibilities for improvement.
Reflection agents
Reflection is a prompting strategy used in agent workflows to iteratively improve an LLM’s reasoning or outputs. Instead of directly returning a final answer, the LLM is first prompted to reflect on its initial response and identify errors, gaps, or opportunities for improvement. It then uses this feedback to generate a revised response. This can be repeated multiple times until some stopping condition is met (e.g., max iterations, token limit, or some evaluation criteria).
This process has been shown to improve performance over direct response generation on a variety of tasks. Some agents add an explicit evaluation step which is called prior to reflection. Evaluation can be done via an LLM judge, external tools (e.g., a code compiler or a knowledge base) or other methods (e.g., heuristic score). Reflection can be used in combination with other agent design patterns such as the ReAct framework.
Further reading
Reflexion: Language Agents with Verbal Reinforcement Learning by Shinn et al. — A seminal paper on reflection which used separate evaluation and reflection modules. This paper is a great read if you want to understand reflection more in depth. The appendix includes the prompts the authors used in their experiments.
If you want to try running a reflection agent yourself, both LangChain and LlamaIndex include different variations of reflection agents.
Agents by Chip Huyen — this fantastic blog post covers much more than just Reflection, but if you are looking to understand agents and where Reflection fits in, this is a great place to start.
Do you want to learn more NLP concepts?
Each week I pick one core NLP concept and create a one-slide, one-minute explanation of the concept. To receive weekly new posts in your inbox, subscribe here:
Reach out to me:
Connect with me on LinkedIn
Read my technical blog on Medium
Or send me a message by responding to this post
Is there a concept you would like me to cover in a future issue? Let me know!