AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Catch JSON error in summary_memory.py (#3996)
Kristian Jacksona60512cdae97
diff --git a/autogpt/memory_management/summary_memory.py b/autogpt/memory_management/summary_memory.pyindex 4e818acf11..a13b63f3af 100644--- a/autogpt/memory_management/summary_memory.py+++ b/autogpt/memory_management/summary_memory.py@@ -6,6 +6,7 @@ from autogpt.agent import Agentfrom autogpt.config import Configfrom autogpt.llm.llm_utils import create_chat_completionfrom autogpt.log_cycle.log_cycle import PROMPT_SUMMARY_FILE_NAME, SUMMARY_FILE_NAME+from autogpt.logs import loggercfg = Config()@@ -75,10 +76,14 @@ def update_running_summary(event["role"] = "you"# Remove "thoughts" dictionary from "content"- content_dict = json.loads(event["content"])- if "thoughts" in content_dict:- del content_dict["thoughts"]- event["content"] = json.dumps(content_dict)+ try:+ content_dict = json.loads(event["content"])+ if "thoughts" in content_dict:+ del content_dict["thoughts"]+ event["content"] = json.dumps(content_dict)+ except json.decoder.JSONDecodeError:+ if cfg.debug_mode:+ logger.error(f"Error: Invalid JSON: {event['content']}\n")elif event["role"].lower() == "system":event["role"] = "your computer"