From d441794b8e5fdf589babb51dbbe0883bd5078c6a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 24 Nov 2023 11:11:46 +0800 Subject: [PATCH 1/2] Fix class names used in persistence manager logging Signed-off-by: Claudio Cambra --- memgpt/persistence_manager.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/memgpt/persistence_manager.py b/memgpt/persistence_manager.py index 7899a5905a..31e72286be 100644 --- a/memgpt/persistence_manager.py +++ b/memgpt/persistence_manager.py @@ -146,7 +146,7 @@ def save(self, filename): printd(f"Saved state to {fh}") def init(self, agent): - printd(f"Initializing InMemoryStateManager with agent object") + printd(f"Initializing LocalStateManager with agent object") self.all_messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.memory = agent.memory @@ -199,7 +199,7 @@ def __init__(self, archival_memory_db): self.archival_memory_db = archival_memory_db def init(self, agent): - print(f"Initializing InMemoryStateManager with agent object") + print(f"Initializing InMemoryStateManagerWithPreloadedArchivalMemory with agent object") self.all_messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.memory = agent.memory @@ -228,7 +228,7 @@ def save(self, _filename): raise NotImplementedError def init(self, agent): - print(f"Initializing InMemoryStateManager with agent object") + print(f"Initializing InMemoryStateManagerWithFaiss with agent object") self.all_messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.memory = agent.memory From ec2be310a93928c71b32f6168ecb8cdd64075ffe Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 29 Nov 2023 14:05:02 +0800 Subject: [PATCH 2/2] Use self.__class__.__name__ for logging in different persistence managers Signed-off-by: Claudio Cambra --- memgpt/persistence_manager.py | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/memgpt/persistence_manager.py b/memgpt/persistence_manager.py index 31e72286be..8efd74ac40 100644 --- a/memgpt/persistence_manager.py +++ b/memgpt/persistence_manager.py @@ -57,7 +57,7 @@ def save(self, filename): pickle.dump(self, fh, protocol=pickle.HIGHEST_PROTOCOL) def init(self, agent): - printd(f"Initializing InMemoryStateManager with agent object") + printd(f"Initializing {self.__class__.__name__} with agent object") self.all_messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.memory = agent.memory @@ -77,7 +77,7 @@ def prepend_to_messages(self, added_messages): # first tag with timestamps added_messages = [{"timestamp": get_local_time(), "message": msg} for msg in added_messages] - printd(f"InMemoryStateManager.prepend_to_message") + printd(f"{self.__class__.__name__}.prepend_to_message") self.messages = [self.messages[0]] + added_messages + self.messages[1:] self.all_messages.extend(added_messages) @@ -85,7 +85,7 @@ def append_to_messages(self, added_messages): # first tag with timestamps added_messages = [{"timestamp": get_local_time(), "message": msg} for msg in added_messages] - printd(f"InMemoryStateManager.append_to_messages") + printd(f"{self.__class__.__name__}.append_to_messages") self.messages = self.messages + added_messages self.all_messages.extend(added_messages) @@ -93,12 +93,12 @@ def swap_system_message(self, new_system_message): # first tag with timestamps new_system_message = {"timestamp": get_local_time(), "message": new_system_message} - printd(f"InMemoryStateManager.swap_system_message") + printd(f"{self.__class__.__name__}.swap_system_message") self.messages[0] = new_system_message self.all_messages.append(new_system_message) def update_memory(self, new_memory): - printd(f"InMemoryStateManager.update_memory") + printd(f"{self.__class__.__name__}.update_memory") self.memory = new_memory @@ -146,12 +146,12 @@ def save(self, filename): printd(f"Saved state to {fh}") def init(self, agent): - printd(f"Initializing LocalStateManager with agent object") + printd(f"Initializing {self.__class__.__name__} with agent object") self.all_messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.memory = agent.memory - printd(f"InMemoryStateManager.all_messages.len = {len(self.all_messages)}") - printd(f"InMemoryStateManager.messages.len = {len(self.messages)}") + printd(f"{self.__class__.__name__}.all_messages.len = {len(self.all_messages)}") + printd(f"{self.__class__.__name__}.messages.len = {len(self.messages)}") # Persistence manager also handles DB-related state self.recall_memory = self.recall_memory_cls(message_database=self.all_messages) @@ -166,7 +166,7 @@ def prepend_to_messages(self, added_messages): # first tag with timestamps added_messages = [{"timestamp": get_local_time(), "message": msg} for msg in added_messages] - printd(f"InMemoryStateManager.prepend_to_message") + printd(f"{self.__class__.__name__}.prepend_to_message") self.messages = [self.messages[0]] + added_messages + self.messages[1:] self.all_messages.extend(added_messages) @@ -174,7 +174,7 @@ def append_to_messages(self, added_messages): # first tag with timestamps added_messages = [{"timestamp": get_local_time(), "message": msg} for msg in added_messages] - printd(f"InMemoryStateManager.append_to_messages") + printd(f"{self.__class__.__name__}.append_to_messages") self.messages = self.messages + added_messages self.all_messages.extend(added_messages) @@ -182,12 +182,12 @@ def swap_system_message(self, new_system_message): # first tag with timestamps new_system_message = {"timestamp": get_local_time(), "message": new_system_message} - printd(f"InMemoryStateManager.swap_system_message") + printd(f"{self.__class__.__name__}.swap_system_message") self.messages[0] = new_system_message self.all_messages.append(new_system_message) def update_memory(self, new_memory): - printd(f"InMemoryStateManager.update_memory") + printd(f"{self.__class__.__name__}.update_memory") self.memory = new_memory @@ -199,12 +199,12 @@ def __init__(self, archival_memory_db): self.archival_memory_db = archival_memory_db def init(self, agent): - print(f"Initializing InMemoryStateManagerWithPreloadedArchivalMemory with agent object") + print(f"Initializing {self.__class__.__name__} with agent object") self.all_messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.memory = agent.memory - print(f"InMemoryStateManager.all_messages.len = {len(self.all_messages)}") - print(f"InMemoryStateManager.messages.len = {len(self.messages)}") + print(f"{self.__class__.__name__}.all_messages.len = {len(self.all_messages)}") + print(f"{self.__class__.__name__}.messages.len = {len(self.messages)}") self.recall_memory = self.recall_memory_cls(message_database=self.all_messages) self.archival_memory = self.archival_memory_cls(archival_memory_database=self.archival_memory_db) @@ -228,12 +228,12 @@ def save(self, _filename): raise NotImplementedError def init(self, agent): - print(f"Initializing InMemoryStateManagerWithFaiss with agent object") + print(f"Initializing {self.__class__.__name__} with agent object") self.all_messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.messages = [{"timestamp": get_local_time(), "message": msg} for msg in agent.messages.copy()] self.memory = agent.memory - print(f"InMemoryStateManager.all_messages.len = {len(self.all_messages)}") - print(f"InMemoryStateManager.messages.len = {len(self.messages)}") + print(f"{self.__class__.__name__}.all_messages.len = {len(self.all_messages)}") + print(f"{self.__class__.__name__}.messages.len = {len(self.messages)}") # Persistence manager also handles DB-related state self.recall_memory = self.recall_memory_cls(message_database=self.all_messages)