Module 37: Advanced - Building a Personalized Shopping Agent
Theoryโ
Introductionโ
Welcome to Part 7: Capstone Project & Best Practices, and the first of the two capstone-scale projects that close out the course. This is your first real chance to put nearly everything you've learned so far to work in one system: multi-agent orchestration, distributed A2A, state, tools, and multimodal input. In this advanced module, we'll build a sophisticated AI agent capable of navigating a simulated e-commerce website to help a user find and purchase a product. This agent will demonstrate how to integrate external web environments and use a combination of tools to perform complex, multi-step tasks.
Agent Architectureโ
The personalized shopping agent is a distributed multi-agent system composed of three specialized agents communicating via the Agent-to-Agent (A2A) protocol:
- Orchestrator Agent: The main, user-facing agent. It manages the conversation, understands user intent (including multimodal image input), and delegates tasks to the appropriate specialist.
- Personalization Agent: A remote agent responsible for managing user preferences. It uses the ADK's state management features to remember information like preferred sizes, colors, and brands. Known limitation: this persistence works reliably when you call
personalization_agentdirectly, but it does not currently persist across separate turns of theorchestrator_agentin this lab's mandated architecture (AgentToolwrappingRemoteA2aAgent) โ see "Known Limitation: Preferences Don't Persist Across Orchestrator Turns" below. - Web Agent: A remote agent that acts as an interface to the e-commerce website. It exposes
search/clickas plainFunctionTool-wrapped Python functions, abstracting the web environment from the main orchestrator.
Core Componentsโ
-
Web Environment: The agent interacts with a small, self-contained mock catalog (
webshop_data.py) vendored directly in this lab's ownweb_agentproject โ a handful of in-memory products with anid,name,category,price, anddescription, plus a tiny in-process "session" tracking the currently viewed product. This stands in for a real e-commerce backend without requiring any extra install: the realweb_agent_siteGym environment used by Google'spersonalized-shoppingADK sample pulls in a heavyweight dependency chain (pyserini, torch, spacy, a multi-GB product dataset) that's disproportionate to what this lab is teaching, and theweb_agent_sitepackage itself doesn't exist on PyPI โ see the Setup section in the lab for details. -
Tools: The agent is equipped with two primary tools, both plain Python functions wrapped in
FunctionTool:search(keywords: str): Filters the mock catalog by keyword and returns a short text listing of matching products (id, name, price).click(button: str): Simulates clicking a product ID from the search results, or a navigation button ("Buy Now", "Back to Search"). It updates the tiny in-process session and returns a text description of the resulting page.
-
Prompt Engineering: The agent's instruction prompt is crucial for its success. It defines a state machine-like flow that guides the agent through the shopping process:
- Initial Inquiry: Ask the user for the product they're looking for.
- Search Phase: Use the
searchtool and present the results. - Product Exploration: Use the
clicktool to navigate to product details, descriptions, features, and reviews. - Purchase Confirmation: Use the
clicktool to select options and confirm the purchase. - Finalization: Inform the user that the purchase is complete.
The prompt also includes specific instructions on how to handle the web environment's state, such as using the "
< Prev" button to navigate back. -
Artifacts (optional extension): This lab's solution doesn't save artifacts โ but the
web_agent'sclick/searchtools are a natural place to addtool_context.save_artifact()calls, saving the HTML content of the current page after each action. That would let a user see the web page the agent is interacting with in the ADK's web UI, using the same pattern from Module 23.
By combining these components, we can create a powerful agent that can navigate a web environment, gather information, and interact with a user to complete a complex task.