From 3e83a8d7fa77df187361b301c942f8b0a123710a Mon Sep 17 00:00:00 2001 From: stellahsr Date: Tue, 9 Apr 2024 16:35:59 +0800 Subject: [PATCH 1/5] update example --- examples/mgx/run_mgx.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/mgx/run_mgx.py b/examples/mgx/run_mgx.py index 4a1964d59..edfaff3d7 100644 --- a/examples/mgx/run_mgx.py +++ b/examples/mgx/run_mgx.py @@ -9,12 +9,13 @@ requirement = ( # "design a game using Gym (an open source Python library), including a graphical interface and interactive gameplay" # "帮我把pip的源设置成:https://pypi.tuna.tsinghua.edu.cn/simple" # "This is a website url does not require login: https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767 please write a similar web page,developed in vue language, The package.json dependency must be generated" - "I would like to imitate the website available at https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767. Could you please browse through it?" + # "I would like to imitate the website available at https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767. Could you please browse through it?" + "Create a 2048 Game" ) async def main(requirement: str = ""): - mgx = MGX(use_intent=True) + mgx = MGX(use_intent=True, tools=["software development"]) await mgx.run(requirement) From 2b56c367879e737696d3ecc5d305b3ff61c71cb4 Mon Sep 17 00:00:00 2001 From: stellahsr Date: Tue, 9 Apr 2024 17:07:03 +0800 Subject: [PATCH 2/5] update code --- metagpt/strategy/task_type.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/metagpt/strategy/task_type.py b/metagpt/strategy/task_type.py index c5453f1aa..2bc53b964 100644 --- a/metagpt/strategy/task_type.py +++ b/metagpt/strategy/task_type.py @@ -67,7 +67,10 @@ class TaskType(Enum): name="email login", desc="For logging to an email.", ) - DEVELOP_SOFTWARE = TaskTypeDef(name="develop software", desc="Develop software.") + DEVELOP_SOFTWARE = TaskTypeDef( + name="develop software", + desc="SOP related to develop software such as Writes a PRD, Writes a design, Writes a project plan and Writes code to implement designed features according to the project plan", + ) @property def type_name(self): From eef0375c6c8ef4ddca9de542c33f428b1cbf8f26 Mon Sep 17 00:00:00 2001 From: stellahsr Date: Tue, 9 Apr 2024 17:37:49 +0800 Subject: [PATCH 3/5] update tools according to intention update TaskTypeDef for software development --- examples/mgx/run_mgx.py | 6 +++--- metagpt/actions/di/detect_intent.py | 6 ++++-- metagpt/actions/di/write_plan.py | 18 +++++++++--------- metagpt/roles/di/mgx.py | 7 ++++++- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/examples/mgx/run_mgx.py b/examples/mgx/run_mgx.py index edfaff3d7..86aa67ad7 100644 --- a/examples/mgx/run_mgx.py +++ b/examples/mgx/run_mgx.py @@ -9,13 +9,13 @@ requirement = ( # "design a game using Gym (an open source Python library), including a graphical interface and interactive gameplay" # "帮我把pip的源设置成:https://pypi.tuna.tsinghua.edu.cn/simple" # "This is a website url does not require login: https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767 please write a similar web page,developed in vue language, The package.json dependency must be generated" - # "I would like to imitate the website available at https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767. Could you please browse through it?" - "Create a 2048 Game" + "I would like to imitate the website available at https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767. Could you please browse through it?" + # "Create a 2048 Game" ) async def main(requirement: str = ""): - mgx = MGX(use_intent=True, tools=["software development"]) + mgx = MGX(use_intent=True, tools=[""]) await mgx.run(requirement) diff --git a/metagpt/actions/di/detect_intent.py b/metagpt/actions/di/detect_intent.py index 5d25e9fbe..d7187c4f3 100644 --- a/metagpt/actions/di/detect_intent.py +++ b/metagpt/actions/di/detect_intent.py @@ -98,10 +98,12 @@ To meet user requirements, the following standard operating procedure(SOP) must {sop} -### SOP Type -{sop_type} + """ +### SOP Type +# {sop_type} + class DetectIntent(Action): async def run(self, with_message: Message, **kwargs) -> Tuple[str, str]: diff --git a/metagpt/actions/di/write_plan.py b/metagpt/actions/di/write_plan.py index 83709bc1a..201280d9b 100644 --- a/metagpt/actions/di/write_plan.py +++ b/metagpt/actions/di/write_plan.py @@ -29,15 +29,15 @@ If you are modifying an existing plan, carefully follow the instruction, don't m If you encounter errors on the current task, revise and output the current single task only. Output a list of jsons following the format: ```json -[ - {{ - "task_id": str = "unique identifier for a task in plan, can be an ordinal", - "dependent_task_ids": list[str] = "ids of tasks prerequisite to this task", - "instruction": "what you should do in this task, one short phrase or sentence. If the SOP description is provided in the `Knowledge` section, the reference to the SOP description should be included intact in the instruction.", - "task_type": "type of this task, should be one of Available Task Types. You can refer to the hints in the `SOP Type` section to make a selection if `SOP Type` section is provided.", - }}, - ... -] + [ + {{ + "task_id": str = "unique identifier for a task in plan, can be an ordinal", + "dependent_task_ids": list[str] = "ids of tasks prerequisite to this task", + "instruction": "what you should do in this task, one short phrase or sentence", + "task_type": "type of this task, should be one of Available Task Types", + }}, + ... + ] ``` """ diff --git a/metagpt/roles/di/mgx.py b/metagpt/roles/di/mgx.py index 0fa7c77b6..9d2f182e3 100644 --- a/metagpt/roles/di/mgx.py +++ b/metagpt/roles/di/mgx.py @@ -4,10 +4,11 @@ import asyncio from typing import Dict -from metagpt.actions.di.detect_intent import DetectIntent +from metagpt.actions.di.detect_intent import DetectIntent, SOPItem from metagpt.logs import logger from metagpt.roles.di.data_interpreter import DataInterpreter from metagpt.schema import Message +from metagpt.tools.tool_recommend import BM25ToolRecommender class MGX(DataInterpreter): @@ -18,6 +19,10 @@ class MGX(DataInterpreter): todo = DetectIntent(context=self.context) request_with_sop, sop_type = await todo.run(user_msg) logger.info(f"{sop_type} {request_with_sop}") + if sop_type == SOPItem.SOFTWARE_DEVELOPMENT.type_name: + self.tool_recommender = BM25ToolRecommender(tools=["software development"]) + else: + self.tool_recommender = BM25ToolRecommender(tools=[""]) return request_with_sop async def _plan_and_act(self) -> Message: From 4d072997fac2a797baa23da95bf825eb0f0101a1 Mon Sep 17 00:00:00 2001 From: stellahsr Date: Tue, 9 Apr 2024 18:21:27 +0800 Subject: [PATCH 4/5] update --- metagpt/actions/di/detect_intent.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/metagpt/actions/di/detect_intent.py b/metagpt/actions/di/detect_intent.py index 79d49b285..d9b587e5c 100644 --- a/metagpt/actions/di/detect_intent.py +++ b/metagpt/actions/di/detect_intent.py @@ -99,9 +99,6 @@ To meet user requirements, the following standard operating procedure(SOP) must {sop} """ -### SOP Type -# {sop_type} - class DetectIntent(Action): async def run(self, with_message: Message, **kwargs) -> Tuple[str, str]: From b130751b01dff73604eda53ed41b72102bc6555d Mon Sep 17 00:00:00 2001 From: stellahsr Date: Wed, 10 Apr 2024 17:03:07 +0800 Subject: [PATCH 5/5] update prompt indention --- metagpt/actions/di/write_plan.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/metagpt/actions/di/write_plan.py b/metagpt/actions/di/write_plan.py index 04aed7e17..8d6eccf57 100644 --- a/metagpt/actions/di/write_plan.py +++ b/metagpt/actions/di/write_plan.py @@ -16,9 +16,7 @@ from metagpt.schema import Message, Plan, Task from metagpt.strategy.task_type import TaskType from metagpt.utils.common import CodeParser - -class WritePlan(Action): - PROMPT_TEMPLATE: str = """ +PROMPT_TEMPLATE: str = """ # Context: {context} # Available Task Types: @@ -29,21 +27,23 @@ If you are modifying an existing plan, carefully follow the instruction, don't m If you encounter errors on the current task, revise and output the current single task only. Output a list of jsons following the format: ```json - [ - {{ - "task_id": str = "unique identifier for a task in plan, can be an ordinal", - "dependent_task_ids": list[str] = "ids of tasks prerequisite to this task", - "instruction": "what you should do in this task, one short phrase or sentence.", - "task_type": "type of this task, should be one of Available Task Types.", - }}, - ... - ] +[ + {{ + "task_id": str = "unique identifier for a task in plan, can be an ordinal", + "dependent_task_ids": list[str] = "ids of tasks prerequisite to this task", + "instruction": "what you should do in this task, one short phrase or sentence.", + "task_type": "type of this task, should be one of Available Task Types.", + }}, + ... +] ``` - """ +""" + +class WritePlan(Action): async def run(self, context: list[Message], max_tasks: int = 5) -> str: task_type_desc = "\n".join([f"- **{tt.type_name}**: {tt.value.desc}" for tt in TaskType]) - prompt = self.PROMPT_TEMPLATE.format( + prompt = PROMPT_TEMPLATE.format( context="\n".join([str(ct) for ct in context]), max_tasks=max_tasks, task_type_desc=task_type_desc ) rsp = await self._aask(prompt)