Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

format RoreZero Prompt to fit into exp_pool

黄伟韬91affc2a60a4
diff --git a/metagpt/exp_pool/context_builders/role_zero.py b/metagpt/exp_pool/context_builders/role_zero.py
index 924bd56aa..44685411c 100644
--- a/metagpt/exp_pool/context_builders/role_zero.py
+++ b/metagpt/exp_pool/context_builders/role_zero.py
@@ -31,7 +31,14 @@ class RoleZeroContextBuilder(BaseContextBuilder):
return req_copy
def replace_example_content(self, text: str, new_example_content: str) -> str:
- return self.replace_content_between_markers(text, "# Example", "# Instruction", new_example_content)
+ return self.replace_content_of_example_tag(text, new_example_content)
+ # return self.replace_content_between_markers(text, "# Example", "# Instruction", new_example_content)
+
+ @staticmethod
+ def replace_content_of_example_tag(self, text: str, new_example_content: str) -> str:
+ pattern = "# Past Experience\n<experience>"
+ replaced_text = text.replace(pattern, "# Example\n" + new_example_content)
+ return replaced_text
@staticmethod
def replace_content_between_markers(text: str, start_marker: str, end_marker: str, new_content: str) -> str:
diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py
index cc78d809c..24ca29af5 100644
--- a/metagpt/prompts/di/role_zero.py
+++ b/metagpt/prompts/di/role_zero.py
@@ -46,6 +46,9 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet
"""
CMD_PROMPT = """
+# Past Experience
+<experience>
+
{current_state}
# Current Plan
@@ -206,4 +209,4 @@ Response Category: AMBIGUOUS.
QUICK_RESPONSE_SYSTEM_PROMPT = """
{role_info}
However, you MUST respond to the user message by yourself directly, DON'T ask your team members.
-"""
\ No newline at end of file
+"""
diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py
index 3ceee8b43..32508910c 100644
--- a/metagpt/roles/di/role_zero.py
+++ b/metagpt/roles/di/role_zero.py
@@ -21,10 +21,10 @@ from metagpt.prompts.di.role_zero import (
ASK_HUMAN_COMMAND,
CMD_PROMPT,
JSON_REPAIR_PROMPT,
- QUICK_THINK_PROMPT,
+ QUICK_RESPONSE_SYSTEM_PROMPT,
QUICK_THINK_EXAMPLES,
+ QUICK_THINK_PROMPT,
QUICK_THINK_SYSTEM_PROMPT,
- QUICK_RESPONSE_SYSTEM_PROMPT,
REGENERATE_PROMPT,
ROLE_INSTRUCTION,
SYSTEM_PROMPT,
@@ -269,7 +269,7 @@ class RoleZero(Role):
rsp = await self._act()
actions_taken += 1
return rsp # return output from the last action
-
+
def format_quick_system_prompt(self) -> str:
"""Format the system prompt for quick thinking."""
return QUICK_THINK_SYSTEM_PROMPT.format(examples=QUICK_THINK_EXAMPLES, role_info=self._get_prefix())
@@ -289,7 +289,10 @@ class RoleZero(Role):
if "QUICK" in intent_result or "AMBIGUOUS" in intent_result: # llm call with the original context
async with ThoughtReporter(enable_llm_stream=True) as reporter:
await reporter.async_report({"type": "quick"})
- answer = await self.llm.aask(self.llm.format_msg(memory), system_msgs=[QUICK_RESPONSE_SYSTEM_PROMPT.format(role_info=self._get_prefix())])
+ answer = await self.llm.aask(
+ self.llm.format_msg(memory),
+ system_msgs=[QUICK_RESPONSE_SYSTEM_PROMPT.format(role_info=self._get_prefix())],
+ )
elif "SEARCH" in intent_result:
query = "\n".join(str(msg) for msg in memory)
answer = await SearchEnhancedQA().run(query)
@@ -427,11 +430,6 @@ class RoleZero(Role):
def _get_plan_status(self) -> Tuple[str, str]:
plan_status = self.planner.plan.model_dump(include=["goal", "tasks"])
- for task in plan_status["tasks"]:
- task.pop("code")
- task.pop("result")
- task.pop("is_success")
- # print(plan_status)
current_task = (
self.planner.plan.current_task.model_dump(exclude=["code", "result", "is_success"])
if self.planner.plan.current_task