🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
Add EXPERIENCE_MASK to replace the experience placeholder
黄伟韬70fa7b54ce31
diff --git a/metagpt/const.py b/metagpt/const.pyindex 0dfe9e5ec..a83416cdb 100644--- a/metagpt/const.py+++ b/metagpt/const.py@@ -83,6 +83,8 @@ MESSAGE_ROUTE_TO_ALL = "<all>"MESSAGE_ROUTE_TO_NONE = "<none>"MESSAGE_ROUTE_TO_SELF = "<self>" # Add this tag to replace `ActionOutput`+EXPERIENCE_MASK = "<experience>"+REQUIREMENT_FILENAME = "requirement.txt"BUGFIX_FILENAME = "bugfix.txt"PACKAGE_REQUIREMENTS_FILENAME = "requirements.txt"diff --git a/metagpt/exp_pool/context_builders/role_zero.py b/metagpt/exp_pool/context_builders/role_zero.pyindex b25308153..cbda72fc5 100644--- a/metagpt/exp_pool/context_builders/role_zero.py+++ b/metagpt/exp_pool/context_builders/role_zero.py@@ -3,6 +3,7 @@import copyfrom typing import Any+from metagpt.const import EXPERIENCE_MASKfrom metagpt.exp_pool.context_builders.base import BaseContextBuilder@@ -34,6 +35,5 @@ class RoleZeroContextBuilder(BaseContextBuilder):@staticmethoddef fill_experience(text: str, new_example_content: str) -> str:- pattern = "<experience>"- replaced_text = text.replace(pattern, new_example_content)+ replaced_text = text.replace(EXPERIENCE_MASK, new_example_content)return replaced_textdiff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.pyindex 4c407fb97..3c47ebf5f 100644--- a/metagpt/prompts/di/role_zero.py+++ b/metagpt/prompts/di/role_zero.py@@ -1,3 +1,5 @@+from metagpt.const import EXPERIENCE_MASK+ROLE_INSTRUCTION = """Based on the context, write a plan or modify an existing plan to achieve the goal. A plan consists of one to 3 tasks.If plan is created, you should track the progress and update the plan accordingly, such as Plan.finish_current_task, Plan.append_task, Plan.reset_task, Plan.replace_task, etc.@@ -10,7 +12,6 @@ Note:4. Don't forget to append task first when all existing tasks are finished and new tasks are required.5. Avoid repeating tasks you have already completed. And end loop when all requirements are met."""-# To ensure compatibility with hard-coded experience, do not add any other content between "# Example" and "# Instruction".########################## ignore guidance@@ -47,10 +48,14 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet{instruction}"""-CMD_PROMPT = """+CMD_EXPERIENCE_MASK = f"""# Past Experience-<experience>+{EXPERIENCE_MASK}+"""+CMD_PROMPT = (+ CMD_EXPERIENCE_MASK+ + """{current_state}# Current Plan@@ -82,6 +87,7 @@ Output should adhere to the following format.```Notice: your output JSON data section must start with **```json [**"""+)THOUGHT_GUIDANCE = """First, describe the actions you have taken recently.diff --git a/tests/metagpt/exp_pool/test_context_builders/test_rolezero_context_builder.py b/tests/metagpt/exp_pool/test_context_builders/test_rolezero_context_builder.pyindex ee56ea094..82a3622a5 100644--- a/tests/metagpt/exp_pool/test_context_builders/test_rolezero_context_builder.py+++ b/tests/metagpt/exp_pool/test_context_builders/test_rolezero_context_builder.py@@ -1,5 +1,6 @@import pytest+from metagpt.const import EXPERIENCE_MASKfrom metagpt.exp_pool.context_builders.base import BaseContextBuilderfrom metagpt.exp_pool.context_builders.role_zero import RoleZeroContextBuilder@@ -36,7 +37,7 @@ class TestRoleZeroContextBuilder:context_builder.fill_experience.assert_called_once_with("Original text", "New example content")def test_fill_experience(self):- text = "Start\n# Past Experience\n<experience>\n\n# Instruction\nEnd"+ text = f"Start\n# Past Experience\n{EXPERIENCE_MASK}\n\n# Instruction\nEnd"new_content = "New content"result = RoleZeroContextBuilder.fill_experience(text, new_content)expected = "Start\n# Past Experience\nNew content\n\n# Instruction\nEnd"