Add EXPERIENCE_MASK to replace the experience placeholder

This commit is contained in:
黄伟韬 2024-08-16 15:01:23 +08:00
parent d65ae90056
commit 70fa7b54ce
4 changed files with 15 additions and 6 deletions

View file

@ -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"

View file

@ -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 = "<experience>"
replaced_text = text.replace(pattern, new_example_content)
replaced_text = text.replace(EXPERIENCE_MASK, new_example_content)
return replaced_text

View file

@ -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.

View file

@ -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<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"