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.

fix: resolve fatal attribute errors in pyright (#917)

Charles Packer82f339718ce8
diff --git a/memgpt/agent_store/chroma.py b/memgpt/agent_store/chroma.py
index 8b76e83cf..f99438634 100644
--- a/memgpt/agent_store/chroma.py
+++ b/memgpt/agent_store/chroma.py
@@ -224,3 +224,14 @@ class ChromaStorageConnector(StorageConnector):
# count = len(results) if count is None else count
# results = results[start : start + count]
# return self.results_to_records(results)
+
+ def get_all_cursor(
+ self,
+ filters: Optional[Dict] = {},
+ after: uuid.UUID = None,
+ before: uuid.UUID = None,
+ limit: Optional[int] = 1000,
+ order_by: str = "created_at",
+ reverse: bool = False,
+ ):
+ raise ValueError("Cannot run get_all_cursor with chroma")
diff --git a/memgpt/agent_store/db.py b/memgpt/agent_store/db.py
index 1d3495f60..f7f5e0204 100644
--- a/memgpt/agent_store/db.py
+++ b/memgpt/agent_store/db.py
@@ -433,10 +433,6 @@ class PostgresStorageConnector(SQLStorageConnector):
self.uri = self.config.recall_storage_uri
if self.config.recall_storage_uri is None:
raise ValueError(f"Must specifiy recall_storage_uri in config {self.config.config_path}")
- elif table_type == TableType.DATA_SOURCES:
- self.uri = self.config.metadata_storage_uri
- if self.config.metadata_storage_uri is None:
- raise ValueError(f"Must specifiy metadata_storage_uri in config {self.config.config_path}")
else:
raise ValueError(f"Table type {table_type} not implemented")
# create table
diff --git a/memgpt/agent_store/lancedb.py b/memgpt/agent_store/lancedb.py
index 2a69f33c9..274693dc1 100644
--- a/memgpt/agent_store/lancedb.py
+++ b/memgpt/agent_store/lancedb.py
@@ -34,7 +34,7 @@ def get_db_model(table_name: str, table_type: TableType):
doc_id: str
agent_id: str
data_source: str
- embedding: Vector(config.embedding_dim)
+ embedding: Vector(config.default_embedding_config.embedding_dim)
metadata_: Dict
def __repr__(self):
@@ -67,6 +67,7 @@ def get_db_model(table_name: str, table_type: TableType):
# openai info
role: str
+ name: str
text: str
model: str
user: str
@@ -76,7 +77,7 @@ def get_db_model(table_name: str, table_type: TableType):
function_args: str
function_response: str
- embedding = Vector(config.embedding_dim)
+ embedding = Vector(config.default_embedding_config.embedding_dim)
# Add a datetime column, with default value as the current time
created_at = datetime
@@ -102,25 +103,7 @@ def get_db_model(table_name: str, table_type: TableType):
"""Create database model for table_name"""
return MessageModel
- elif table_type == TableType.DATA_SOURCES:
-
- class SourceModel(LanceModel):
- """Defines data model for storing Passages (consisting of text, embedding)"""
-
- # Assuming passage_id is the primary key
- id: uuid.UUID
- user_id: str
- name: str
- created_at: datetime
-
- def __repr__(self):
- return f"<Source(passage_id='{self.id}', name='{self.name}')>"
- def to_record(self):
- return Source(id=self.id, user_id=self.user_id, name=self.name, created_at=self.created_at)
-
- """Create database model for table_name"""
- return SourceModel
else:
raise ValueError(f"Table type {table_type} not implemented")
diff --git a/memgpt/autogen/memgpt_agent.py b/memgpt/autogen/memgpt_agent.py
index 23545f220..e06f5bed6 100644
--- a/memgpt/autogen/memgpt_agent.py
+++ b/memgpt/autogen/memgpt_agent.py
@@ -387,6 +387,8 @@ def create_memgpt_autogen_agent_from_config(
Construct AutoGen config workflow in a clean way.
"""
+ if not isinstance(llm_config, dict):
+ llm_config = None
llm_config = llm_config["config_list"][0]
if interface_kwargs is None:
diff --git a/memgpt/cli/cli_load.py b/memgpt/cli/cli_load.py
index ba4b31c90..98343af43 100644
--- a/memgpt/cli/cli_load.py
+++ b/memgpt/cli/cli_load.py
@@ -44,7 +44,7 @@ def insert_passages_into_source(passages: List[Passage], source_name: str, user_
source = ms.get_source(user_id=user_id, source_name=source_name)
if not source:
# create new
- source = Source(user_id=user_id, name=source_name, created_at=get_utc_time())
+ source = Source(user_id=user_id, name=source_name)
ms.create_source(source)
# make sure user_id is set for passages
@@ -83,7 +83,6 @@ def store_docs(name, docs, user_id=None, show_progress=True):
data_source = Source(
user_id=user.id,
name=name,
- created_at=get_utc_time(),
embedding_model=config.default_embedding_config.embedding_model,
embedding_dim=config.default_embedding_config.embedding_dim,
)
diff --git a/memgpt/config.py b/memgpt/config.py
index 32aea9dd9..5aa8339d1 100644
--- a/memgpt/config.py
+++ b/memgpt/config.py
@@ -310,16 +310,34 @@ class AgentConfig:
self.persona = config.persona if persona is None else persona
self.human = config.human if human is None else human
self.preset = config.preset if preset is None else preset
- self.context_window = config.context_window if context_window is None else context_window
- self.model = config.model if model is None else model
- self.model_endpoint_type = config.model_endpoint_type if model_endpoint_type is None else model_endpoint_type
- self.model_endpoint = config.model_endpoint if model_endpoint is None else model_endpoint
- self.model_wrapper = config.model_wrapper if model_wrapper is None else model_wrapper
- self.embedding_endpoint_type = config.embedding_endpoint_type if embedding_endpoint_type is None else embedding_endpoint_type
- self.embedding_endpoint = config.embedding_endpoint if embedding_endpoint is None else embedding_endpoint
- self.embedding_model = config.embedding_model if embedding_model is None else embedding_model
- self.embedding_dim = config.embedding_dim if embedding_dim is None else embedding_dim
- self.embedding_chunk_size = config.embedding_chunk_size if embedding_chunk_size is None else embedding_chunk_size
+ self.context_window = config.default_llm_config.context_window if context_window is None else context_window
+ self.model = config.default_llm_config.model if model is None else model
+ self.model_endpoint_type = config.default_llm_config.model_endpoint_type if model_endpoint_type is None else model_endpoint_type
+ self.model_endpoint = config.default_llm_config.model_endpoint if model_endpoint is None else model_endpoint
+ self.model_wrapper = config.default_llm_config.model_wrapper if model_wrapper is None else model_wrapper
+ self.llm_config = LLMConfig(
+ model=self.model,
+ model_endpoint_type=self.model_endpoint_type,
+ model_endpoint=self.model_endpoint,
+ model_wrapper=self.model_wrapper,
+ context_window=self.context_window,
+ )
+ self.embedding_endpoint_type = (
+ config.default_embedding_config.embedding_endpoint_type if embedding_endpoint_type is None else embedding_endpoint_type
+ )
+ self.embedding_endpoint = config.default_embedding_config.embedding_endpoint if embedding_endpoint is None else embedding_endpoint
+ self.embedding_model = config.default_embedding_config.embedding_model if embedding_model is None else embedding_model
+ self.embedding_dim = config.default_embedding_config.embedding_dim if embedding_dim is None else embedding_dim
+ self.embedding_chunk_size = (
+ config.default_embedding_config.embedding_chunk_size if embedding_chunk_size is None else embedding_chunk_size
+ )
+ self.embedding_config = EmbeddingConfig(
+ embedding_endpoint_type=self.embedding_endpoint_type,
+ embedding_endpoint=self.embedding_endpoint,
+ embedding_model=self.embedding_model,
+ embedding_dim=self.embedding_dim,
+ embedding_chunk_size=self.embedding_chunk_size,
+ )
# agent metadata
self.data_sources = data_sources if data_sources is not None else []
diff --git a/memgpt/data_types.py b/memgpt/data_types.py
index ea5bf5089..1f1fdc2ee 100644
--- a/memgpt/data_types.py
+++ b/memgpt/data_types.py
@@ -69,7 +69,7 @@ class Message(Record):
text: str,
model: Optional[str] = None, # model used to make function call
name: Optional[str] = None, # optional participant name
- created_at: Optional[str] = None,
+ created_at: Optional[datetime] = None,
tool_calls: Optional[List[ToolCall]] = None, # list of tool calls requested
tool_call_id: Optional[str] = None,
embedding: Optional[np.ndarray] = None,
@@ -82,7 +82,7 @@ class Message(Record):
self.agent_id = agent_id
self.text = text
self.model = model # model name (e.g. gpt-4)
- self.created_at = get_utc_time() if created_at is None else created_at
+ self.created_at = created_at if created_at is not None else datetime.now()
# openai info
assert role in ["system", "assistant", "user", "tool"]
@@ -486,7 +486,7 @@ class Source:
self.name = name
self.user_id = user_id
- self.created_at = created_at
+ self.created_at = created_at if created_at is not None else datetime.now()
# embedding info (optional)
self.embedding_dim = embedding_dim
diff --git a/memgpt/embeddings.py b/memgpt/embeddings.py
index a9c89e9c0..2ef5c8bfc 100644
--- a/memgpt/embeddings.py
+++ b/memgpt/embeddings.py
@@ -29,6 +29,7 @@ def check_and_split_text(text: str, embedding_model: str) -> List[str]:
# determine max length
if hasattr(encoding, "max_length"):
+ # TODO(fix) this is broken
max_length = encoding.max_length
else:
# TODO: figure out the real number
diff --git a/memgpt/interface.py b/memgpt/interface.py
index e217ef504..bf57d2f1f 100644
--- a/memgpt/interface.py
+++ b/memgpt/interface.py
@@ -38,6 +38,21 @@ class AgentInterface(ABC):
"""MemGPT calls a function"""
raise NotImplementedError
+ # @abstractmethod
+ # @staticmethod
+ # def print_messages():
+ # raise NotImplementedError
+
+ # @abstractmethod
+ # @staticmethod
+ # def print_messages_raw():
+ # raise NotImplementedError
+
+ # @abstractmethod
+ # @staticmethod
+ # def step_yield():
+ # raise NotImplementedError
+
class CLIInterface(AgentInterface):
"""Basic interface for dumping agent events to the command-line"""
diff --git a/memgpt/migrate.py b/memgpt/migrate.py
index 09c2f34eb..19b1347df 100644
--- a/memgpt/migrate.py
+++ b/memgpt/migrate.py
@@ -50,7 +50,7 @@ def wipe_config_and_reconfigure(data_dir: str = MEMGPT_DIR, run_configure=True):
os.makedirs(os.path.join(data_dir, MIGRATION_BACKUP_FOLDER, "agents"))
# Get the current timestamp in a readable format (e.g., YYYYMMDD_HHMMSS)
- timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
# Construct the new backup directory name with the timestamp
backup_filename = os.path.join(data_dir, MIGRATION_BACKUP_FOLDER, f"config_backup_{timestamp}")
diff --git a/memgpt/server/server.py b/memgpt/server/server.py
index 0f1fd1de8..bbcbcfffa 100644
--- a/memgpt/server/server.py
+++ b/memgpt/server/server.py
@@ -362,24 +362,7 @@ class SyncServer(LockingServer):
except:
raise ValueError(command)
- # TODO: check if agent already has it
- data_source_options = StorageConnector.list_loaded_data()
- if len(data_source_options) == 0:
- raise ValueError('No sources available. You must load a souce with "memgpt load ..." before running /attach.')
- elif data_source not in data_source_options:
- raise ValueError(f"Invalid data source name: {data_source} (options={data_source_options})")
- else:
- # attach new data
- attach(memgpt_agent.agent_state.name, data_source)
-
- # update agent config
- memgpt_agent.agent_state.attach_data_source(data_source)
-
- # reload agent with new data source
- # TODO: maybe make this less ugly...
- memgpt_agent.persistence_manager.archival_memory.storage = StorageConnector.get_storage_connector(
- agent_config=memgpt_agent.agent_state
- )
+ attach(agent_name=memgpt_agent.agent_state.name, data_source=data_source, user_id=user_id)
elif command.lower() == "dump" or command.lower().startswith("dump "):
# Check if there's an additional argument that's an integer
diff --git a/memgpt/utils.py b/memgpt/utils.py
index 5c94b9613..7b599b327 100644
--- a/memgpt/utils.py
+++ b/memgpt/utils.py
@@ -945,7 +945,7 @@ def get_schema_diff(schema_a, schema_b):
def validate_date_format(date_str):
"""Validate the given date string in the format 'YYYY-MM-DD'."""
try:
- datetime.datetime.strptime(date_str, "%Y-%m-%d")
+ datetime.strptime(date_str, "%Y-%m-%d")
return True
except (ValueError, TypeError):
return False