Skip to content

Commit 288f858

Browse files
committed
Fix all API usage issues in 03_memory_integration notebook
- Fixed len(long_term_memories) to len(long_term_memories.memories) - Fixed iteration over long_term_memories to long_term_memories.memories - Fixed empty list [] to actual message creation for working memory - Fixed if long_term_memories: to if long_term_memories.memories:
1 parent 8da9cc7 commit 288f858

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
" text=user_query,\n",
176176
" limit=3\n",
177177
")\n",
178-
"print(f\" Relevant memories found: {len(long_term_memories)}\")\n",
178+
"print(f\" Relevant memories found: {len(long_term_memories.memories)}\")\n",
179179
"\n",
180180
"# Step 3: Process with LLM\n",
181181
"print(\"\\n3. Processing with LLM...\")\n",
@@ -192,7 +192,10 @@
192192
"from agent_memory_client.models import WorkingMemory, MemoryMessage\n",
193193
"\n",
194194
"# Convert messages to MemoryMessage format\n",
195-
"memory_messages = [MemoryMessage(**msg) for msg in []]\n",
195+
"memory_messages = [\n",
196+
" MemoryMessage(role=\"user\", content=user_query),\n",
197+
" MemoryMessage(role=\"assistant\", content=response.content)\n",
198+
"]\n",
196199
"\n",
197200
"# Create WorkingMemory object\n",
198201
"working_memory = WorkingMemory(\n",
@@ -249,7 +252,7 @@
249252
" text=user_query_2,\n",
250253
" limit=3\n",
251254
")\n",
252-
"print(f\" Relevant memories found: {len(long_term_memories)}\")\n",
255+
"print(f\" Relevant memories found: {len(long_term_memories.memories)}\")\n",
253256
"\n",
254257
"# Step 3: Process with LLM (with conversation history)\n",
255258
"print(\"\\n3. Processing with LLM...\")\n",
@@ -378,15 +381,15 @@
378381
" text=user_query_3,\n",
379382
" limit=5\n",
380383
")\n",
381-
"print(f\" Relevant memories found: {len(long_term_memories)}\")\n",
382-
"if long_term_memories:\n",
384+
"print(f\" Relevant memories found: {len(long_term_memories.memories)}\")\n",
385+
"if long_term_memories.memories:\n",
383386
" print(\"\\n Retrieved memories:\")\n",
384-
" for memory in long_term_memories:\n",
387+
" for memory in long_term_memories.memories:\n",
385388
" print(f\" - {memory.text}\")\n",
386389
"\n",
387390
"# Step 3: Process with LLM (with long-term context)\n",
388391
"print(\"\\n3. Processing with LLM...\")\n",
389-
"context = \"\\n\".join([f\"- {m.text}\" for m in long_term_memories])\n",
392+
"context = \"\\n\".join([f\"- {m.text}\" for m in long_term_memories.memories])\n",
390393
"system_prompt = f\"\"\"You are a helpful class scheduling agent for Redis University.\n",
391394
"\n",
392395
"What you know about this student:\n",
@@ -408,7 +411,10 @@
408411
"from agent_memory_client.models import WorkingMemory, MemoryMessage\n",
409412
"\n",
410413
"# Convert messages to MemoryMessage format\n",
411-
"memory_messages = [MemoryMessage(**msg) for msg in []]\n",
414+
"memory_messages = [\n",
415+
" MemoryMessage(role=\"user\", content=user_query_3),\n",
416+
" MemoryMessage(role=\"assistant\", content=response.content)\n",
417+
"]\n",
412418
"\n",
413419
"# Create WorkingMemory object\n",
414420
"working_memory = WorkingMemory(\n",

0 commit comments

Comments
 (0)