From 08ba3f52f8bec8d7b848b44fd8356068b1535934 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 11:58:05 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8C=87=E5=AE=9A=E6=AD=A5=E9=AA=A4=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=85=A8=E4=BA=A4=E7=94=B1=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=91=98=E5=AE=8C=E6=88=90=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...equirements.py => analyze_requirements.py} | 20 ++++++++++--------- metagpt/prompts/di/role_zero.py | 2 +- metagpt/prompts/di/team_leader.py | 15 ++++++++++++-- metagpt/roles/architect.py | 2 +- metagpt/roles/di/engineer2.py | 2 +- metagpt/roles/di/role_zero.py | 7 ++++--- metagpt/roles/di/team_leader.py | 2 ++ metagpt/strategy/experience_retriever.py | 2 +- 8 files changed, 34 insertions(+), 18 deletions(-) rename metagpt/actions/{anaylze_requirements.py => analyze_requirements.py} (94%) diff --git a/metagpt/actions/anaylze_requirements.py b/metagpt/actions/analyze_requirements.py similarity index 94% rename from metagpt/actions/anaylze_requirements.py rename to metagpt/actions/analyze_requirements.py index 3deb60d0d..ac412b1d1 100644 --- a/metagpt/actions/anaylze_requirements.py +++ b/metagpt/actions/analyze_requirements.py @@ -4,6 +4,8 @@ ANALYZE_REQUIREMENTS = """ # Example {examples} +---------------- + # Requirements {requirements} @@ -18,14 +20,6 @@ Follow the instructions and output format. Do not include any additional content EXAMPLES = """ Example 1 -Requirements: -Create 2048 game using Python. Do not write PRD. -Outputs: -[User Restrictions] : Do not write PRD. -[Language Restrictions] : The response, message and instruction must be in the language specified by English. -[Programming Language] : Python - -Example 2 Requirements: 创建一个贪吃蛇,只需要给出设计文档和代码 Outputs: @@ -33,6 +27,14 @@ Outputs: [Language Restrictions] : The response, message and instruction must be in the language specified by Chinese. [Programming Language] : HTML (*.html), CSS (*.css), and JavaScript (*.js) +Example 2 +Requirements: +Create 2048 game using Python. Do not write PRD. +Outputs: +[User Restrictions] : Do not write PRD. +[Language Restrictions] : The response, message and instruction must be in the language specified by English. +[Programming Language] : Python + Example 3 Requirements: You must ignore create PRD and TRD. Help me write a schedule display program for the Paris Olympics. @@ -44,7 +46,7 @@ Outputs: INSTRUCTIONS = """ You must output in the same language as the Requirements. -First, This language should be consistent with the language used in the requirement description. determine the natural language you must respond in. The default language is English +First, This language should be consistent with the language used in the requirement description. determine the natural language you must respond in. If the requirements specify a special language, follow those instructions. The default language for responses is English. Second, extract the restrictions in the requirements, specifically the steps. Do not include detailed demand descriptions; focus only on the restrictions. Third, if the requirements is a software development, extract the program language. If If no specific programming language is required, Use HTML (*.html), CSS (*.css), and JavaScript (*.js) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 6b48b7c91..4cb643439 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -76,7 +76,7 @@ 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 whether you will end, then follow your thoughts to list the commands, adhering closely to the instructions provided. +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. diff --git a/metagpt/prompts/di/team_leader.py b/metagpt/prompts/di/team_leader.py index 7686de36e..86288ec73 100644 --- a/metagpt/prompts/di/team_leader.py +++ b/metagpt/prompts/di/team_leader.py @@ -27,9 +27,20 @@ Note: 9. Do not use the 'end' command when the current task remains unfinished; instead, use the 'finish_current_task' command to indicate completion before switching to the next task. 10. Do not use escape characters in json data, particularly within file paths. 11. Analyze the capabilities of team members and assign tasks to them based on user Requirements. If the requirements ask to ignore certain tasks, follow the requirements. -12. If the requirement is to develop software and does not specify a programming language, use the default web technologies: HTML (`*.html`), CSS (`*.css`), and JavaScript (`*.js`). You must add this to the requirements. +13. 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. +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} Your team member: diff --git a/metagpt/roles/architect.py b/metagpt/roles/architect.py index 503be51f6..52b450a6a 100644 --- a/metagpt/roles/architect.py +++ b/metagpt/roles/architect.py @@ -33,7 +33,7 @@ class Architect(RoleZero): name: str = "Bob" profile: str = "Architect" - goal: str = "design a concise, usable, complete software system." + goal: str = "design a concise, usable, complete software system. ouput the system design and software framework." constraints: str = ( "make sure the architecture is simple enough and use appropriate open source " "libraries. Use same language as user requirement" diff --git a/metagpt/roles/di/engineer2.py b/metagpt/roles/di/engineer2.py index 01bf826f4..1610a652b 100644 --- a/metagpt/roles/di/engineer2.py +++ b/metagpt/roles/di/engineer2.py @@ -9,7 +9,7 @@ from metagpt.strategy.experience_retriever import ENGINEER_EXAMPLE class Engineer2(RoleZero): name: str = "Alex" profile: str = "Engineer" - goal: str = "Take on game, app, and web development" + goal: str = "Take on game, app, and web development." instruction: str = ENGINEER2_INSTRUCTION tools: list[str] = ["Plan", "Editor:write,read", "RoleZero", "ReviewAndRewriteCode"] diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index f93122626..d4746e167 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -9,7 +9,7 @@ from typing import Callable, Dict, List, Literal, Tuple from pydantic import model_validator from metagpt.actions import Action, UserRequirement -from metagpt.actions.anaylze_requirements import AnalyzeRequirementsRestrictions +from metagpt.actions.analyze_requirements import AnalyzeRequirementsRestrictions from metagpt.actions.di.run_command import RunCommand from metagpt.exp_pool import exp_cache from metagpt.exp_pool.context_builders import RoleZeroContextBuilder @@ -47,6 +47,7 @@ class RoleZero(Role): goal: str = "" system_msg: list[str] = None # Use None to conform to the default value at llm.aask cmd_prompt: str = CMD_PROMPT + thought_guidance: str = THOUGHT_GUIDANCE instruction: str = ROLE_INSTRUCTION task_type_desc: str = None @@ -161,7 +162,7 @@ class RoleZero(Role): plan_status=plan_status, current_task=current_task, instruction=instruction, - thought_guidance=THOUGHT_GUIDANCE, + thought_guidance=self.thought_guidance, latest_observation=memory[-1].content, requirements_constraints=self.requirements_constraints, ) @@ -214,7 +215,7 @@ class RoleZero(Role): self.rc.memory.add(UserMessage(content=outputs)) return AIMessage( - content=f"{self.name} has finished the task, mark it as finished. Complete run with outputs: {outputs}", + content=f"I have finished the task, please mark my task as finished. Outputs: {outputs}", sent_from=self.name, cause_by=RunCommand, ) diff --git a/metagpt/roles/di/team_leader.py b/metagpt/roles/di/team_leader.py index fca45f5a8..257c6c12d 100644 --- a/metagpt/roles/di/team_leader.py +++ b/metagpt/roles/di/team_leader.py @@ -6,6 +6,7 @@ from metagpt.prompts.di.team_leader import ( QUICK_THINK_SYSTEM_PROMPT, SYSTEM_PROMPT, TL_INSTRUCTION, + TL_THOUGHT_GUIDANCE, ) from metagpt.roles.di.role_zero import RoleZero from metagpt.schema import AIMessage, Message, UserMessage @@ -55,6 +56,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 return await super()._think() def publish_message(self, msg: Message, send_to="no one"): diff --git a/metagpt/strategy/experience_retriever.py b/metagpt/strategy/experience_retriever.py index 41d876210..9587ef9f8 100644 --- a/metagpt/strategy/experience_retriever.py +++ b/metagpt/strategy/experience_retriever.py @@ -479,7 +479,7 @@ Explanation: The requirement is about software development. Assign each tasks to "args": { "task_id": "1", "dependent_task_ids": [], - "instruction": "Create a product requirement document (PRD) outlining the features, user interface, and user experience of the CLI python snake game.Using Python as the programming language.", + "instruction": "Create a product requirement document (PRD) outlining the features, user interface, and user experience of the CLI python snake game. Using Python as the programming language.", "assignee": "Alice" } }, From 28059f14df0cb4855d64c70a18f626505e93048c 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 14:52:34 +0800 Subject: [PATCH 2/6] Add a "finish current task" command before the "end" command for the engineer and the data analyst. --- metagpt/prompts/di/data_analyst.py | 1 + metagpt/prompts/di/team_leader.py | 1 + metagpt/roles/di/data_analyst.py | 26 ++++++++++++++++---------- metagpt/roles/di/engineer2.py | 10 ++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/metagpt/prompts/di/data_analyst.py b/metagpt/prompts/di/data_analyst.py index 56675de9b..3e4dac6f5 100644 --- a/metagpt/prompts/di/data_analyst.py +++ b/metagpt/prompts/di/data_analyst.py @@ -10,6 +10,7 @@ EXTRA_INSTRUCTION = """ 7. When you are making plan. It is highly recommend to plan and append all the tasks in first response once time. 8. Don't finish_current_task multiple times for the same task. 9. Finish current task timely, such as when the code is written and executed successfully. +10. When using the command 'end', add the command 'finish_current_task' before it. """ TASK_TYPE_DESC = "\n".join([f"- **{tt.type_name}**: {tt.value.desc}" for tt in TaskType]) diff --git a/metagpt/prompts/di/team_leader.py b/metagpt/prompts/di/team_leader.py index 86288ec73..4fc03222d 100644 --- a/metagpt/prompts/di/team_leader.py +++ b/metagpt/prompts/di/team_leader.py @@ -39,6 +39,7 @@ Fifth, describe if you should terminate, you should use **end** command to termi - 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 = """ diff --git a/metagpt/roles/di/data_analyst.py b/metagpt/roles/di/data_analyst.py index 154d1593d..b39053340 100644 --- a/metagpt/roles/di/data_analyst.py +++ b/metagpt/roles/di/data_analyst.py @@ -3,7 +3,7 @@ from __future__ import annotations from pydantic import Field, model_validator from metagpt.actions.di.execute_nb_code import ExecuteNbCode -from metagpt.actions.di.write_analysis_code import WriteAnalysisCode, CheckData +from metagpt.actions.di.write_analysis_code import CheckData, WriteAnalysisCode from metagpt.logs import logger from metagpt.prompts.di.data_analyst import ( CODE_STATUS, @@ -111,15 +111,11 @@ class DataAnalyst(RoleZero): return output async def _check_data(self): - if ( - not self.planner.plan.get_finished_tasks() - or self.planner.plan.current_task.task_type - not in [ - TaskType.DATA_PREPROCESS.type_name, - TaskType.FEATURE_ENGINEERING.type_name, - TaskType.MODEL_TRAIN.type_name, - ] - ): + if not self.planner.plan.get_finished_tasks() or self.planner.plan.current_task.task_type not in [ + TaskType.DATA_PREPROCESS.type_name, + TaskType.FEATURE_ENGINEERING.type_name, + TaskType.MODEL_TRAIN.type_name, + ]: return logger.info("Check updated data") code = await CheckData().run(self.planner.plan) @@ -130,3 +126,13 @@ class DataAnalyst(RoleZero): print(result) data_info = DATA_INFO.format(info=result) self.rc.working_memory.add(Message(content=data_info, role="user", cause_by=CheckData)) + + async def _run_special_command(self, cmd) -> str: + """command requiring special check or parsing.""" + # 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" + 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 1610a652b..3050071fd 100644 --- a/metagpt/roles/di/engineer2.py +++ b/metagpt/roles/di/engineer2.py @@ -26,3 +26,13 @@ class Engineer2(RoleZero): def _retrieve_experience(self) -> str: return ENGINEER_EXAMPLE + + async def _run_special_command(self, cmd) -> str: + """command requiring special check or parsing.""" + # 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" + command_output += await super()._run_special_command(cmd) + return command_output From f548b58f8427199afd83916c141950abd0da7926 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 15:36:56 +0800 Subject: [PATCH 3/6] Fix the format issue. --- metagpt/prompts/di/team_leader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metagpt/prompts/di/team_leader.py b/metagpt/prompts/di/team_leader.py index 4fc03222d..c1eb6e79e 100644 --- a/metagpt/prompts/di/team_leader.py +++ b/metagpt/prompts/di/team_leader.py @@ -27,7 +27,7 @@ Note: 9. Do not use the 'end' command when the current task remains unfinished; instead, use the 'finish_current_task' command to indicate completion before switching to the next task. 10. Do not use escape characters in json data, particularly within file paths. 11. Analyze the capabilities of team members and assign tasks to them based on user Requirements. If the requirements ask to ignore certain tasks, follow the requirements. -13. 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. +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. 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 4/6] =?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"): From 78cc39c5f99faf287b3328851caa6f99a6f0c1a8 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 19:34:12 +0800 Subject: [PATCH 5/6] Fix format issues --- metagpt/prompts/di/team_leader.py | 7 ++++++- metagpt/roles/architect.py | 2 +- metagpt/roles/di/data_analyst.py | 2 +- metagpt/roles/di/engineer2.py | 2 +- metagpt/roles/di/team_leader.py | 4 +--- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/metagpt/prompts/di/team_leader.py b/metagpt/prompts/di/team_leader.py index b3eeda1a2..2f3e69651 100644 --- a/metagpt/prompts/di/team_leader.py +++ b/metagpt/prompts/di/team_leader.py @@ -1,3 +1,5 @@ +from metagpt.prompts.di.role_zero import THOUGHT_GUIDANCE + SYSTEM_PROMPT = """ You are a team leader, and you are responsible for drafting tasks and routing tasks to your team members. When drafting and routing tasks, ALWAYS include necessary or important info inside the instruction, such as path, link, environment to team members, because you are their sole info source. @@ -29,10 +31,13 @@ Note: 11. Analyze the capabilities of team members and assign tasks to them based on user Requirements. If the requirements ask to ignore certain tasks, follow the requirements. 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 = """ +TL_THOUGHT_GUIDANCE = ( + THOUGHT_GUIDANCE + + """ 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. """ +) QUICK_THINK_SYSTEM_PROMPT = """ {role_info} Your team member: diff --git a/metagpt/roles/architect.py b/metagpt/roles/architect.py index 52b450a6a..e37f00913 100644 --- a/metagpt/roles/architect.py +++ b/metagpt/roles/architect.py @@ -33,7 +33,7 @@ class Architect(RoleZero): name: str = "Bob" profile: str = "Architect" - goal: str = "design a concise, usable, complete software system. ouput the system design and software framework." + goal: str = "design a concise, usable, complete software system. ouput the system design or software framework." constraints: str = ( "make sure the architecture is simple enough and use appropriate open source " "libraries. Use same language as user requirement" diff --git a/metagpt/roles/di/data_analyst.py b/metagpt/roles/di/data_analyst.py index b9156d365..3a43f72e0 100644 --- a/metagpt/roles/di/data_analyst.py +++ b/metagpt/roles/di/data_analyst.py @@ -134,7 +134,7 @@ class DataAnalyst(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_all_task() + self.planner.plan.finish_all_tasks() 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 ed0efa75b..fbade0421 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_all_task() + self.planner.plan.finish_all_tasks() 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 a8aec75f6..f495c4aaa 100644 --- a/metagpt/roles/di/team_leader.py +++ b/metagpt/roles/di/team_leader.py @@ -1,7 +1,6 @@ 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, @@ -21,7 +20,7 @@ class TeamLeader(RoleZero): profile: str = "Team Leader" goal: str = "Manage a team to assist users" system_msg: list[str] = [SYSTEM_PROMPT] - + thought_guidance: str = TL_THOUGHT_GUIDANCE # TeamLeader only reacts once each time, but may encounter errors or need to ask human, thus allowing 2 more turns max_react_loop: int = 3 @@ -57,7 +56,6 @@ class TeamLeader(RoleZero): async def _think(self) -> bool: self.instruction = TL_INSTRUCTION.format(team_info=self._get_team_info()) - self.thought_guidance = THOUGHT_GUIDANCE + TL_THOUGHT_GUIDANCE return await super()._think() def publish_message(self, msg: Message, send_to="no one"): From c581158fa11414dd9755a6ea3875dcfb3fad3496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Thu, 1 Aug 2024 10:23:38 +0800 Subject: [PATCH 6/6] =?UTF-8?q?planner=E6=B7=BB=E5=8A=A0=20finish=20crrent?= =?UTF-8?q?=20task=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/schema.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/metagpt/schema.py b/metagpt/schema.py index c716f8b2f..648e2bd73 100644 --- a/metagpt/schema.py +++ b/metagpt/schema.py @@ -657,6 +657,11 @@ class Plan(BaseModel): self.current_task.is_finished = True self._update_current_task() # set to next task + def finish_all_tasks(self): + "Finish all tasks." + while self.current_task: + self.finish_current_task() + def is_plan_finished(self) -> bool: """Check if all tasks are finished""" return all(task.is_finished for task in self.tasks) @@ -669,14 +674,16 @@ class Plan(BaseModel): """ return [task for task in self.tasks if task.is_finished] - def append_task(self, task_id: str, dependent_task_ids: list[str], instruction: str, assignee: str, task_type: str = ""): + def append_task( + self, task_id: str, dependent_task_ids: list[str], instruction: str, assignee: str, task_type: str = "" + ): """Append a new task with task_id (number) to the end of existing task sequences. If dependent_task_ids is not empty, the task will depend on the tasks with the ids in the list. Note that the assignee should be the 'name' of the role.""" new_task = Task( task_id=task_id, dependent_task_ids=dependent_task_ids, instruction=instruction, assignee=assignee, - task_type=task_type + task_type=task_type, ) return self._append_task(new_task)