|
52 | 52 | "## Set up the client" |
53 | 53 | ] |
54 | 54 | }, |
| 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 | + }, |
55 | 66 | { |
56 | 67 | "cell_type": "code", |
57 | 68 | "id": "3f060791d5fa56fd8657f80c37f2d982", |
|
111 | 122 | " elif event.type == \"agent.tool_use\":\n", |
112 | 123 | " # Surface reads and writes to the memory mount so you can see\n", |
113 | 124 | " # 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", |
115 | 127 | " if \"/mnt/memory/\" in str(target):\n", |
116 | 128 | " print(f\" [memory] {event.name}: {target}\")\n", |
117 | 129 | "\n", |
118 | 130 | " elif event.type == \"session.status_idle\":\n", |
119 | 131 | " if event.stop_reason and event.stop_reason.type == \"end_turn\":\n", |
120 | 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", |
| 136 | + " break\n", |
121 | 137 | "\n", |
122 | 138 | " elif event.type == \"session.status_terminated\":\n", |
123 | 139 | " break\n", |
|
483 | 499 | "\n", |
484 | 500 | "### Seed a store from your existing data\n", |
485 | 501 | "\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." |
487 | 505 | ] |
488 | 506 | }, |
489 | 507 | { |
|
501 | 519 | } |
502 | 520 | ], |
503 | 521 | "source": [ |
504 | | - "# Run before the cleanup cell below; `store` is deleted there.\n", |
505 | 522 | "seeded = client.beta.memory_stores.memories.create(\n", |
506 | 523 | " store.id,\n", |
507 | 524 | " path=\"/purchase-history.md\",\n", |
|
571 | 588 | "execution_count": 10, |
572 | 589 | "outputs": [], |
573 | 590 | "source": [ |
| 591 | + "wait_for_idle_status(client, session_one.id)\n", |
| 592 | + "wait_for_idle_status(client, session_two.id)\n", |
| 593 | + "\n", |
574 | 594 | "client.beta.sessions.archive(session_one.id)\n", |
575 | 595 | "client.beta.sessions.archive(session_two.id)\n", |
576 | 596 | "client.beta.memory_stores.delete(store.id)\n", |
|
594 | 614 | "\n", |
595 | 615 | "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", |
596 | 616 | "\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", |
597 | 622 | "### Learn more\n", |
598 | 623 | "\n", |
599 | 624 | "- [Claude Managed Agents overview](https://docs.anthropic.com/en/docs/managed-agents/overview)\n", |
|
0 commit comments