Skip to content

Commit

Permalink
Fix class names used in persistence manager logging (#503)
Browse files Browse the repository at this point in the history
* Fix class names used in persistence manager logging

Signed-off-by: Claudio Cambra <[email protected]>

* Use self.__class__.__name__ for logging in different persistence managers

Signed-off-by: Claudio Cambra <[email protected]>

---------

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra authored Nov 29, 2023
1 parent 42eb680 commit 6f22687
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions memgpt/persistence_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,28 +77,28 @@ 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)

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)

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


Expand Down Expand Up @@ -146,12 +146,12 @@ def save(self, filename):
printd(f"Saved state to {fh}")

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
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)
Expand All @@ -166,28 +166,28 @@ 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)

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)

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


Expand All @@ -199,12 +199,12 @@ 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 {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)

Expand All @@ -228,12 +228,12 @@ def save(self, _filename):
raise NotImplementedError

def init(self, agent):
print(f"Initializing InMemoryStateManager 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)
Expand Down

0 comments on commit 6f22687

Please sign in to comment.