Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: improve CLI appearance (#687)
Charles Packer3482a196d6e6
diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.pyindex 5e27a085f..2417bfca1 100644--- a/memgpt/cli/cli.py+++ b/memgpt/cli/cli.py@@ -17,7 +17,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, open_folder_in_explorer+from memgpt.utils import printd, open_folder_in_explorer, suppress_stdoutfrom memgpt.persistence_manager import LocalStateManagerfrom memgpt.config import MemGPTConfig, AgentConfigfrom memgpt.constants import MEMGPT_DIR, CLI_WARNING_PREFIX@@ -315,6 +315,7 @@ def run("openai": "Use OpenAI (requires an OpenAI API key)","other": "Other (OpenAI Azure, custom LLM endpoint, etc)",}+ print()config_selection = questionary.select("How would you like to set up MemGPT?",choices=list(config_choices.values()),@@ -322,9 +323,11 @@ def run().ask()if config_selection == config_choices["memgpt"]:+ print()MemGPTConfig.create_config_dir()quickstart(backend=QuickstartChoice.memgpt_hosted, debug=debug, terminal=False, latest=False)elif config_selection == config_choices["openai"]:+ print()MemGPTConfig.create_config_dir()quickstart(backend=QuickstartChoice.openai, debug=debug, terminal=False, latest=False)elif config_selection == config_choices["other"]:@@ -357,6 +360,7 @@ def run(agents = [AgentConfig.load(f).name for f in agent_files]if len(agents) > 0 and not any([persona, human, model]):+ print()select_agent = questionary.confirm("Would you like to select an existing agent?").ask()if select_agent:agent = questionary.select("Select agent:", choices=agents).ask()@@ -372,7 +376,7 @@ def run(# create agent configif agent and AgentConfig.exists(agent): # use existing agent- typer.secho(f"Using existing agent {agent}", fg=typer.colors.GREEN)+ typer.secho(f"\n🔁 Using existing agent {agent}", fg=typer.colors.GREEN)agent_config = AgentConfig.load(agent)printd("State path:", agent_config.save_state_dir())printd("Persistent manager path:", agent_config.save_persistence_manager_dir())@@ -420,11 +424,14 @@ def run(# Update the agent config with any overridesagent_config.save()- # load existing agent- memgpt_agent = Agent.load_agent(interface, agent_config)+ # Supress llama-index noise+ with suppress_stdout():+ # load existing agent+ memgpt_agent = Agent.load_agent(interface, agent_config)+else: # create new agent# create new agent config: override defaults with args if provided- typer.secho("Creating new agent...", fg=typer.colors.GREEN)+ typer.secho("\n🧬 Creating new agent...", fg=typer.colors.WHITE)agent_config = AgentConfig(name=agent,persona=persona,@@ -437,12 +444,16 @@ def run(context_window=context_window,)- # TODO: allow configrable state manager (only local is supported right now)- persistence_manager = LocalStateManager(agent_config) # TODO: insert dataset/pre-fill-# save new agent configagent_config.save()- typer.secho(f"Created new agent {agent_config.name}.", fg=typer.colors.GREEN)+ typer.secho(f"-> 🤖 Using persona profile '{agent_config.persona}'", fg=typer.colors.WHITE)+ typer.secho(f"-> 🧑 Using human profile '{agent_config.human}'", fg=typer.colors.WHITE)+ typer.secho(f"🎉 Created new agent '{agent_config.name}'", fg=typer.colors.GREEN)++ # Supress llama-index noise+ with suppress_stdout():+ # TODO: allow configrable state manager (only local is supported right now)+ persistence_manager = LocalStateManager(agent_config) # TODO: insert dataset/pre-fill# create agentmemgpt_agent = presets.use_preset(@@ -461,6 +472,7 @@ def run(# start event loopfrom memgpt.main import run_agent_loop+ print() # extra spacerun_agent_loop(memgpt_agent, first, no_verify, config) # TODO: add back no_verifydiff --git a/memgpt/config.py b/memgpt/config.pyindex 63c5fc1c1..85a92b929 100644--- a/memgpt/config.py+++ b/memgpt/config.py@@ -84,6 +84,9 @@ class MemGPTConfig:# version (for backcompat)memgpt_version: str = None+ # user info+ policies_accepted: bool = False+def __post_init__(self):# ensure typesself.embedding_chunk_size = int(self.embedding_chunk_size)diff --git a/memgpt/utils.py b/memgpt/utils.pyindex 9c3b5ed79..368866fa1 100644--- a/memgpt/utils.py+++ b/memgpt/utils.py@@ -4,7 +4,9 @@ import osimport pickleimport platformimport subprocess-+import sys+import io+from contextlib import contextmanagerimport difflibimport demjson3 as demjson@@ -21,6 +23,18 @@ from memgpt.openai_backcompat.openai_object import OpenAIObjectDEBUG = False+@contextmanager+def suppress_stdout():+ """Used to temporarily stop stdout (eg for the 'MockLLM' message)"""+ new_stdout = io.StringIO()+ old_stdout = sys.stdout+ sys.stdout = new_stdout+ try:+ yield+ finally:+ sys.stdout = old_stdout++def open_folder_in_explorer(folder_path):"""Opens the specified folder in the system's native file explorer.