Skip to content

Commit 293bd2a

Browse files
committed
fix(managed_agents): address remaining memory cookbook review items
- Add wait_for_idle_status calls before session archive in cleanup - Break out of run_turn on any status_idle, not just end_turn - Guard event.input against None in tool_use handler - Move seeding-order warning to a markdown Note callout - Add %pip install cell for minimum SDK version - Link to sibling CMA notebooks from the summary
1 parent fd673f8 commit 293bd2a

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

managed_agents/CMA_remember_user_preferences.ipynb

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@
5252
"## Set up the client"
5353
]
5454
},
55+
{
56+
"cell_type": "code",
57+
"id": "da6a39d52f3e4b0a",
58+
"metadata": {},
59+
"execution_count": null,
60+
"outputs": [],
61+
"source": [
62+
"%%capture\n",
63+
"%pip install -q \"anthropic>=0.91.0\""
64+
]
65+
},
5566
{
5667
"cell_type": "code",
5768
"id": "3f060791d5fa56fd8657f80c37f2d982",
@@ -111,13 +122,18 @@
111122
" elif event.type == \"agent.tool_use\":\n",
112123
" # Surface reads and writes to the memory mount so you can see\n",
113124
" # the agent checking and updating its memory.\n",
114-
" target = event.input.get(\"file_path\") or event.input.get(\"command\", \"\")\n",
125+
" inp = event.input or {}\n",
126+
" target = inp.get(\"file_path\") or inp.get(\"command\", \"\")\n",
115127
" if \"/mnt/memory/\" in str(target):\n",
116128
" print(f\" [memory] {event.name}: {target}\")\n",
117129
"\n",
118130
" elif event.type == \"session.status_idle\":\n",
119131
" if event.stop_reason and event.stop_reason.type == \"end_turn\":\n",
120132
" 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",
136+
" break\n",
121137
"\n",
122138
" elif event.type == \"session.status_terminated\":\n",
123139
" break\n",
@@ -483,7 +499,9 @@
483499
"\n",
484500
"### Seed a store from your existing data\n",
485501
"\n",
486-
"If you already know things about a customer from their account profile or purchase history, you can write them into the store before the first session so the agent starts informed. In a real application you would run this seeding step before any sessions are created; it appears here, after the demo, only so the main learn-then-recall flow above stays focused."
502+
"If you already know things about a customer from their account profile or purchase history, you can write them into the store before the first session so the agent starts informed. In a real application you would run this seeding step before any sessions are created; it appears here, after the demo, only so the main learn-then-recall flow above stays focused.\n",
503+
"\n",
504+
"> **Note:** Run this cell before the cleanup cell at the end of the notebook, since `store` is deleted there."
487505
]
488506
},
489507
{
@@ -501,7 +519,6 @@
501519
}
502520
],
503521
"source": [
504-
"# Run before the cleanup cell below; `store` is deleted there.\n",
505522
"seeded = client.beta.memory_stores.memories.create(\n",
506523
" store.id,\n",
507524
" path=\"/purchase-history.md\",\n",
@@ -571,6 +588,9 @@
571588
"execution_count": 10,
572589
"outputs": [],
573590
"source": [
591+
"wait_for_idle_status(client, session_one.id)\n",
592+
"wait_for_idle_status(client, session_two.id)\n",
593+
"\n",
574594
"client.beta.sessions.archive(session_one.id)\n",
575595
"client.beta.sessions.archive(session_two.id)\n",
576596
"client.beta.memory_stores.delete(store.id)\n",
@@ -594,6 +614,11 @@
594614
"\n",
595615
"From here you can map your own user IDs to memory store IDs, seed stores from your existing customer data, and layer shared read-only stores on top for brand-wide knowledge.\n",
596616
"\n",
617+
"### Other notebooks in this series\n",
618+
"\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",
621+
"\n",
597622
"### Learn more\n",
598623
"\n",
599624
"- [Claude Managed Agents overview](https://docs.anthropic.com/en/docs/managed-agents/overview)\n",

0 commit comments

Comments
 (0)