The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
Catch json error for new_memories_with_action (#2324)
Dev Khant07d2f1108102
diff --git a/mem0/memory/main.py b/mem0/memory/main.pyindex d3f2d74a5..6bb1ac54a 100644--- a/mem0/memory/main.py+++ b/mem0/memory/main.py@@ -194,13 +194,21 @@ class Memory(MemoryBase):function_calling_prompt = get_update_memory_messages(retrieved_old_memory, new_retrieved_facts)- new_memories_with_actions = self.llm.generate_response(- messages=[{"role": "user", "content": function_calling_prompt}],- response_format={"type": "json_object"},- )+ try:+ new_memories_with_actions = self.llm.generate_response(+ messages=[{"role": "user", "content": function_calling_prompt}],+ response_format={"type": "json_object"},+ )+ except Exception as e:+ logging.error(f"Error in new_memories_with_actions: {e}")+ new_memories_with_actions = []- new_memories_with_actions = remove_code_blocks(new_memories_with_actions)- new_memories_with_actions = json.loads(new_memories_with_actions)+ try:+ new_memories_with_actions = remove_code_blocks(new_memories_with_actions)+ new_memories_with_actions = json.loads(new_memories_with_actions)+ except Exception as e:+ logging.error(f"Invalid JSON response: {e}")+ new_memories_with_actions = []returned_memories = []try: