From 075a82e6f499856927d9b7465c2804e035231241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Thu, 8 Aug 2024 20:44:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E8=A7=92=E8=89=B2=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=EF=BC=8C=E8=A7=92=E8=89=B2instruction=E5=92=8C=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=8A=A0=E5=85=A5=E5=BC=80=E5=A7=8B=E7=9A=84system=5F?= =?UTF-8?q?prompt=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/prompts/di/role_zero.py | 36 ++++++++++++++++++++++----------- metagpt/roles/di/role_zero.py | 25 ++++++++++++++++------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 8443a7960..de4bdb066 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -11,9 +11,14 @@ Note: 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". -CMD_PROMPT = """ + +#################### # Latest Observation -{latest_observation} +# {latest_observation} + + +########################### +INSTRUCTION_GUIDANCE = """ # Data Structure class Task(BaseModel): @@ -30,11 +35,6 @@ class Task(BaseModel): {available_commands} Special Command: Use {{"command_name": "end"}} to do nothing or indicate completion of all requirements and the end of actions. -# Current Plan -{plan_status} - -# Current Task -{current_task} # Example {example} @@ -42,6 +42,22 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet # Instruction {instruction} +""" + + +# {thought_guidance} +# Finally, combine your thoughts, describe what you want to do conscisely in 20 words, including which process you will taked and whether you will end, then follow your thoughts to list the commands, adhering closely to the instructions provided. + +CMD_PROMPT = """ +# Current Plan +{plan_status} + +# Current Task +{current_task} + +# Restrictions +{requirements_constraints} + Pay close attention to the Example provided, you can reuse the example for your current situation if it fits. You may use any of the available commands to create a plan or update the plan. You may output mutiple commands, they will be executed sequentially. @@ -49,14 +65,9 @@ If you finish current task, you will automatically take the next task in the exi Review the latest plan's outcome, focusing on achievements. If your completed task matches the current, consider it finished. In your response, include at least one command. -# Restrictions -{requirements_constraints} - # Your commands in a json array, in the following output format with correct command_name and args. If there is nothing to do, use the pass or end command: Some text indicating your thoughts before JSON is required, such as what tasks have been completed, what tasks are next, how you should update the plan status, respond to inquiry, or seek for help. Then a json array of commands. You must output ONE and ONLY ONE json array. DON'T output multiple json arrays with thoughts between them. Output should adhere to the following format. -{thought_guidance} -Finally, combine your thoughts, describe what you want to do conscisely in 20 words, including which process you will taked and whether you will end, then follow your thoughts to list the commands, adhering closely to the instructions provided. ```json [ {{ @@ -68,6 +79,7 @@ Finally, combine your thoughts, describe what you want to do conscisely in 20 wo ``` Notice: your output JSON data section must start with **```json [** """ + THOUGHT_GUIDANCE = """ First, describe the actions you have taken recently. Second, describe the messages you have received recently, with a particular emphasis on messages from users. If necessary, develop a plan to address the new user requirements. diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 773124dcc..388eca13e 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -19,6 +19,7 @@ from metagpt.logs import logger from metagpt.prompts.di.role_zero import ( ASK_HUMAN_COMMAND, CMD_PROMPT, + INSTRUCTION_GUIDANCE, JSON_REPAIR_PROMPT, QUICK_THINK_PROMPT, REGENERATE_PROMPT, @@ -47,6 +48,7 @@ class RoleZero(Role): profile: str = "RoleZero" goal: str = "" system_msg: list[str] = None # Use None to conform to the default value at llm.aask + instruction_system_prpomt: str = INSTRUCTION_GUIDANCE cmd_prompt: str = CMD_PROMPT thought_guidance: str = THOUGHT_GUIDANCE instruction: str = ROLE_INSTRUCTION @@ -152,18 +154,25 @@ class RoleZero(Role): tools = await self.tool_recommender.recommend_tools() tool_info = json.dumps({tool.name: tool.schemas for tool in tools}) - ### Make Decision Dynamically ### - memory = self.rc.memory.get(self.memory_k) instruction = self.instruction.strip() - prompt = self.cmd_prompt.format( + instruction_system_prpomt = self.instruction_system_prpomt.format( example=example, available_commands=tool_info, + instruction=instruction, task_type_desc=self.task_type_desc, + ) + guidance_system_msgs = [instruction_system_prpomt] + if self.system_msg: + guidance_system_msgs = self.system_msg + guidance_system_msgs + + # print(("\n"+"="*10+"\n").join(guidance_system_msgs)) + ### Make Decision Dynamically ### + memory = self.rc.memory.get(self.memory_k) + prompt = self.cmd_prompt.format( plan_status=plan_status, current_task=current_task, - instruction=instruction, - thought_guidance=self.thought_guidance, - latest_observation=memory[-1].content, + # thought_guidance=self.thought_guidance, + # latest_observation=memory[-1].content, requirements_constraints=self.requirements_constraints, ) memory = await self.parse_browser_actions(memory) @@ -175,7 +184,9 @@ class RoleZero(Role): current_task=current_task, instruction=instruction, ) - self.command_rsp = await self.llm_cached_aask(req=req, system_msgs=self.system_msg, state_data=state_data) + self.command_rsp = await self.llm_cached_aask( + req=req, system_msgs=guidance_system_msgs, state_data=state_data + ) self.command_rsp = await self._check_duplicates(req, self.command_rsp)