From 8edd764066d8f010ff9570c087af760078a94fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Wed, 31 Jul 2024 17:24:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/prompts/di/role_zero.py | 3 ++- metagpt/prompts/di/team_leader.py | 9 --------- metagpt/roles/di/data_analyst.py | 6 ++++-- metagpt/roles/di/engineer2.py | 4 ++-- metagpt/roles/di/team_leader.py | 3 ++- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 4cb643439..5891522bd 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -56,6 +56,7 @@ In your response, include at least one 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 [ {{ @@ -76,8 +77,8 @@ Fifth, describe if you should terminate, you should use **end** command to termi - You have completed the overall user requirement - All tasks are finished and current task is empty - You are repetitively replying to human -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. """.strip() + REGENERATE_PROMPT = """ Review and reflect on the history carefully, provide a different response. Describe if you should terminate using **end** command, or use **RoleZero.ask_human** to ask human for help, or try a different approach and output different commands. You are NOT allowed to provide the same commands again. diff --git a/metagpt/prompts/di/team_leader.py b/metagpt/prompts/di/team_leader.py index c1eb6e79e..b3eeda1a2 100644 --- a/metagpt/prompts/di/team_leader.py +++ b/metagpt/prompts/di/team_leader.py @@ -30,17 +30,8 @@ Note: 12. Add default web technologies: HTML (*.html), CSS (*.css), and JavaScript (*.js) to your requirements.If no specific programming language is required, include these technologies in the project requirements. Using instruction to forward this information to your team members. """ TL_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. -Third, describe the plan status and the current task. Review the histroy, if `Current Task` has been undertaken and completed by you or anyone, you MUST use the **Plan.finish_current_task** command to finish it first before taking any action, the command will automatically move you to the next task. -Fourth, describe any necessary human interaction. Use **RoleZero.reply_to_human** to report your progress if you complete a task or the overall requirement, pay attention to the history, DON'T repeat reporting. Use **RoleZero.ask_human** if you failed the current task, unsure of the situation encountered, need any help from human, or executing repetitive commands but receiving repetitive feedbacks without making progress. -Fifth, describe if you should terminate, you should use **end** command to terminate if any of the following is met: - - You have completed the overall user requirement - - All tasks are finished and current task is empty - - You are repetitively replying to human Sixth, when planning, describe the requirements as they pertain to software development, data analysis, or other areas. If the requirements is a software development and no specific restrictions are mentioned, you must create a Product Requirements Document (PRD), write a System Design document, develop a project schedule, and then begin coding. List the steps you will undertake. Plan these steps in a single response. Seventh, describe the technologies you must use. -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. """ QUICK_THINK_SYSTEM_PROMPT = """ {role_info} diff --git a/metagpt/roles/di/data_analyst.py b/metagpt/roles/di/data_analyst.py index b39053340..b9156d365 100644 --- a/metagpt/roles/di/data_analyst.py +++ b/metagpt/roles/di/data_analyst.py @@ -129,10 +129,12 @@ class DataAnalyst(RoleZero): async def _run_special_command(self, cmd) -> str: """command requiring special check or parsing.""" + # TODO: duplicate with Engineer2._run_special_command, consider dedup + # finish current task before end. command_output = "" if cmd["command_name"] == "end" and not self.planner.plan.is_plan_finished(): - self.planner.plan.finish_current_task() - command_output += "Current task is finished. \n" + self.planner.plan.finish_all_task() + command_output += "All tasks are finished.\n" command_output += await super()._run_special_command(cmd) return command_output diff --git a/metagpt/roles/di/engineer2.py b/metagpt/roles/di/engineer2.py index 3050071fd..ed0efa75b 100644 --- a/metagpt/roles/di/engineer2.py +++ b/metagpt/roles/di/engineer2.py @@ -32,7 +32,7 @@ class Engineer2(RoleZero): # finish current task before end. command_output = "" if cmd["command_name"] == "end" and not self.planner.plan.is_plan_finished(): - self.planner.plan.finish_current_task() - command_output += "Current task is finished. \n" + self.planner.plan.finish_all_task() + command_output += "All tasks are finished.\n" command_output += await super()._run_special_command(cmd) return command_output diff --git a/metagpt/roles/di/team_leader.py b/metagpt/roles/di/team_leader.py index 257c6c12d..a8aec75f6 100644 --- a/metagpt/roles/di/team_leader.py +++ b/metagpt/roles/di/team_leader.py @@ -1,6 +1,7 @@ from __future__ import annotations from metagpt.actions.di.run_command import RunCommand +from metagpt.prompts.di.role_zero import THOUGHT_GUIDANCE from metagpt.prompts.di.team_leader import ( FINISH_CURRENT_TASK_CMD, QUICK_THINK_SYSTEM_PROMPT, @@ -56,7 +57,7 @@ class TeamLeader(RoleZero): async def _think(self) -> bool: self.instruction = TL_INSTRUCTION.format(team_info=self._get_team_info()) - self.thought_guidance = TL_THOUGHT_GUIDANCE + self.thought_guidance = THOUGHT_GUIDANCE + TL_THOUGHT_GUIDANCE return await super()._think() def publish_message(self, msg: Message, send_to="no one"):