Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: decrease number of saves to MemGPTConfig (#943)
tombedore6554b149c29
diff --git a/memgpt/cli/cli.py b/memgpt/cli/cli.pyindex 8a778933c..fa5c4ef6c 100644--- a/memgpt/cli/cli.py+++ b/memgpt/cli/cli.py@@ -55,8 +55,15 @@ def str_to_quickstart_choice(choice_str: str) -> QuickstartChoice:raise ValueError(f"{choice_str} is not a valid QuickstartChoice. Valid options are: {valid_options}")-def set_config_with_dict(new_config: dict) -> bool:- """Set the base config using a dict"""+def set_config_with_dict(new_config: dict) -> (MemGPTConfig, bool):+ """_summary_++ Args:+ new_config (dict): Dict of new config values++ Returns:+ new_config MemGPTConfig, modified (bool): Returns the new config and a boolean indicating if the config was modified+ """from memgpt.utils import printdold_config = MemGPTConfig.load()@@ -93,32 +100,7 @@ def set_config_with_dict(new_config: dict) -> bool:else:printd(f"Skipping new config {k}: {v} == {new_config[k]}")- if modified:- printd(f"Saving new config file.")- old_config.save()- typer.secho(f"π MemGPT configuration file updated!", fg=typer.colors.GREEN)- typer.secho(- "\n".join(- [- f"π§ model\t-> {old_config.default_llm_config.model}",- f"π₯οΈ endpoint\t-> {old_config.default_llm_config.model_endpoint}",- ]- ),- fg=typer.colors.GREEN,- )- return True- else:- typer.secho(f"π MemGPT configuration file unchanged.", fg=typer.colors.WHITE)- typer.secho(- "\n".join(- [- f"π§ model\t-> {old_config.default_llm_config.model}",- f"π₯οΈ endpoint\t-> {old_config.default_llm_config.model_endpoint}",- ]- ),- fg=typer.colors.WHITE,- )- return False+ return (old_config, modified)def quickstart(@@ -127,7 +109,10 @@ def quickstart(debug: Annotated[bool, typer.Option(help="Use --debug to enable debugging output")] = False,terminal: bool = True,):- """Set the base config file with a single command"""+ """Set the base config file with a single command++ This function and `configure` should be the ONLY places where MemGPTConfig.save() is called.+ """# setup loggerutils.DEBUG = debug@@ -154,7 +139,7 @@ def quickstart(config = response.json()# Output a success message and the first few items in the dictionary as a sampleprintd("JSON config file downloaded successfully.")- config_was_modified = set_config_with_dict(config)+ new_config, config_was_modified = set_config_with_dict(config)else:typer.secho(f"Failed to download config from {url}. Status code: {response.status_code}", fg=typer.colors.RED)@@ -165,7 +150,7 @@ def quickstart(with open(backup_config_path, "r", encoding="utf-8") as file:backup_config = json.load(file)printd("Loaded backup config file successfully.")- config_was_modified = set_config_with_dict(backup_config)+ new_config, config_was_modified = set_config_with_dict(backup_config)except FileNotFoundError:typer.secho(f"Backup config file not found at {backup_config_path}", fg=typer.colors.RED)return@@ -177,7 +162,7 @@ def quickstart(with open(backup_config_path, "r", encoding="utf-8") as file:backup_config = json.load(file)printd("Loaded config file successfully.")- config_was_modified = set_config_with_dict(backup_config)+ new_config, config_was_modified = set_config_with_dict(backup_config)except FileNotFoundError:typer.secho(f"Config file not found at {backup_config_path}", fg=typer.colors.RED)return@@ -203,7 +188,7 @@ def quickstart(config = response.json()# Output a success message and the first few items in the dictionary as a sampleprint("JSON config file downloaded successfully.")- config_was_modified = set_config_with_dict(config)+ new_config, config_was_modified = set_config_with_dict(config)else:typer.secho(f"Failed to download config from {url}. Status code: {response.status_code}", fg=typer.colors.RED)@@ -214,7 +199,7 @@ def quickstart(with open(backup_config_path, "r", encoding="utf-8") as file:backup_config = json.load(file)printd("Loaded backup config file successfully.")- config_was_modified = set_config_with_dict(backup_config)+ new_config, config_was_modified = set_config_with_dict(backup_config)except FileNotFoundError:typer.secho(f"Backup config file not found at {backup_config_path}", fg=typer.colors.RED)return@@ -226,7 +211,7 @@ def quickstart(with open(backup_config_path, "r", encoding="utf-8") as file:backup_config = json.load(file)printd("Loaded config file successfully.")- config_was_modified = set_config_with_dict(backup_config)+ new_config, config_was_modified = set_config_with_dict(backup_config)except FileNotFoundError:typer.secho(f"Config file not found at {backup_config_path}", fg=typer.colors.RED)return@@ -234,6 +219,31 @@ def quickstart(else:raise NotImplementedError(backend)+ if config_was_modified:+ printd(f"Saving new config file.")+ new_config.save()+ typer.secho(f"π MemGPT configuration file updated!", fg=typer.colors.GREEN)+ typer.secho(+ "\n".join(+ [+ f"π§ model\t-> {new_config.default_llm_config.model}",+ f"π₯οΈ endpoint\t-> {new_config.default_llm_config.model_endpoint}",+ ]+ ),+ fg=typer.colors.GREEN,+ )+ else:+ typer.secho(f"π MemGPT configuration file unchanged.", fg=typer.colors.WHITE)+ typer.secho(+ "\n".join(+ [+ f"π§ model\t-> {new_config.default_llm_config.model}",+ f"π₯οΈ endpoint\t-> {new_config.default_llm_config.model_endpoint}",+ ]+ ),+ fg=typer.colors.WHITE,+ )+# 'terminal' = quickstart was run alone, in which case we should guide the user on the next commandif terminal:if config_was_modified:diff --git a/memgpt/cli/cli_config.py b/memgpt/cli/cli_config.pyindex ed141bfbb..afc4b8620 100644--- a/memgpt/cli/cli_config.py+++ b/memgpt/cli/cli_config.py@@ -571,7 +571,10 @@ def configure_recall_storage(config: MemGPTConfig, credentials: MemGPTCredential@app.command()def configure():- """Updates default MemGPT configurations"""+ """Updates default MemGPT configurations++ This function and quickstart should be the ONLY place where MemGPTConfig.save() is called+ """# check credentialscredentials = MemGPTCredentials.load()diff --git a/memgpt/config.py b/memgpt/config.pyindex f950fa6df..c259fbb41 100644--- a/memgpt/config.py+++ b/memgpt/config.py@@ -185,7 +185,6 @@ class MemGPTConfig:anon_clientid = MemGPTConfig.generate_uuid()config = cls(anon_clientid=anon_clientid, config_path=config_path)config.create_config_dir() # create dirs- config.save() # save updated configreturn config