Skip to content

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.

Fix side effects on message history (#3619)

AbTrax34261a158353
diff --git a/autogpt/memory_management/summary_memory.py b/autogpt/memory_management/summary_memory.py
index 9e6126377b..754c09ba7c 100644
--- a/autogpt/memory_management/summary_memory.py
+++ b/autogpt/memory_management/summary_memory.py
@@ -1,3 +1,4 @@
+import copy
import json
from typing import Dict, List, Tuple
@@ -44,7 +45,9 @@ def get_newly_trimmed_messages(
return new_messages_not_in_context, new_index
-def update_running_summary(current_memory: str, new_events: List[Dict]) -> str:
+def update_running_summary(
+ current_memory: str, new_events: List[Dict[str, str]]
+) -> str:
"""
This function takes a list of dictionaries representing new events and combines them with the current summary,
focusing on key and potentially important information to remember. The updated summary is returned in a message
@@ -61,17 +64,23 @@ def update_running_summary(current_memory: str, new_events: List[Dict]) -> str:
update_running_summary(new_events)
# Returns: "This reminds you of these events from your past: \nI entered the kitchen and found a scrawled note saying 7."
"""
+ # Create a copy of the new_events list to prevent modifying the original list
+ new_events = copy.deepcopy(new_events)
+
# Replace "assistant" with "you". This produces much better first person past tense results.
for event in new_events:
if event["role"].lower() == "assistant":
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)
+
elif event["role"].lower() == "system":
event["role"] = "your computer"
+
# Delete all user messages
elif event["role"] == "user":
new_events.remove(event)