diff --git a/metagpt/const.py b/metagpt/const.py index 0dfe9e5ec..a83416cdb 100644 --- a/metagpt/const.py +++ b/metagpt/const.py @@ -83,6 +83,8 @@ MESSAGE_ROUTE_TO_ALL = "" MESSAGE_ROUTE_TO_NONE = "" MESSAGE_ROUTE_TO_SELF = "" # Add this tag to replace `ActionOutput` +EXPERIENCE_MASK = "" + 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.py index 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 copy from typing import Any +from metagpt.const import EXPERIENCE_MASK from metagpt.exp_pool.context_builders.base import BaseContextBuilder @@ -34,6 +35,5 @@ class RoleZeroContextBuilder(BaseContextBuilder): @staticmethod def fill_experience(text: str, new_example_content: str) -> str: - pattern = "" - replaced_text = text.replace(pattern, new_example_content) + replaced_text = text.replace(EXPERIENCE_MASK, new_example_content) return replaced_text diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 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_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.py index 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_MASK from metagpt.exp_pool.context_builders.base import BaseContextBuilder from 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\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"