Published on 00/00/0000
Last updated on 00/00/0000
Published on 00/00/0000
Last updated on 00/00/0000
Share
Share
INSIGHTS
7 min read
Share
Ah, the holiday season! It’s that delightful time of year when twinkling lights sparkle, warm beverages steam in our mugs, and the quest for the perfect gift begins. For many of us, finding that one-of-a-kind present, something both memorable and meaningful, can feel like a chore. After all, sifting through endless product listings and coping with last-minute gift panic is hardly festive.
But what if you could delegate the entire search process to your team of personal AI holiday shoppers this year instead of stressing? Picture not just one but three helpful, specialized AI agents working behind the scenes, each with their own unique approach:
The enthusiast: A gift-giver who prioritizes excitement and memorable experiences, selecting items that bring a burst of fun and delight into the recipient’s life.
The essentialist: A shopper who focuses on functional, purposeful items that seamlessly fit into daily routines, ensuring each gift is both meaningful and enduring.
The frugalist: A connoisseur of cost-effective choices who carefully curates gifts that maximize value while staying comfortably within budget.
Together, these AI personas will scour the internet, finding unique gift ideas based on their persona type and curating options perfectly aligned with your inputs. Relax, take another sip of hot cocoa, and let this trio of AI shoppers handle the holiday gift-giving.
In this post, we’ll build on the lessons learned in Part 1, where we demonstrated how to leverage AI agents to automate DevOps tasks. We will show you how to create hierarchical multi-agents that use parallel agentic processing to shop and finally use map-reduce patterns to help you find the perfect holiday gift. Let’s get started!
1. Input gathering:
The user provides gift criteria such as the recipient’s interests, budget range, product preferences (e.g., eco-friendly materials), and the maximum number of ideas to generate.
2. Idea generation (Three specialized AI shoppers):
We employ three AI shoppers mentioned above are tasked with generating a set of unique gift ideas. By prompting a large language model (LLM), each shopper agent proposes its original ideas, together forming a diverse pool of gift categories.
3. Market research (Parallel search using SerpAPI):
Next, each idea is used as a query for Google Shopping via SerpAPI, retrieving real-time product information like merchant source, product images, link, and price.
This parallel search ensures that for every idea, we quickly find multiple relevant product options across various retailers.
4. Refinement (Map-reduce):
The recommendation node uses map-reduce patterns to filter products from all three AI shoppers and selects the top number of results specified by the user.
The final outcome is a cohesive, user-ready shortlist of top gift recommendations that blend the creative input of three distinct AI shopper personas with the rich, real-world data sourced from SerpAPI’s Google Shopping results.
Here is the code implementation for building a gift shopper multi-agent application. The application uses LangGraph to manage workflows, an LLM to reason and make decisions, and SerpAPI to query Google Shopping via APIs.
Note: Complete source code, Juypter notebook, and instructions on how to run the following code are available at this GitHub repo
Code Disclaimer: The code provided in this blog is for educational and informational purposes only. While every effort is made to ensure the code is functional and accurate, it is provided "as-is" without any guarantees. Always review and test code in a safe environment before using it in production.
python -m venv venv
source venv/bin/activate
pip install langgraph langchain_openai langchain_core langserve[server] langchain_community google-search-results
# Define AI Shopper Personas
AI_SHOPPER_PERSONAS = Literal["Enthusiast", "Essentialist", "Frugalist"]
# Define Agent State schema
class GiftShopper(BaseModel):
topic: str # Gift Shopping topic
max_ideas: int # Number of ideas to generate
class SearchQuery(BaseModel):
shopper_type: AI_SHOPPER_PERSONAS
search_query: Annotated[str, operator.add]
class Idea(BaseModel):
name: str = Field(
description="Name of the Idea."
)
description: str = Field(
description="Description of the Idea",
)
shopper_type: AI_SHOPPER_PERSONAS = Field(
description="Shopper Type",
)
class IdeaList(BaseModel):
ideas: Annotated[list[Idea], operator.add]
class WebSearchResult(BaseModel):
title: str
link: str
source: str
shopper_type: AI_SHOPPER_PERSONAS
position: int
thumbnail: str
price: str
tag: str
product_link: str
class WebSearchList(BaseModel):
search_results: Annotated[list[WebSearchResult], operator.add]
Note: Code has been edited or removed for brevity. Refer to https://github.com/sriaradhyula/gift-ideas-ai-multi-agent for a complete example.
### Define agent nodes in the state machine
def gift_ideation_router(state: GiftShopper):
logger.debug("Routing gift ideation")
""" Router to select the correct gift ideation node based on the topic """
return state
def gift_shopper(state: GiftShopper, shopper_type: str, instructions: str) -> Command[Literal["scour_the_internet"]]:
....
def gift_shopper_the_enthusiast(state: GiftShopper) -> Command[Literal["scour_the_internet"]]:
instructions = """You are a shopper who prioritizes excitement, joy, and memorable experiences, selecting gifts that bring a burst of fun and delight into the recipient’s life.
Select 3 gift ideas on this topic: {topic}.
"""
return gift_shopper(state, "enthusiast", instructions)
def gift_shopper_the_essentialist(state: GiftShopper) -> Command[Literal["scour_the_internet"]]:
instructions = """You are a shopper who focuses on functional, purposeful items that seamlessly fit into daily routines, ensuring each gift is both meaningful and enduring.
Select {max_ideas} gift ideas on this topic: {topic}.
"""
return gift_shopper(state, "essentialist", instructions)
def gift_shopper_the_frugalist(state: GiftShopper) -> Command[Literal["scour_the_internet"]]:
instructions = """You are a shopper who carefully curates gifts that maximize value while staying firmly within budget. A true connoisseur of cost-effective choices.
Select {max_ideas} gift ideas on this topic: {topic}.
"""
return gift_shopper(state, "frugalist", instructions)
def scour_the_internet(state: IdeaList) -> Command[Literal["web_search_agent"]]:
""" Search query for retrieval """
search_query = f"{idea.name}: {idea.description}"
return Send("web_search_agent", {"shopper_type": idea.shopper_type, "search_query": search_query})
def web_search_agent(state: SearchQuery) -> Command[Literal["final_gift_recommendations"]]:
...
return Command(
goto="final_gift_recommendations",
update={"search_results": all_results}
)
def final_gift_recommendations(state: WebSearchList):
...
with open("gift_recommendations.html", "w") as f:
f.write(html_output)
logger.info("HTML output saved as 'gift_recommendations.html'")
# Add nodes and edges
builder = StateGraph(GiftShopper)
builder.add_node("gift_ideation_router", gift_ideation_router)
builder.add_node("gift_shopper_the_enthusiast", gift_shopper_the_enthusiast)
builder.add_node("gift_shopper_the_essentialist", gift_shopper_the_essentialist)
builder.add_node("gift_shopper_the_frugalist", gift_shopper_the_frugalist)
builder.add_node("scour_the_internet", scour_the_internet)
builder.add_node("web_search_agent", web_search_agent)
builder.add_node("final_gift_recommendations", final_gift_recommendations)
# Logic
builder.add_edge(START, "gift_ideation_router")
builder.add_edge("gift_ideation_router", "gift_shopper_the_enthusiast")
builder.add_edge("gift_ideation_router", "gift_shopper_the_essentialist")
builder.add_edge("gift_ideation_router", "gift_shopper_the_frugalist")
builder.add_edge("final_gift_recommendations", END)
# Compile
graph = builder.compile()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Gift Ideas AI Multi-Agent System")
parser.add_argument("--topic", type=str, required=True, help="Gift Shopping topic")
parser.add_argument("--max_ideas", type=int, required=True, help="Number of ideas to generate")
parser.add_argument("--generate-graph", action="store_true", help="Generate and save the state graph as an image")
args = parser.parse_args()
if args.generate_graph:
create_agent_graph_image()
graph.invoke({"topic": args.topic, "max_ideas": args.max_ideas})
More example queries are shown here https://sriaradhyula.github.io/gift-ideas-ai-multi-agent
Caution: Always verify the URL before clicking to ensure it leads to a trusted source.
We’ve evolved from automating DevOps tasks in Part 1 to orchestrating AI holiday shoppers in a complex, multi-agent workflow. By leveraging hierarchical multi-agents, parallel web searches, and a map-reduce pattern, you can transform tedious gift hunting into a fun, efficient, and personalized process.
So, this holiday season, treat yourself to a bit of AI assistance, sit back, and let the multi-agent shoppers handle the heavy lifting on your quest for the perfect gift!
Get emerging insights on innovative technology straight to your inbox.
Discover how AI assistants can revolutionize your business, from automating routine tasks and improving employee productivity to delivering personalized customer experiences and bridging the AI skills gap.
The Shift is Outshift’s exclusive newsletter.
The latest news and updates on generative AI, quantum computing, and other groundbreaking innovations shaping the future of technology.