Skip to content

Commit 5c77fd9

Browse files
committed
Fix get_or_create_working_memory issue in 03_memory_integration
For new sessions, don't call get_or_create_working_memory as it fails when the session doesn't exist. Instead, just start with empty working memory and create it with put_working_memory.
1 parent 288f858 commit 5c77fd9

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

python-recipes/context-engineering/notebooks/section-3-memory/03_memory_integration.ipynb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,9 @@
161161
"\n",
162162
"# Step 1: Load working memory (empty for first turn)\n",
163163
"print(\"\\n1. Loading working memory...\")\n",
164-
"_, working_memory = await memory_client.get_or_create_working_memory(\n",
165-
" session_id=session_id_1,\n",
166-
" user_id=\"demo_user\",\n",
167-
" model_name=\"gpt-4o\"\n",
168-
")\n",
169-
"print(f\" Messages in working memory: {len(working_memory.messages) if working_memory else 0}\")\n",
164+
"# For first turn, working memory is empty\n",
165+
"working_memory = None\n",
166+
"print(f\" Messages in working memory: 0 (new session)\")\n",
170167
"\n",
171168
"# Step 2: Search long-term memory (empty for first interaction)\n",
172169
"print(\"\\n2. Searching long-term memory...\")\n",
@@ -366,12 +363,9 @@
366363
"\n",
367364
"# Step 1: Load working memory (empty - new session)\n",
368365
"print(\"\\n1. Loading working memory...\")\n",
369-
"_, working_memory = await memory_client.get_or_create_working_memory(\n",
370-
" session_id=session_id_2,\n",
371-
" user_id=\"demo_user\",\n",
372-
" model_name=\"gpt-4o\"\n",
373-
")\n",
374-
"print(f\" Messages in working memory: {len(working_memory.messages) if working_memory else 0}\")\n",
366+
"# For new session, working memory is empty\n",
367+
"working_memory = None\n",
368+
"print(f\" Messages in working memory: 0\")\n",
375369
"print(\" (Empty - this is a new session)\")\n",
376370
"\n",
377371
"# Step 2: Search long-term memory (has data from Session 1)\n",

0 commit comments

Comments
 (0)