Skip to content

Commit 93a3559

Browse files
committed
Fix tools.py to use actual MemoryAPIClient API
- Use create_long_term_memory() with ClientMemoryRecord - Use search_long_term_memory() which returns MemoryRecordResults - Access memories via results.memories
1 parent 0482676 commit 93a3559

File tree

1 file changed

+14
-8
lines changed
  • python-recipes/context-engineering/reference-agent/redis_context_course

1 file changed

+14
-8
lines changed

python-recipes/context-engineering/reference-agent/redis_context_course/tools.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,17 @@ async def store_memory(text: str, memory_type: str = "semantic", topics: List[st
213213
- text="Student completed CS101 with grade A", memory_type="episodic", topics=["courses", "grades"]
214214
"""
215215
try:
216-
await memory_client.create_memory(
216+
from agent_memory_client import ClientMemoryRecord
217+
218+
# Note: user_id should be passed from the calling context
219+
# For now, we'll let the client use its default namespace
220+
memory = ClientMemoryRecord(
217221
text=text,
218222
memory_type=memory_type,
219223
topics=topics if topics else ["general"]
220224
)
225+
226+
await memory_client.create_long_term_memory([memory])
221227
return f"✅ Stored memory: {text}"
222228
except Exception as e:
223229
return f"❌ Failed to store memory: {str(e)}"
@@ -241,16 +247,16 @@ async def search_memories(query: str, limit: int = 5) -> str:
241247
- query="goals" → finds student's stated goals
242248
"""
243249
try:
244-
memories = await memory_client.search_memories(
245-
query=query,
250+
results = await memory_client.search_long_term_memory(
251+
text=query,
246252
limit=limit
247253
)
248-
249-
if not memories:
254+
255+
if not results.memories:
250256
return "No relevant memories found."
251-
252-
result = f"Found {len(memories)} relevant memories:\n\n"
253-
for i, memory in enumerate(memories, 1):
257+
258+
result = f"Found {len(results.memories)} relevant memories:\n\n"
259+
for i, memory in enumerate(results.memories, 1):
254260
result += f"{i}. {memory.text}\n"
255261
result += f" Type: {memory.memory_type} | Topics: {', '.join(memory.topics)}\n\n"
256262

0 commit comments

Comments
 (0)