Last week, I described four design patterns for AI agentic workflows that I believe will drive significant progress this year: Reflection, Tool use, Planning and Multi-agent collaboration. Instead of having an LLM generate its final output directly, an agentic workflow prompts the LLM multiple times, giving it opportunities to build step by step to higher-quality output. Here, I'd like to discuss Reflection. For a design pattern that’s relatively quick to implement, I've seen it lead to surprising performance gains.
You may have had the experience of prompting ChatGPT/Claude/Gemini, receiving unsatisfactory output, delivering critical feedback to help the LLM improve its response, and then getting a better response. What if you automate the step of delivering critical feedback, so the model automatically criticizes its own output and improves its response? This is the crux of Reflection.
Take the task of asking an LLM to write code. We can prompt it to generate the desired code directly to carry out some task X. After that, we can prompt it to reflect on its own output, perhaps as follows:
Here’s code intended for task X:
[previously generated code]
Check the code carefully for correctness, style, and efficiency, and give constructive criticism for how to improve it.
Sometimes this causes the LLM to spot problems and come up with constructive suggestions. Next, we can prompt the LLM with context including (i) the previously generated code and (ii) the constructive feedback, and ask it to use the feedback to rewrite the code. This can lead to a better response. Repeating the criticism/rewrite process might yield further improvements. This self-reflection process allows the LLM to spot gaps and improve its output on a variety of tasks including producing code, writing text, and answering questions.
And we can go beyond self-reflection by giving the LLM tools that help evaluate its output; for example, running its code through a few unit tests to check whether it generates correct results on test cases or searching the web to double-check text output. Then it can reflect on any errors it found and come up with ideas for improvement.
Further, we can implement Reflection using a multi-agent framework. I've found it convenient to create two different agents, one prompted to generate good outputs and the other prompted to give constructive criticism of the first agent's output. The resulting discussion between the two agents leads to improved responses.
Reflection is a relatively basic type of agentic workflow, but I've been delighted by how much it improved my applications’ results in a few cases. I hope you will try it in your own work. If you’re interested in learning more about reflection, I recommend these papers:
- Self-Refine: Iterative Refinement with Self-Feedback, by Madaan et al. (2023)
- Reflexion: Language Agents with Verbal Reinforcement Learning, by Shinn et al. (2023)
- CRITIC: Large Language Models Can Self-Correct with Tool-Interactive Critiquing, by Gou et al. (2024)
I’ll discuss the other agentic design patterns as well in the future.
[Original text: https://t.co/FtM2zOT2Lx ]
🏆 Celebrating Claudia Goldin🌟We applaud Harvard's Prof Goldin, the 3rd woman to win the Nobel Prize in Economic Sciences! Her groundbreaking research on gendered wage inequality reshaped our understanding of the gender pay gap. Brava! 👏👩🔬
https://t.co/o8D9fEBi2I
Join us from Oct 3-6 to connect with @nvidiaeu@nvidiaaidev experts for a FREE Developer Days event where knowledge meets recognition - attend just 3 sessions to earn your certificate of attendance! 🤩
🔥 Don't miss out on this experience & register here: https://t.co/qkMFBZdKpw
@apyacc This is really amazing work, may 2023 brings happiness, good health and wonderful event!!
We are working on AI + Art project, can you kindly email me to [email protected] pls
@TobyWalsh The focus on text generation rather than 'understanding' results in the only applications LLMs can do at scale. Next generation will have 'understanding' but it's a new paradigm. @jbthinking has an interactive session Tuesday 9am Sydney time https://t.co/SbCZ9CuuSd #voicefirst
#Limitless has won Silver in the @GlobalGoodAward!
Fantastic recognition of its positive impact on communities worldwide, driving innovation for the collective good: https://t.co/54oFQ8TwT5
Well done @ActionLabMonash and @IFRCInnovation!
@MonashUni
My manager is from Iran. What he described happens to girls that don’t comply with a “dress code” is a human rights crisis. I stand with you all. I stand with the youth. #OpIran
“This promises to bring people together by enabling machines to interact with us in our native language, whichever that is” — @jbthinking https://t.co/1es2JEhNuH #voicefirst
So Facebook is deleting one billion facial recognition scans, but it's keeping DeepFace, the model that is trained on all those faces. Note that "the company has also not ruled out incorporating facial recognition into future products." Very meta. 👀