🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
add `enable_longterm_memory` config
seehicf3b80d5f10c
diff --git a/config/config2.example.yaml b/config/config2.example.yamlindex 2a0ebcc47..1c0934567 100644--- a/config/config2.example.yaml+++ b/config/config2.example.yaml@@ -83,6 +83,8 @@ exp_pool:use_llm_ranker: true # Default is `true`, it will use LLM Reranker to get better result.collection_name: experience_pool # When `retrieval_type` is `chroma`, `collection_name` is the collection name in chromadb.+role_zero:+ enable_longterm_memory: false # Whether to use long-term memory.azure_tts_subscription_key: "YOUR_SUBSCRIPTION_KEY"azure_tts_region: "eastus"diff --git a/metagpt/config2.py b/metagpt/config2.pyindex 7b6ddf8c6..c328713c5 100644--- a/metagpt/config2.py+++ b/metagpt/config2.py@@ -19,6 +19,7 @@ from metagpt.configs.mermaid_config import MermaidConfigfrom metagpt.configs.omniparse_config import OmniParseConfigfrom metagpt.configs.redis_config import RedisConfigfrom metagpt.configs.role_custom_config import RoleCustomConfig+from metagpt.configs.role_zero_config import RoleZeroConfigfrom metagpt.configs.s3_config import S3Configfrom metagpt.configs.search_config import SearchConfigfrom metagpt.configs.workspace_config import WorkspaceConfig@@ -89,6 +90,9 @@ class Config(CLIParams, YamlModel):# Role's custom configurationroles: Optional[List[RoleCustomConfig]] = None+ # RoleZero's configuration+ role_zero: Optional[RoleZeroConfig] = None+omniparse: Optional[OmniParseConfig] = None@classmethoddiff --git a/metagpt/configs/role_zero_config.py b/metagpt/configs/role_zero_config.pynew file mode 100644index 000000000..27103ddf6--- /dev/null+++ b/metagpt/configs/role_zero_config.py@@ -0,0 +1,7 @@+from pydantic import Field++from metagpt.utils.yaml_model import YamlModel+++class RoleZeroConfig(YamlModel):+ enable_longterm_memory: bool = Field(default=False, description="Whether to use long-term memory.")diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.pyindex 466d87f5c..586e5345f 100644--- a/metagpt/roles/di/role_zero.py+++ b/metagpt/roles/di/role_zero.py@@ -92,7 +92,6 @@ class RoleZero(Role):command_rsp: str = "" # the raw string containing the commandscommands: list[dict] = [] # commands to be executedmemory_k: int = 200 # number of memories (messages) to use as historical context- enable_longterm_memory: bool = True # whether to use longterm memoryuse_fixed_sop: bool = Falserequirements_constraints: str = "" # the constraints in user requirementsuse_summary: bool = True # whether to summarize at the end@@ -168,14 +167,16 @@ class RoleZero(Role):@model_validator(mode="after")def set_longterm_memory(self) -> "RoleZero":- """Set longterm memory.+ """Set up long-term memory for the role if enabled in the configuration.- If enable_longterm_memory is True and longterm_memory is not set, set it.+ If `enable_longterm_memory` is True, set up long-term memory.The role name will be used as the collection name."""- if self.enable_longterm_memory:+ enable_longterm_memory = bool(self.config.role_zero and self.config.role_zero.enable_longterm_memory)+ if enable_longterm_memory:self.rc.memory = RoleZeroLongTermMemory(collection_name=self.name.replace(" ", ""), memory_k=self.memory_k)+ logger.info(f"Long-term memory set for role '{self.name}'")return self