chore(memory): enhance debugging and memory retrieval robustness
Some checks failed
Build and Push Docker / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker / build-and-push (push) Has been cancelled
This commit is contained in:
@ -58,14 +58,24 @@ In your response, consider the memories above to provide a personalized answer."
|
||||
def add_memory(self, messages: List[Dict[str, str]], user_id: str, metadata: Optional[Dict] = None) -> Dict[str, Any]:
|
||||
"""Add a memory for the user."""
|
||||
try:
|
||||
# Debug: Print what we're trying to add
|
||||
print(f"[DEBUG] Adding memory for user {user_id}")
|
||||
print(f"[DEBUG] Messages: {messages}")
|
||||
print(f"[DEBUG] Metadata: {metadata}")
|
||||
|
||||
result = self.memory.add(
|
||||
messages=messages,
|
||||
user_id=user_id,
|
||||
metadata=metadata or {}
|
||||
)
|
||||
|
||||
# Debug: Print the result
|
||||
print(f"[DEBUG] Add memory result: {result}")
|
||||
return result
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to add memory: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return {}
|
||||
|
||||
def format_memories_for_prompt(self, memories: List[Any]) -> str:
|
||||
@ -157,9 +167,23 @@ In your response, consider the memories above to provide a personalized answer."
|
||||
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}")
|
||||
|
||||
if isinstance(memories, dict):
|
||||
# Handle dictionary response format
|
||||
memories_list = memories.get("memories", [])
|
||||
# Check for different possible key names
|
||||
if "memories" in memories:
|
||||
memories_list = memories.get("memories", [])
|
||||
elif "results" in memories:
|
||||
memories_list = memories.get("results", [])
|
||||
else:
|
||||
# Try to find any list in the dict
|
||||
for key, value in memories.items():
|
||||
if isinstance(value, list):
|
||||
memories_list = value
|
||||
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]}")
|
||||
@ -172,6 +196,8 @@ In your response, consider the memories above to provide a personalized answer."
|
||||
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:
|
||||
|
Reference in New Issue
Block a user