Skip to content

Commit 923ebb7

Browse files
committed
Improve instructions
1 parent 404653b commit 923ebb7

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

README.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ In this workshop, you’ll build a **Grocery Shopping AI agent** step by step. E
66
## Exercise 0: Browse the Database
77

88
1. On the left-hand sidebar, click on the green leaf icon to open the MongoDB extension.
9-
2. From the extension page, click on **Groceries Database** to connect to the MongoDB database.
9+
2. From the extension page, click on **Local MongoDB Atlas** to connect to the MongoDB database.
1010
3. Explore the **grocery_store** database and the **inventory** collection provided.
1111
4. Open a few documents and notice their structure.
1212

@@ -45,9 +45,9 @@ In this step, you’ll create your first AI Agent with ADK. At this stage, the a
4545
Explanation of each field:
4646
4747
* **model** — The LLM powering the agent (here, Gemini 2.5 Flash).
48-
* **name** A unique identifier for your agent instance.
49-
* **instruction** A system message that defines how the agent should behave (you’ll fill this in later).
50-
* **tools** Python functions that the agent can call (currently empty).
48+
* **name** A unique identifier for your agent instance.
49+
* **instruction** A system message that defines how the agent should behave (you’ll fill this in later).
50+
* **tools** Python functions that the agent can call (currently empty).
5151
5252
1. Run the following command in the terminal to start the ADK development UI:
5353
@@ -75,11 +75,12 @@ In this step, you’ll create your first AI Agent with ADK. At this stage, the a
7575
7676
**What happens?**
7777
Since the agent doesn’t have any tools yet, it cannot actually access the database. Instead, it might:
78-
- Make up a product that doesn’t exist in the database.
79-
- Ask you follow up questions about which inventory you're referring to.
80-
- Attempt to search the web for an answer.
8178
82-
Neither of these behaviors is desirable — we want the agent to only use our inventory.
79+
- Make up a product that doesn’t exist in the database.
80+
- Ask you follow up questions about which inventory you're referring to.
81+
- Attempt to search the web for an answer.
82+
83+
Neither of these behaviors is desirable — you want the agent to only use the grocery store inventory.
8384
8485
**<span aria-hidden="true">👉</span> Discussion point:**
8586
What risks do you see if an agent makes up products or fetches information from outside sources instead of the inventory?
@@ -91,11 +92,13 @@ In this exercise, you’ll add a tool that lets the agent find products relevant
9192
### Step 1: Generate Embeddings
9293
9394
1. Open the MongoDB extension by clicking the green MongoDB leaf in the sidebar.
94-
2. Expand the **Groceries Database** connection, then the **grocery_store** database and finally, the **inventory** collection.
95-
3. Open any document. Notice the **gemini_embedding** field: it already contains the product’s vector embedding.
95+
2. Expand the **Local MongoDB Atlas** connection, then the **grocery_store** database and finally, the **inventory** collection.
96+
3. Open any MongoDB document from the **inventory** collection. Notice the **gemini_embedding** field: it already contains the product’s vector embedding.
9697
9798
We pre-generated these embeddings to save time and resources. Otherwise, every workshop attendee would need to re-run the same embedding process—producing identical vectors at unnecessary cost. For this exercise, you can work directly with the stored vectors.
9899
100+
***Hint***: Don't close the document—you'll need it for the next steps.
101+
99102
### Step 2: Create a Vector Search Index
100103
101104
A vector search index is a special data structure optimized for similarity searches. It allows MongoDB to efficiently compare vectors and return the closest matches.
@@ -112,29 +115,31 @@ Open **`mongodb_groceries_agent/create-vector-search-index.py`** and fill in the
112115
113116
1. `<DATABASE_NAME>`: the name of the database that you explored through the MongoDB extension
114117
2. `<COLLECTION_NAME>`: the collection with grocery products
115-
3. `<VECTOR_FIELD_IN_THE_DOCUMENT>`: the field storing the embedding (the numeric array)
116-
4. `<LENGTH_OF_THE_VECTOR>`: the size of the embedding array
118+
3. `<VECTOR_FIELD_IN_THE_DOCUMENT>`: the name of the field storing the vector embedding
119+
4. `<LENGTH_OF_THE_VECTOR>`: the size of the embedding array.
120+
- ***Hint***: The size is one of 128, 256, 512, 768, 1536, or 2048. Check the number of lines in the MongoDB document you opened earlier.
117121
5. `<VECTOR_SEARCH_DEFINITION>`: use the predefined variable in the script and pass it into the method
118122
119-
In the bottom panel, open a new terminal tab and run the script to create the index:
123+
Stop the running process in the terminal by pressing CTRL+C. Then, execute the vector creation script:
120124
121125
```bash
122126
python mongodb_groceries_agent/create-vector-search-index.py
123127
```
124128

125-
Creating the index takes only a few seconds for the 5000 documents you have in the dataset. After a 10-second timeout, the script will display the collection’s search indexes. At that point, your vector search index is ready and can be used by the agent to find similar products.
129+
After a 10-second timeout, the script will display the collection’s search indexes. Pay attention to the status of the index you just created—it may show as ***BUILDING*** or ***READY***. The collection has only 5000 documents, so by the time you start using the index, it will be fully built with status ***READY***.
126130

127-
### Step 3: Implement the Vector Search Tool
131+
### Step 3: Implement the Vector Search Tool
128132

129-
With the index in place, let’s wire up the agent so it can actually use it.
133+
With the index in place, let’s implement the search tool that the agent will use to find similar products.
130134

131135
In this step, you’ll:
132-
- Configure placeholders for your database and collection.
133-
- Define a helper to generate embeddings with Gemini.
134-
- Implement the `find_similar_products` tool that performs a vector search against MongoDB.
135-
- Register the tool with the agent so it becomes part of the shopping workflow.
136+
- Define a helper function to generate embeddings with Gemini. The function will be used to transform the user questions into vector embeddings.
137+
- Implement the `find_similar_products` tool that performs a vector search against the MongoDB `inventory` collection.
138+
- Register the tool with the agent so it becomes part of the shopping workflow.
139+
140+
Open **`mongodb_groceries_agent/agent.py`** and replace the `root_agent` variable with the following code.
136141

137-
Open **`mongodb_groceries_agent/agent.py`** and add the following code:
142+
**<span aria-hidden="true">️⚠️</span> Important**: Don't delete the imports or the `GOOGLE_API_KEY` variable!
138143

139144
```python
140145
# Initialize the GenAI client to vectorize the user queries
@@ -201,19 +206,12 @@ Your role is to guide customers through their shopping experience.
201206
What you can do:
202207
- Help users discover and explore products in the store.
203208
- Suggest alternatives when the exact item is not available.
204-
- Add products to the user’s shopping cart.
205-
- Answer product-related questions in a clear and concise way.
206-
- Return the total in the user’s shopping cart.
207209
208210
Available tools:
209211
1. **find_similar_products**: Search for products with names semantically similar to the user’s request.
210-
2. **add_to_cart**: Add a product to the user’s cart in MongoDB. Pass only the product name (as it appears in the inventory collection) and the user’s username.
211-
3. **calculate_cart_total**: Sum the total of all products in a user's cart and return it. Pass the user’s username.
212-
213212
Core guidelines:
214-
- **Always search first**: If a user asks for a product, call `find_similar_products` before attempting to add it to the cart.
213+
- **Always search first**: If a user asks for a product, call `find_similar_products`.
215214
- **Handle missing products**: If the requested product is not in the inventory, suggest similar items returned by the search.
216-
- **Parallel tool use**: You may call multiple tools in parallel when appropriate (e.g., searching for several items at once).
217215
- **Clarify only when necessary**: Ask for more details if the request is unclear and you cannot perform a search.
218216
- Keep your tone positive, approachable, and customer-focused throughout the interaction.
219217
@@ -222,9 +220,8 @@ Additional important instructions:
222220
- **Respect exact names**: When using `add_to_cart`, pass the product name exactly as stored in the inventory collection.
223221
- **Multi-item requests**: If the user asks for several items in one message, search for all items together and suggest results before adding to the cart.
224222
- **Quantity requests**: If the user specifies a quantity, repeat it back to confirm and ensure it is respected when adding to the cart.
225-
- **Cart confirmation**: After adding items, confirm with the user that they have been successfully added.
226223
- **Fallback behavior**: If no results are found, apologize politely, and encourage the user to try a different product or category.
227-
- **Stay focused**: Only handle product discovery, shopping, and cart management tasks. Politely decline requests unrelated to groceries.
224+
- **Stay focused**: Only handle product discovery. Politely decline requests unrelated to groceries.
228225
- **Answering product questions**: If the question is about a product (e.g., "Is this organic?" or "How much does it cost?"), use the search results to answer. If the information is not available, respond transparently that you don’t have that detail.
229226
230227
Remember: you are a professional yet friendly shopping assistant whose goal is to make the user’s grocery shopping smooth, efficient, and enjoyable.
@@ -234,14 +231,20 @@ Remember: you are a professional yet friendly shopping assistant whose goal is t
234231
root_agent = Agent(
235232
model="gemini-2.5-flash",
236233
name="grocery_shopping_agent",
237-
instruction=instruction
234+
instruction=instruction,
238235
tools=[
239-
find_similar_products
236+
<TOOL_FUNCTION_NAME> # <-- 4. Replace with the product search function declared above.
240237
]
241238
)
242239
```
243240

244-
Finally, restart the agent with the following command:
241+
Replace any of the placeholders with the correct values:
242+
1. `<OUTPUT_VECTOR_SIZE>` - Replace with the desired size of the vector. This should match the vector size in the document.
243+
2. `<VECTOR_FIELD_IN_THE_DOCUMENT` — Replace with the document field that holds the vector embedding
244+
3. `<VECTOR_FIELD_IN_THE_DOCUMENT>` (again) — Replace with the document field the holds the embedding. This will reduce the network traffic and the tokens the agent needs to include in LLM prompt.
245+
4. `<TOOL_FUNCTION_NAME>` - Replace with the product search function declared above.
246+
247+
Finally, start the agent development server again with the following command:
245248

246249
```
247250
adk web

0 commit comments

Comments
 (0)