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] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E6=AD=A5=E9=AA=A4=E5=90=8E=EF=BC=8C=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=85=A8=E4=BA=A4=E7=94=B1=E7=A8=8B=E5=BA=8F=E5=91=98?= =?UTF-8?q?=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" } },