diff --git a/config/config2.example.yaml b/config/config2.example.yaml index 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.py index 7b6ddf8c6..c328713c5 100644 --- a/metagpt/config2.py +++ b/metagpt/config2.py @@ -19,6 +19,7 @@ from metagpt.configs.mermaid_config import MermaidConfig from metagpt.configs.omniparse_config import OmniParseConfig from metagpt.configs.redis_config import RedisConfig from metagpt.configs.role_custom_config import RoleCustomConfig +from metagpt.configs.role_zero_config import RoleZeroConfig from metagpt.configs.s3_config import S3Config from metagpt.configs.search_config import SearchConfig from metagpt.configs.workspace_config import WorkspaceConfig @@ -89,6 +90,9 @@ class Config(CLIParams, YamlModel): # Role's custom configuration roles: Optional[List[RoleCustomConfig]] = None + # RoleZero's configuration + role_zero: Optional[RoleZeroConfig] = None + omniparse: Optional[OmniParseConfig] = None @classmethod diff --git a/metagpt/configs/role_zero_config.py b/metagpt/configs/role_zero_config.py new file mode 100644 index 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.py index 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 commands commands: list[dict] = [] # commands to be executed memory_k: int = 200 # number of memories (messages) to use as historical context - enable_longterm_memory: bool = True # whether to use longterm memory use_fixed_sop: bool = False requirements_constraints: str = "" # the constraints in user requirements use_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