diff --git a/metagpt/actions/prepare_documents.py b/metagpt/actions/prepare_documents.py index 3d202e762..b751dc970 100644 --- a/metagpt/actions/prepare_documents.py +++ b/metagpt/actions/prepare_documents.py @@ -23,17 +23,14 @@ class PrepareDocuments(Action): super().__init__(name, context, llm) async def run(self, with_messages, **kwargs): - if CONFIG.git_repo: - doc = await FileRepository.get_file(filename=REQUIREMENT_FILENAME, relative_path=DOCS_FILE_REPO) - return ActionOutput(content=doc.json(exclue="content"), instruct_content=doc) - - # Create and initialize the workspace folder, initialize the Git environment. - project_name = CONFIG.project_name or FileRepository.new_filename() - workdir = Path(CONFIG.project_path or DEFAULT_WORKSPACE_ROOT / project_name) - if not CONFIG.inc and workdir.exists(): - shutil.rmtree(workdir) - CONFIG.git_repo = GitRepository() - CONFIG.git_repo.open(local_path=workdir, auto_init=True) + if not CONFIG.git_repo: + # Create and initialize the workspace folder, initialize the Git environment. + project_name = CONFIG.project_name or FileRepository.new_filename() + workdir = Path(CONFIG.project_path or DEFAULT_WORKSPACE_ROOT / project_name) + if not CONFIG.inc and workdir.exists(): + shutil.rmtree(workdir) + CONFIG.git_repo = GitRepository() + CONFIG.git_repo.open(local_path=workdir, auto_init=True) # Write the newly added requirements from the main parameter idea to `docs/requirement.txt`. doc = Document(root_path=DOCS_FILE_REPO, filename=REQUIREMENT_FILENAME, content=with_messages[0].content) diff --git a/metagpt/roles/product_manager.py b/metagpt/roles/product_manager.py index a13a13f6c..017feade7 100644 --- a/metagpt/roles/product_manager.py +++ b/metagpt/roles/product_manager.py @@ -52,3 +52,6 @@ class ProductManager(Role): else: self._set_state(0) return self._rc.todo + + async def _observe(self, ignore_memory=False) -> int: + return await super(ProductManager, self)._observe(ignore_memory=True) diff --git a/metagpt/roles/qa_engineer.py b/metagpt/roles/qa_engineer.py index ac5a280bb..41a3213dc 100644 --- a/metagpt/roles/qa_engineer.py +++ b/metagpt/roles/qa_engineer.py @@ -169,3 +169,8 @@ class QaEngineer(Role): sent_from=self.profile, send_to=MESSAGE_ROUTE_TO_NONE, ) + + async def _observe(self, ignore_memory=False) -> int: + # This role has events that trigger and execute themselves based on conditions, and cannot rely on the + # content of memory to activate. + return await super(QaEngineer, self)._observe(ignore_memory=True) diff --git a/metagpt/roles/role.py b/metagpt/roles/role.py index 47ffb3f9e..1e99cc1ff 100644 --- a/metagpt/roles/role.py +++ b/metagpt/roles/role.py @@ -291,12 +291,12 @@ class Role: return msg - async def _observe(self) -> int: + async def _observe(self, ignore_memory=False) -> int: """Prepare new messages for processing from the message buffer and other sources.""" # Read unprocessed messages from the msg buffer. news = self._rc.msg_buffer.pop_all() # Store the read messages in your own memory to prevent duplicate processing. - old_messages = self._rc.memory.get() + old_messages = [] if ignore_memory else self._rc.memory.get() self._rc.memory.add_batch(news) # Filter out messages of interest. self._rc.news = [n for n in news if n.cause_by in self._rc.watch and n not in old_messages]