Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

len needs to be implemented in all memory classes (#236)

Charles Packer250252f1053e
diff --git a/memgpt/memory.py b/memgpt/memory.py
index f9631b151..2e1bc7503 100644
--- a/memgpt/memory.py
+++ b/memgpt/memory.py
@@ -172,6 +172,11 @@ async def a_summarize_messages(
class ArchivalMemory(ABC):
+ @abstractmethod
+ def __len__(self):
+ """Define the length of the object. Must be implemented by subclasses."""
+ pass
+
@abstractmethod
def insert(self, memory_string):
"""Insert new archival memory
@@ -439,6 +444,11 @@ class DummyArchivalMemoryWithFaiss(DummyArchivalMemory):
class RecallMemory(ABC):
+ @abstractmethod
+ def __len__(self):
+ """Define the length of the object. Must be implemented by subclasses."""
+ pass
+
@abstractmethod
def text_search(self, query_string, count=None, start=None):
pass
@@ -680,6 +690,10 @@ class LocalArchivalMemory(ArchivalMemory):
# TODO: have some mechanism for cleanup otherwise will lead to OOM
self.cache = {}
+ def __len__(self):
+ # TODO FIXME
+ return 1
+
def save(self):
"""Save the index to disk"""
if self.agent_config.data_source: # update original archival index