Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
Deprecate list_loaded_data for listing sources, and use metadata DB instead
Sarah Wooders5b991988f6f6
diff --git a/memgpt/autogen/memgpt_agent.py b/memgpt/autogen/memgpt_agent.pyindex 3571850d6..db47ecda7 100644--- a/memgpt/autogen/memgpt_agent.py+++ b/memgpt/autogen/memgpt_agent.py@@ -12,7 +12,7 @@ import memgpt.presets.presets as presetsfrom memgpt.config import AgentConfig, MemGPTConfigfrom memgpt.cli.cli import attachfrom memgpt.cli.cli_load import load_directory, load_webpage, load_index, load_database, load_vector_database-from memgpt.connectors.storage import StorageConnector+from memgpt.connectors.storage import StorageConnector, TableTypedef create_memgpt_autogen_agent_from_config(@@ -240,7 +240,9 @@ class MemGPTAgent(ConversableAgent):def load_and_attach(self, name: str, type: str, force=False, **kwargs):# check if data source already exists- if name in StorageConnector.list_loaded_data() and not force:+ data_sources = StorageConnector.get_metadata_storage_connector(TableType.DATA_SOURCES).get_all()+ data_sources = [source.name for source in data_sources]+ if name in data_sources and not force:print(f"Data source {name} already exists. Use force=True to overwrite.")self.attach(name)else:diff --git a/memgpt/cli/cli_config.py b/memgpt/cli/cli_config.pyindex 533bfb7df..df9991063 100644--- a/memgpt/cli/cli_config.py+++ b/memgpt/cli/cli_config.py@@ -542,17 +542,19 @@ def list(option: str):elif option == "sources":"""List all data sources"""conn = StorageConnector.get_metadata_storage_connector(table_type=TableType.DATA_SOURCES) # already filters by user+ passage_conn = StorageConnector.get_storage_connector(table_type=TableType.PASSAGES)# create tabletable = PrettyTable()- table.field_names = ["Name", "Created At", "Agents"]+ table.field_names = ["Name", "Created At", "Number of Passages", "Agents"]# TODO: eventually look accross all storage connections# TODO: add data source stats# TODO: connect to agents# get all sourcesfor data_source in conn.get_all():- table.add_row([data_source.name, data_source.created_at, ""])+ num_passages = passage_conn.size({"data_source": data_source.name})+ table.add_row([data_source.name, data_source.created_at, num_passages, ""])print(table)else:raise ValueError(f"Unknown option {option}")diff --git a/memgpt/connectors/chroma.py b/memgpt/connectors/chroma.pyindex 6deef1d54..09622abce 100644--- a/memgpt/connectors/chroma.py+++ b/memgpt/connectors/chroma.py@@ -193,13 +193,3 @@ class ChromaStorageConnector(StorageConnector):# count = len(results) if count is None else count# results = results[start : start + count]# return self.results_to_records(results)-- @staticmethod- def list_loaded_data(user_id: Optional[str] = None):- if user_id is None:- config = MemGPTConfig.load()- user_id = config.anon_clientid-- # get all collections- # TODO: implement this- passdiff --git a/memgpt/connectors/db.py b/memgpt/connectors/db.pyindex 926b15410..8ac6ba30d 100644--- a/memgpt/connectors/db.py+++ b/memgpt/connectors/db.py@@ -258,17 +258,6 @@ class SQLStorageConnector(StorageConnector):unique_data_sources = session.query(self.db_model.data_source).filter(*self.filters).distinct().all()return unique_data_sources- @staticmethod- def list_loaded_data():- config = MemGPTConfig.load()- engine = create_engine(config.archival_storage_uri)- inspector = inspect(engine)- tables = inspector.get_table_names()- tables = [table for table in tables if table.startswith("memgpt_") and not table.startswith("memgpt_agent_")]- start_chars = len("memgpt_")- tables = [table[start_chars:] for table in tables]- return tables-def query_date(self, start_date, end_date):session = self.Session()filters = self.get_filters({})diff --git a/memgpt/connectors/storage.py b/memgpt/connectors/storage.pyindex f12f47270..b62fa67a4 100644--- a/memgpt/connectors/storage.py+++ b/memgpt/connectors/storage.py@@ -153,34 +153,6 @@ class StorageConnector:storage_type = MemGPTConfig.load().metadata_storage_typereturn StorageConnector.get_storage_connector(table_type, storage_type=storage_type)- @staticmethod- def list_loaded_data(storage_type: Optional[str] = None):- # TODO: modify this to simply list loaded data from a given user- if storage_type is None:- storage_type = MemGPTConfig.load().archival_storage_type-- return-- if storage_type == "local":- from memgpt.connectors.local import VectorIndexStorageConnector-- # TODO: remove- return VectorIndexStorageConnector.list_loaded_data()- elif storage_type == "postgres":- from memgpt.connectors.db import PostgresStorageConnector-- return PostgresStorageConnector.list_loaded_data()- elif storage_type == "chroma":- from memgpt.connectors.chroma import ChromaStorageConnector-- return ChromaStorageConnector.list_loaded_data()- elif storage_type == "lancedb":- from memgpt.connectors.db import LanceDBConnector-- return LanceDBConnector.list_loaded_data()- else:- raise NotImplementedError(f"Storage type {storage_type} not implemented")-@abstractmethoddef get_filters(self, filters: Optional[Dict] = {}):passdiff --git a/memgpt/main.py b/memgpt/main.pyindex f8f94d3cc..cce9b4a38 100644--- a/memgpt/main.py+++ b/memgpt/main.py@@ -24,7 +24,7 @@ import memgpt.constants as constantsfrom memgpt.cli.cli import run, attach, versionfrom memgpt.cli.cli_config import configure, list, add, deletefrom memgpt.cli.cli_load import app as load_app-from memgpt.connectors.storage import StorageConnector+from memgpt.connectors.storage import StorageConnector, TableTypeapp = typer.Typer(pretty_exceptions_enable=False)app.command(name="run")(run)@@ -61,6 +61,7 @@ def run_agent_loop(memgpt_agent, first, no_verify=False, cfg=None, strip_ui=Falsprint()multiline_input = False+ metadata_db = StorageConnector.get_metadata_storage_connector(table_type=TableType.DATA_SOURCES) # already filters by userwhile True:if not skip_next_user_input and (counter > 0 or USER_GOES_FIRST):# Ask for user input@@ -98,7 +99,8 @@ def run_agent_loop(memgpt_agent, first, no_verify=False, cfg=None, strip_ui=Falscontinueelif user_input.lower() == "/attach":# TODO: check if agent already has it- data_source_options = StorageConnector.list_loaded_data()++ data_source_options = [row.name for row in metadata_db.get_all()]if len(data_source_options) == 0:typer.secho('No sources available. You must load a souce with "memgpt load ..." before running /attach.',diff --git a/memgpt/memory.py b/memgpt/memory.pyindex afd532d02..fd1645401 100644--- a/memgpt/memory.py+++ b/memgpt/memory.py@@ -1,6 +1,5 @@from abc import ABC, abstractmethodimport datetime-import refrom typing import Optional, List, Tuplefrom memgpt.constants import MESSAGE_SUMMARY_WARNING_FRAC@@ -8,9 +7,10 @@ from memgpt.utils import get_local_time, printd, count_tokens, validate_date_forfrom memgpt.prompts.gpt_summarize import SYSTEM as SUMMARY_PROMPT_SYSTEMfrom memgpt.openai_tools import createfrom memgpt.data_types import Message, Passage+from memgpt.config import MemGPTConfig+from memgpt.embeddings import embedding_modelfrom llama_index import Documentfrom llama_index.node_parser import SimpleNodeParser-from llama_index.node_parser import SimpleNodeParserclass CoreMemory(object):