Skip to content

Commit

Permalink
Fix side effects on message history (Significant-Gravitas#3619)
Browse files Browse the repository at this point in the history
Co-authored-by: Reinier van der Leer <[email protected]>
  • Loading branch information
AbTrax and Pwuts authored May 1, 2023
1 parent d8968ae commit 34261a1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion autogpt/memory_management/summary_memory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import json
from typing import Dict, List, Tuple

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 34261a1

Please sign in to comment.