Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: added memgpt folder command (#632)
Charles Packer569bc7da31d6
diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.pyindex 7cc2d58d5..9ad3adf24 100644--- a/memgpt/cli/cli.py+++ b/memgpt/cli/cli.py@@ -16,7 +16,7 @@ from memgpt.interface import CLIInterface as interface # for printing to terminfrom memgpt.cli.cli_config import configureimport memgpt.presets.presets as presetsimport memgpt.utils as utils-from memgpt.utils import printd+from memgpt.utils import printd, open_folder_in_explorerfrom memgpt.persistence_manager import LocalStateManagerfrom memgpt.config import MemGPTConfig, AgentConfigfrom memgpt.constants import MEMGPT_DIR, CLI_WARNING_PREFIX@@ -25,6 +25,15 @@ from memgpt.embeddings import embedding_modelfrom memgpt.server.constants import WS_DEFAULT_PORT, REST_DEFAULT_PORT+def open_folder():+ """Open a folder viewer of the MemGPT home directory"""+ try:+ print(f"Opening home folder: {MEMGPT_DIR}")+ open_folder_in_explorer(MEMGPT_DIR)+ except Exception as e:+ print(f"Failed to open folder with system viewer, error:\n{e}")++class ServerChoice(Enum):rest_api = "rest"ws_api = "websocket"diff --git a/memgpt/main.py b/memgpt/main.pyindex 01dd947c5..8bc3e00e3 100644--- a/memgpt/main.py+++ b/memgpt/main.py@@ -21,7 +21,7 @@ from memgpt.interface import CLIInterface as interface # for printing to terminimport memgpt.agent as agentimport memgpt.system as systemimport memgpt.constants as constants-from memgpt.cli.cli import run, attach, version, server+from memgpt.cli.cli import run, attach, version, server, open_folderfrom memgpt.cli.cli_config import configure, list, addfrom memgpt.cli.cli_load import app as load_appfrom memgpt.connectors.storage import StorageConnector@@ -34,6 +34,7 @@ app.command(name="configure")(configure)app.command(name="list")(list)app.command(name="add")(add)app.command(name="server")(server)+app.command(name="folder")(open_folder)# load data commandsapp.add_typer(load_app, name="load")diff --git a/memgpt/utils.py b/memgpt/utils.pyindex d84c7f524..ec62bd439 100644--- a/memgpt/utils.py+++ b/memgpt/utils.py@@ -2,6 +2,9 @@ from datetime import datetimeimport jsonimport osimport pickle+import platform+import subprocess+import difflibimport demjson3 as demjson@@ -18,6 +21,32 @@ from memgpt.openai_backcompat.openai_object import OpenAIObjectDEBUG = False+def open_folder_in_explorer(folder_path):+ """+ Opens the specified folder in the system's native file explorer.++ :param folder_path: Absolute path to the folder to be opened.+ """+ if not os.path.exists(folder_path):+ raise ValueError(f"The specified folder {folder_path} does not exist.")++ # Determine the operating system+ os_name = platform.system()++ # Open the folder based on the operating system+ if os_name == "Windows":+ # Windows: use 'explorer' command+ subprocess.run(["explorer", folder_path], check=True)+ elif os_name == "Darwin":+ # macOS: use 'open' command+ subprocess.run(["open", folder_path], check=True)+ elif os_name == "Linux":+ # Linux: use 'xdg-open' command (works for most Linux distributions)+ subprocess.run(["xdg-open", folder_path], check=True)+ else:+ raise OSError(f"Unsupported operating system {os_name}.")++# Custom unpicklerclass OpenAIBackcompatUnpickler(pickle.Unpickler):def find_class(self, module, name):