Day 9: Santa’s Self-Reflecting Gift Agent ๐
Elf Pash at the North Pole has a challenge. Every year, Santa needs to process millions of gift requests and optimize his gift selections based on children’s wishlists and budget constraints. Other elves often ask questions like “What gifts should we get for a 9-year-old who loves science?” or “How can we maximize joy while staying within budget?” ๐
This year, elf Pash has an idea to solve this: create a self-reflecting agent that can optimize gift selections automatically! As he experiments with LLMs, he realizes that simple gift suggestions aren’t enough - the agent needs to reflect on its choices to ensure they’re optimal. Being a Haystack elf, Pash knows how to solve this: SELF-REFLECTION! ๐ญ
So, he comes up with a plan. Santa will create a gift recommendation system using Haystack’s RAG pipeline with MongoDB Atlas vector search, enhanced with a self-reflecting component that optimizes gift selections based on budget, age appropriateness, and joy factor! โจ
For this challenge, you must help elf Pash create a pipeline that can suggest and optimize gift selections through self-reflection.
- Implement a self-reflecting agent that can optimize gift selections
- Use MongoDB Atlas vector search for semantic gift matching
- Include price, age range, and category in gift considerations
- Ensure all suggestions stay within the specified budget
๐ฏ Requirements:
- To use the default embedding and text generation models in this notebook, you’ll need an OpenAI API Key. Alternatively, you can replace these models with others that better suit your needs.
-
MongoDB Atlas project with an Atlas cluster (free tier works). Create your cluster, take a note of your
connection string and have
0.0.0.0/0
address in your network access list. Visit detailed tutorial for step by step guide.
๐ Some Hints:
- Include gift metadata in embeddings with
meta_fields_to_embed
of your document embedder- Create a custom component for gift optimization checks, you have seen this in day 3
- Use the
max_runs_per_component
parameter in Pipeline for controlled self-reflection- Enable Real-Time Pipeline Logging to inspect the data that’s flowing through your agentic pipeline
- Check our DeepLearning.AI course Building AI Applications with Haystack or Web-Enhanced Self-Reflecting Agent for similar examples
๐ Here is the Starter Colab