Skip to content

Commit e21917c

Browse files
authored
Feature/enable intuitive logs summarization (Significant-Gravitas#3697)
1 parent 26c6cfe commit e21917c

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

autogpt/llm/chat.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,8 @@
88
from autogpt.llm.base import Message
99
from autogpt.llm.llm_utils import create_chat_completion
1010
from autogpt.llm.token_counter import count_message_tokens
11-
from autogpt.log_cycle.log_cycle import PROMPT_NEXT_ACTION_FILE_NAME
11+
from autogpt.log_cycle.log_cycle import CURRENT_CONTEXT_FILE_NAME
1212
from autogpt.logs import logger
13-
from autogpt.memory_management.store_memory import (
14-
save_memory_trimmed_from_context_window,
15-
)
16-
from autogpt.memory_management.summary_memory import (
17-
get_newly_trimmed_messages,
18-
update_running_summary,
19-
)
2013

2114
cfg = Config()
2215

@@ -153,6 +146,10 @@ def chat_with_ai(
153146

154147
# Move to the next most recent message in the full message history
155148
next_message_to_add_index -= 1
149+
from autogpt.memory_management.summary_memory import (
150+
get_newly_trimmed_messages,
151+
update_running_summary,
152+
)
156153

157154
# Insert Memories
158155
if len(full_message_history) > 0:
@@ -164,7 +161,9 @@ def chat_with_ai(
164161
current_context=current_context,
165162
last_memory_index=agent.last_memory_index,
166163
)
164+
167165
agent.summary_memory = update_running_summary(
166+
agent,
168167
current_memory=agent.summary_memory,
169168
new_events=newly_trimmed_messages,
170169
)
@@ -237,7 +236,7 @@ def chat_with_ai(
237236
agent.created_at,
238237
agent.cycle_count,
239238
current_context,
240-
PROMPT_NEXT_ACTION_FILE_NAME,
239+
CURRENT_CONTEXT_FILE_NAME,
241240
)
242241

243242
# TODO: use a model defined elsewhere, so that model can contain

autogpt/log_cycle/log_cycle.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
DEFAULT_PREFIX = "agent"
88
FULL_MESSAGE_HISTORY_FILE_NAME = "full_message_history.json"
9-
PROMPT_NEXT_ACTION_FILE_NAME = "prompt_next_action.json"
9+
CURRENT_CONTEXT_FILE_NAME = "current_context.json"
1010
NEXT_ACTION_FILE_NAME = "next_action.json"
11+
PROMPT_SUMMARY_FILE_NAME = "prompt_summary.json"
12+
SUMMARY_FILE_NAME = "summary.txt"
1113

1214

1315
class LogCycleHandler:

autogpt/memory_management/summary_memory.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import json
33
from typing import Dict, List, Tuple
44

5+
from autogpt.agent import Agent
56
from autogpt.config import Config
67
from autogpt.llm.llm_utils import create_chat_completion
8+
from autogpt.log_cycle.log_cycle import PROMPT_SUMMARY_FILE_NAME, SUMMARY_FILE_NAME
79

810
cfg = Config()
911

@@ -46,7 +48,7 @@ def get_newly_trimmed_messages(
4648

4749

4850
def update_running_summary(
49-
current_memory: str, new_events: List[Dict[str, str]]
51+
agent: Agent, current_memory: str, new_events: List[Dict[str, str]]
5052
) -> str:
5153
"""
5254
This function takes a list of dictionaries representing new events and combines them with the current summary,
@@ -110,9 +112,24 @@ def update_running_summary(
110112
"content": prompt,
111113
}
112114
]
115+
agent.log_cycle_handler.log_cycle(
116+
agent.config.ai_name,
117+
agent.created_at,
118+
agent.cycle_count,
119+
messages,
120+
PROMPT_SUMMARY_FILE_NAME,
121+
)
113122

114123
current_memory = create_chat_completion(messages, cfg.fast_llm_model)
115124

125+
agent.log_cycle_handler.log_cycle(
126+
agent.config.ai_name,
127+
agent.created_at,
128+
agent.cycle_count,
129+
current_memory,
130+
SUMMARY_FILE_NAME,
131+
)
132+
116133
message_to_return = {
117134
"role": "system",
118135
"content": f"This reminds you of these events from your past: \n{current_memory}",

0 commit comments

Comments
 (0)