Skip to content

Commit 869f7e7

Browse files
committed
fix(managed_agents): round 5 of memory cookbook review feedback
- Simplify status_idle handler to a single unconditional break - Document run_turn return value in the docstring - Restore inline 'Optional: run before cleanup' hint in the seeding cell - Add catalog store cleanup reminder to the combine-stores snippet - Tighten registry description and intro phrasing
1 parent 293bd2a commit 869f7e7

2 files changed

Lines changed: 51 additions & 48 deletions

File tree

managed_agents/CMA_remember_user_preferences.ipynb

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"source": [
88
"# Build agents that remember your users\n",
99
"\n",
10-
"Most agents start every conversation from scratch. A customer tells your shopping assistant their size, their budget, and which materials they avoid, and the next time they return, the agent has forgotten everything. They have to repeat themselves, and the experience feels transactional rather than personal.\n",
10+
"Most agents start every conversation from scratch. A customer tells your shopping assistant their size, their budget, and which materials they avoid, and the next time they return, the agent has forgotten everything. They have to repeat themselves, and the experience feels generic rather than personal.\n",
1111
"\n",
12-
"We just introduced **Memory** in Claude Managed Agents to solve this. A memory store is a persistent collection of text files that Claude can read and write during a session, and that survives across sessions. Anthropic hosts the storage, mounts it into the agent's environment, and prompts Claude on when and what to save \u2014 so there is no database, vector store, or retrieval pipeline for you to stand up. Attach the same store to every session for a given customer, and your agent accumulates knowledge about them over time.\n",
12+
"We just introduced Memory in Claude Managed Agents to solve this. Think of it as a shared notebook your agent gets for each customer: Claude jots relevant things down during a session, and those notes are still there the next time the same customer comes back. Setup is a simple API call away.\n",
1313
"\n",
14-
"In this guide you will build a personal shopping assistant for a retail brand. The agent will learn a customer's preferences during their first visit, save them to a memory store, and recall them automatically on the next visit without being told again.\n",
14+
"In this guide you will build an example shopping assistant for a retail brand. The agent will learn a customer's preferences during their first visit, save them to a user-specific memory store, and recall them automatically on the next visit without being told again.\n",
1515
"\n",
1616
"## What you will build\n",
1717
"\n",
@@ -54,9 +54,9 @@
5454
},
5555
{
5656
"cell_type": "code",
57+
"execution_count": null,
5758
"id": "da6a39d52f3e4b0a",
5859
"metadata": {},
59-
"execution_count": null,
6060
"outputs": [],
6161
"source": [
6262
"%%capture\n",
@@ -65,9 +65,9 @@
6565
},
6666
{
6767
"cell_type": "code",
68+
"execution_count": 1,
6869
"id": "3f060791d5fa56fd8657f80c37f2d982",
6970
"metadata": {},
70-
"execution_count": 1,
7171
"outputs": [],
7272
"source": [
7373
"import os\n",
@@ -92,13 +92,16 @@
9292
},
9393
{
9494
"cell_type": "code",
95+
"execution_count": 2,
9596
"id": "f3a4cbcc2086151619d476cc38eb19fc",
9697
"metadata": {},
97-
"execution_count": 2,
9898
"outputs": [],
9999
"source": [
100100
"def run_turn(session_id: str, user_text: str) -> str:\n",
101-
" \"\"\"Send one user message and stream the agent's response until it goes idle.\"\"\"\n",
101+
" \"\"\"Send one user message and stream the agent's response until it goes idle.\n",
102+
"\n",
103+
" Returns the agent's full text reply for callers who want it programmatically.\n",
104+
" \"\"\"\n",
102105
" print(f\"\\n[user] {user_text}\")\n",
103106
" reply_parts: list[str] = []\n",
104107
"\n",
@@ -128,11 +131,8 @@
128131
" print(f\" [memory] {event.name}: {target}\")\n",
129132
"\n",
130133
" elif event.type == \"session.status_idle\":\n",
131-
" if event.stop_reason and event.stop_reason.type == \"end_turn\":\n",
132-
" break\n",
133-
" # This notebook only sends user.message events, so end_turn is the\n",
134-
" # only idle reason we expect. Break on anything else as well so an\n",
135-
" # unexpected stop_reason (such as requires_action) cannot hang the loop.\n",
134+
" # Break on any idle reason so an unexpected stop_reason\n",
135+
" # (such as requires_action) cannot hang the loop.\n",
136136
" break\n",
137137
"\n",
138138
" elif event.type == \"session.status_terminated\":\n",
@@ -156,9 +156,9 @@
156156
},
157157
{
158158
"cell_type": "code",
159+
"execution_count": 3,
159160
"id": "e188613e44222908c586b1926f7a8426",
160161
"metadata": {},
161-
"execution_count": 3,
162162
"outputs": [
163163
{
164164
"name": "stdout",
@@ -194,9 +194,9 @@
194194
},
195195
{
196196
"cell_type": "code",
197+
"execution_count": 4,
197198
"id": "39d254525e9703649b4e8a170d3b3d2d",
198199
"metadata": {},
199-
"execution_count": 4,
200200
"outputs": [
201201
{
202202
"name": "stdout",
@@ -248,9 +248,9 @@
248248
},
249249
{
250250
"cell_type": "code",
251+
"execution_count": 5,
251252
"id": "ddb9a6c41adb8958ea43912ae86d775a",
252253
"metadata": {},
253-
"execution_count": 5,
254254
"outputs": [
255255
{
256256
"name": "stdout",
@@ -286,9 +286,9 @@
286286
},
287287
{
288288
"cell_type": "code",
289+
"execution_count": 6,
289290
"id": "99218076c63d2339353963a2bfb0280b",
290291
"metadata": {},
291-
"execution_count": 6,
292292
"outputs": [
293293
{
294294
"name": "stdout",
@@ -303,37 +303,37 @@
303303
"\n",
304304
"---\n",
305305
"\n",
306-
"### \ud83c\udf3f Top Picks for You\n",
306+
"### 🌿 Top Picks for You\n",
307307
"\n",
308-
"#### 1. **Olive Moto Jacket** \u2014 ~$110\u2013$150\n",
308+
"#### 1. **Olive Moto Jacket** ~$110$150\n",
309309
"A classic biker silhouette in a deep **olive green** faux leather. Look for styles with zip-detail sleeves and a fitted waist. Great for casual or edgy looks.\n",
310310
"- *Why you'll love it:* Earthy tone, very on-trend, versatile for layering.\n",
311311
"\n",
312-
"#### 2. **Camel/Tan Oversized Blazer-Jacket** \u2014 ~$80\u2013$160\n",
312+
"#### 2. **Camel/Tan Oversized Blazer-Jacket** ~$80$160\n",
313313
"A structured vegan leather blazer in **camel or tan** gives a polished, sophisticated vibe. Works dressed up or down.\n",
314314
"- *Why you'll love it:* Classic earth tone, medium sizing runs well in this style, timeless investment.\n",
315315
"\n",
316-
"#### 3. **Rust/Cognac Bomber Jacket** \u2014 ~$90\u2013$170\n",
316+
"#### 3. **Rust/Cognac Bomber Jacket** ~$90$170\n",
317317
"A **rust or cognac-toned** vegan leather bomber is a bold earth-tone statement piece with a relaxed, comfortable fit.\n",
318318
"- *Why you'll love it:* Rich warm color, bomber silhouettes are flattering in medium, cozy feel.\n",
319319
"\n",
320-
"#### 4. **Terracotta Cropped Jacket** \u2014 ~$75\u2013$140\n",
320+
"#### 4. **Terracotta Cropped Jacket** ~$75$140\n",
321321
"A cropped vegan leather jacket in **terracotta** pairs beautifully with high-waisted jeans or wide-leg trousers.\n",
322322
"- *Why you'll love it:* Trendy silhouette, stunning earthy hue, well within budget.\n",
323323
"\n",
324324
"---\n",
325325
"\n",
326-
"### \ud83d\udecd\ufe0f Brands to Check Out\n",
326+
"### 🛍️ Brands to Check Out\n",
327327
"Here are some brands known for quality vegan leather within your budget:\n",
328-
"- **ASOS** \u2013 Wide range of faux leather styles in various earth tones\n",
329-
"- **Free People** \u2013 Boho-leaning earth tone options\n",
330-
"- **H&M** \u2013 Affordable vegan leather jackets in seasonal colors\n",
331-
"- **Lulus** \u2013 Great selection of trendy vegan styles under $100\n",
332-
"- **Noize** \u2013 A dedicated vegan outerwear brand, often has earthy tones under $200\n",
328+
"- **ASOS** Wide range of faux leather styles in various earth tones\n",
329+
"- **Free People** Boho-leaning earth tone options\n",
330+
"- **H&M** Affordable vegan leather jackets in seasonal colors\n",
331+
"- **Lulus** Great selection of trendy vegan styles under $100\n",
332+
"- **Noize** A dedicated vegan outerwear brand, often has earthy tones under $200\n",
333333
"\n",
334334
"---\n",
335335
"\n",
336-
"Do any of these styles appeal to you? I can help narrow it down further \u2014 for example, do you prefer a **fitted or relaxed fit**, or a particular style like moto, bomber, or blazer? \ud83d\ude0a\n"
336+
"Do any of these styles appeal to you? I can help narrow it down further for example, do you prefer a **fitted or relaxed fit**, or a particular style like moto, bomber, or blazer? 😊\n"
337337
]
338338
}
339339
],
@@ -360,9 +360,9 @@
360360
},
361361
{
362362
"cell_type": "code",
363+
"execution_count": 7,
363364
"id": "8e9635b265c0205eb209d791613b1448",
364365
"metadata": {},
365-
"execution_count": 7,
366366
"outputs": [
367367
{
368368
"name": "stdout",
@@ -382,7 +382,7 @@
382382
"- Usually under $200\n",
383383
"\n",
384384
"## Materials\n",
385-
"- VEGAN LEATHER ONLY \u2014 absolutely no animal leather\n",
385+
"- VEGAN LEATHER ONLY absolutely no animal leather\n",
386386
"- (No other material restrictions noted yet)\n",
387387
"\n",
388388
"## Favorite Brands\n",
@@ -426,9 +426,9 @@
426426
},
427427
{
428428
"cell_type": "code",
429+
"execution_count": 8,
429430
"id": "1e1b4b4e8183a2f5fbf095f8f68caab6",
430431
"metadata": {},
431-
"execution_count": 8,
432432
"outputs": [
433433
{
434434
"name": "stdout",
@@ -439,25 +439,25 @@
439439
" [memory] read: /mnt/memory/shopper-preferences\n",
440440
" [memory] bash: ls /mnt/memory/shopper-preferences/\n",
441441
" [memory] read: /mnt/memory/shopper-preferences/preferences.md\n",
442-
"[agent] Great news \u2014 I already have your preferences on file! Here's what I kept in mind for you:\n",
442+
"[agent] Great news I already have your preferences on file! Here's what I kept in mind for you:\n",
443443
"\n",
444-
"- \ud83c\udfa8 **Style:** Earth tones (browns, tans, olive, camel, etc.)\n",
445-
"- \ud83d\udcb0 **Budget:** Under $200\n",
446-
"- \ud83c\udf31 **Materials:** Vegan leather only \u2014 no animal leather\n",
444+
"- 🎨 **Style:** Earth tones (browns, tans, olive, camel, etc.)\n",
445+
"- 💰 **Budget:** Under $200\n",
446+
"- 🌱 **Materials:** Vegan leather only no animal leather\n",
447447
"\n",
448448
"With that in mind, here are some work bag recommendations that would suit you perfectly:\n",
449449
"\n",
450450
"---\n",
451451
"\n",
452-
"### \ud83d\udecd\ufe0f Top Picks for a Work Bag\n",
452+
"### 🛍️ Top Picks for a Work Bag\n",
453453
"\n",
454-
"1. **Structured Tote in Camel Vegan Leather** \u2014 A polished, professional look in a warm earth tone. Fits a laptop + daily essentials. Great desk-to-commute bag.\n",
454+
"1. **Structured Tote in Camel Vegan Leather** A polished, professional look in a warm earth tone. Fits a laptop + daily essentials. Great desk-to-commute bag.\n",
455455
"\n",
456-
"2. **Olive Canvas & Vegan Leather Trim Laptop Bag** \u2014 A sleek crossbody/shoulder bag with a relaxed but put-together vibe. The canvas keeps it lightweight.\n",
456+
"2. **Olive Canvas & Vegan Leather Trim Laptop Bag** A sleek crossbody/shoulder bag with a relaxed but put-together vibe. The canvas keeps it lightweight.\n",
457457
"\n",
458-
"3. **Tan Vegan Leather Satchel** \u2014 A classic work satchel with a top handle and shoulder strap. Timeless silhouette, stays under budget.\n",
458+
"3. **Tan Vegan Leather Satchel** A classic work satchel with a top handle and shoulder strap. Timeless silhouette, stays under budget.\n",
459459
"\n",
460-
"4. **Terracotta Faux-Leather Tote** \u2014 A bold but grounded earth tone that adds personality to a work outfit without being over the top.\n",
460+
"4. **Terracotta Faux-Leather Tote** A bold but grounded earth tone that adds personality to a work outfit without being over the top.\n",
461461
"\n",
462462
"---\n",
463463
"\n",
@@ -506,19 +506,20 @@
506506
},
507507
{
508508
"cell_type": "code",
509+
"execution_count": 9,
509510
"id": "22425c8bded6cc68f57d6610c148d71f",
510511
"metadata": {},
511-
"execution_count": 9,
512512
"outputs": [
513513
{
514-
"output_type": "stream",
515514
"name": "stdout",
515+
"output_type": "stream",
516516
"text": [
517517
"Seeded /purchase-history.md\n"
518518
]
519519
}
520520
],
521521
"source": [
522+
"# Optional: run before the cleanup cell.\n",
522523
"seeded = client.beta.memory_stores.memories.create(\n",
523524
" store.id,\n",
524525
" path=\"/purchase-history.md\",\n",
@@ -564,6 +565,9 @@
564565
" },\n",
565566
" ],\n",
566567
")\n",
568+
"\n",
569+
"# Remember to clean up the catalog store when you are done:\n",
570+
"# client.beta.memory_stores.delete(catalog.id)\n",
567571
"```\n",
568572
"\n",
569573
"### Audit and correct\n",
@@ -583,9 +587,9 @@
583587
},
584588
{
585589
"cell_type": "code",
590+
"execution_count": 10,
586591
"id": "ee5e185e47607a3948f634faeb30dbce",
587592
"metadata": {},
588-
"execution_count": 10,
589593
"outputs": [],
590594
"source": [
591595
"wait_for_idle_status(client, session_one.id)\n",
@@ -616,8 +620,8 @@
616620
"\n",
617621
"### Other notebooks in this series\n",
618622
"\n",
619-
"- [`CMA_iterate_fix_failing_tests.ipynb`](CMA_iterate_fix_failing_tests.ipynb) \u2014 the entry-point notebook. Introduces agents, environments, sessions, file mounts, and the streaming event loop through a do-observe-fix loop on a failing test suite.\n",
620-
"- [`CMA_operate_in_production.ipynb`](CMA_operate_in_production.ipynb) \u2014 production setup story: vault-backed MCP credentials, the `session.status_idled` webhook for HITL without long-lived connections, and the resource lifecycle CRUD verbs.\n",
623+
"- [`CMA_iterate_fix_failing_tests.ipynb`](CMA_iterate_fix_failing_tests.ipynb) the entry-point notebook. Introduces agents, environments, sessions, file mounts, and the streaming event loop through a do-observe-fix loop on a failing test suite.\n",
624+
"- [`CMA_operate_in_production.ipynb`](CMA_operate_in_production.ipynb) production setup story: vault-backed MCP credentials, the `session.status_idled` webhook for HITL without long-lived connections, and the resource lifecycle CRUD verbs.\n",
621625
"\n",
622626
"### Learn more\n",
623627
"\n",

registry.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,8 @@
737737
- Multimodal
738738
- Tools
739739
- title: Build agents that remember your users
740-
description: Give a Managed Agent a memory store so it learns and recalls a
741-
customer's shopping preferences across separate sessions, plus patterns for
742-
seeding, inspecting, and combining stores from your own application.
740+
description: Give your Claude Managed Agents a Memory store so they learn and
741+
remember your users' preferences across multiple interactions.
743742
path: managed_agents/CMA_remember_user_preferences.ipynb
744743
authors:
745744
- gaganb-ant

0 commit comments

Comments
 (0)