Llama-Index/AgentWorkflow: Build Reflection Enabled Agentic
By using Llama-Index’s AgentWorkflow, we can create an agent that also contains reflection or critique, where critique can be understood as a reviewer.
We can also use the LlamaIndex to build a similar reflection-enabled agent; this text follows up on the last one.
Use-Case
Execution
ReActAgent or FunctionAgent
Source
Flow example
Report example
Ref.
Use-Case
Execution
In order to run, I use the Gemini 1.5, 2.0 model at the moment. Remember to add the key in your environment.
os.environ[“GOOGLE_API_KEY”] = os.getenv(“GEMINI_API_KEY”)
For some unknown reason, when I use Gemini 2.0 as a regressor, it is sometimes very unstable, resulting in the model returning “empty” results and it seems that LlamaIndex did not address this issue; I had related discussions in this forum. https://github.com/run-llama/llama_index/discussions/17931
But anyway, my configuration is as follows:
regressor: 2.0flash
critic:2.0 flash
reportor 1.5 flash
The temperature of the regressor is very low, mainly because I want to find past online messages in an “honest” and “stable” way. I set the report to 0 to reduce structural uncertainty in the report. As for the issue of the critic being relatively high, it is to allow it to “actively and intelligently” prompt the regressor.
ReActAgent or FunctionAgent
This is a very puzzling choice for me within the LlamaIndex framework. According to many documents and forum conclusions, the former is more flexible while the latter is more functional. Ultimately, my conclusion is that for complex logical conditions, such as switching agents, the ReActAgent clearly performs much better. In this case, the report is a single function without any complex logic, so it should naturally be the latter.
In this case, the interaction between the FunctionAgent, regressor, and critic is disastrous.
Source
Flow example
2025-02-28 18:54:42.257 | INFO | __main__:web_search:78 - 🔍 Searching on web:
MacBook Pro Max (M4) price trends Germany 2022 2023 2024
2025-02-28 18:54:46.971 | INFO | __main__:web_search:78 - 🔍 Searching on web:
MacBook Pro price history Germany seasonal discounts
2025-02-28 18:54:54.816 | INFO | __main__:web_search:78 - 🔍 Searching on web:
MacBook Pro Max (M4) price Germany
2025-02-28 18:55:02.865 | DEBUG | __main__:post_regression:145 - 📈 0. Goal: To determine the optimal time to purchase a MacBook Pro Max (M4) in 2025 in Germany, considering price trends, seasonal discounts, and expected pricing.
1. Purchase Timing & Seasonal Adjustments:
* Best time: Likely during the "Back to School" season (August/September) or Black Friday (November). These periods often see discounts on MacBooks.
* Consider: Monitoring prices starting in late summer 2025 to identify potential deals.
* Trend: Based on the limited data, prices may stabilize or slightly decrease throughout the year after the initial release.
2. Expected Price:
* Current starting price (Feb 2025): €4,099 for the base 16-inch MacBook Pro Max (M4).
* Estimate for MacBook Pro Max (M4) in 2025: Expect a potential discount of €100-€300 during sales events.
3. Minimum Configuration:
* To determine the minimum configuration, I need to know the user's intended use. However, I can assume a "Max" version implies professional use.
* Likely minimum: M4 Max chip with 32GB of RAM and 1TB SSD. This will provide sufficient power and storage for demanding tasks. 48GB is preferable if budget allows.
4. Conclusion and Recommendations:
* The best time to buy the MacBook Pro Max (M4) in 2025 in Germany is likely during seasonal sales events like "Back to School" (August/September) or Black Friday (November).
* Monitor prices closely leading up to these events.
* Opt for at least 32GB of RAM and 1TB SSD for professional use. Consider 48GB if your budget allows for future-proofing. 📉
2025-02-28 18:55:15.357 | DEBUG | __main__:post_critic:127 - The AI provided a well-structured and informative response. However, the price estimate could be more precise, and the analysis could benefit from a deeper exploration of historical price trends (even for previous models). I recommend focusing on providing a more precise price estimate (e.g., percentage-based discount range) and acknowledging the uncertainty of future price trends.
2025-02-28 18:55:15.357 | DEBUG | __main__:post_critic:128 - 🧐 Critic step: {'critic_steps': 0}
2025-02-28 18:55:15.357 | DEBUG | __main__:post_critic:133 - 😉 Critic step updated: {'critic_steps': 1, 'reflection': 'The AI provided a well-structured and informative response. However, the price estimate could be more precise, and the analysis could benefit from a deeper exploration of historical price trends (even for previous models). I recommend focusing on providing a more precise price estimate (e.g., percentage-based discount range) and acknowledging the uncertainty of future price trends.'}
2025-02-28 18:55:15.357 | DEBUG | __main__:post_critic:137 - 👌 Critic done: 1
2025-02-28 18:55:21.509 | DEBUG | __main__:post_reworking:153 - 👍👎 List of the reworking content:
- Revised Price Estimate: Change the price estimate to a percentage-based discount range.
- Added Disclaimer: Include a disclaimer about the uncertainty of future price trends.
The CriticAgent suggested originally: The AI provided a well-structured and informative response. However, the price estimate could be more precise, and the analysis could benefit from a deeper exploration of historical price trends (even for previous models). I recommend focusing on providing a more precise price estimate (e.g., percentage-based discount range) and acknowledging the uncertainty of future price trends.
2025-02-28 18:55:30.158 | DEBUG | __main__:post_critic:127 - The AI provided an excellent and comprehensive response. No further improvements are necessary at this time.
2025-02-28 18:55:30.158 | DEBUG | __main__:post_critic:128 - 🧐 Critic step: {'critic_steps': 1, 'reflection': 'The AI provided a well-structured and informative response. However, the price estimate could be more precise, and the analysis could benefit from a deeper exploration of historical price trends (even for previous models). I recommend focusing on providing a more precise price estimate (e.g., percentage-based discount range) and acknowledging the uncertainty of future price trends.'}
2025-02-28 18:55:30.158 | DEBUG | __main__:post_critic:133 - 😉 Critic step updated: {'critic_steps': 2, 'reflection': 'The AI provided an excellent and comprehensive response. No further improvements are necessary at this time.'}
2025-02-28 18:55:30.158 | DEBUG | __main__:post_critic:137 - 👌 Critic done: 2
Report example
It can be different every time, relying on the model’s random creativity.
Ref.
•Agents: https://ppc.land/content/files/2025/01/Newwhitepaper_Agents2.pdf
•Building Effective Agents: https://www.anthropic.com/research/building-effective-agents
•AGENTIC RETRIEVAL-AUGMENTED GENERATION: A SURVEY ON AGENTIC RAG https://arxiv.org/pdf/2501.09136