refactor(memory): standardize memory service response handling
Some checks failed
Build and Push Docker / build-and-push (push) Failing after 43m47s

This commit is contained in:
gameloader
2025-10-12 17:48:55 +08:00
parent 3ef3b9449a
commit 26ad0dbf0f

View File

@ -36,23 +36,12 @@ In your response, consider the memories above to provide a personalized answer."
user_id=user_id,
limit=limit
)
# Debug: Print the actual format of results
print(f"[DEBUG] Search results type: {type(results)}")
print(f"[DEBUG] Search results content: {results}")
# Handle dictionary response format - check for both 'memories' and 'results' keys
if isinstance(results, dict):
# Handle dictionary response format (based on official docs)
memories = results.get("memories", [])
if memories:
print(f"[DEBUG] First memory type: {type(memories[0])}")
print(f"[DEBUG] First memory: {memories[0]}")
else:
print(f"[DEBUG] No memories found in search results")
memories = results.get("memories", results.get("results", []))
return memories
elif isinstance(results, list):
# Handle list response format
return results
else:
print(f"[WARNING] Unexpected search results format: {type(results)}")
print(f"[ERROR] Unexpected search results format: {type(results)}")
return []
except Exception as e:
print(f"[ERROR] Failed to search memories: {e}")
@ -168,10 +157,7 @@ In your response, consider the memories above to provide a personalized answer."
"""Get all memories for a user."""
try:
memories = self.memory.get_all(user_id=user_id)
# Debug: Print the actual format of memories
print(f"[DEBUG] All memories type: {type(memories)}")
print(f"[DEBUG] All memories content: {memories}")
# Handle dictionary response format
if isinstance(memories, dict):
# Check for different possible key names
if "memories" in memories:
@ -186,21 +172,12 @@ In your response, consider the memories above to provide a personalized answer."
break
else:
memories_list = []
if memories_list:
print(f"[DEBUG] First memory type: {type(memories_list[0])}")
print(f"[DEBUG] First memory: {memories_list[0]}")
return memories_list
elif isinstance(memories, list):
# Handle list response format
return memories
else:
print(f"[WARNING] Unexpected memories format: {type(memories)}")
print(f"[ERROR] Unexpected memories format: {type(memories)}")
return []
except Exception as e:
print(f"[ERROR] Failed to get all memories: {e}")
import traceback
traceback.print_exc()
return []
def delete_memory(self, memory_id: str) -> bool: