From 0469d1ed7d5b07f222aa594b97459ab38e471f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Wed, 14 Aug 2024 15:51:05 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fixbug:u=E4=BC=98=E5=8C=96=E4=BA=86?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=89=A7=E8=A1=8C=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=92=8Cengineer=E6=8F=90=E6=97=A9=E7=BB=93=E6=9D=9F=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/roles/di/role_zero.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 815768fb1..1fa1930e8 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -155,6 +155,8 @@ class RoleZero(Role): ### 2. Plan Status ### plan_status, current_task = self._get_plan_status() + plan_status_formated = self._format_plan_status(plan_status) + ### 3. Tool/Command Info ### tools = await self.tool_recommender.recommend_tools() tool_info = json.dumps({tool.name: tool.schemas for tool in tools}) @@ -168,7 +170,7 @@ class RoleZero(Role): ### Make Decision Dynamically ### prompt = self.cmd_prompt.format( current_state=self.cmd_prompt_current_state, - plan_status=plan_status, + plan_status=plan_status_formated, current_task=current_task, requirements_constraints=self.requirements_constraints, ) @@ -384,11 +386,10 @@ class RoleZero(Role): """command requiring special check or parsing""" command_output = "" - if cmd["command_name"] == "Plan.finish_current_task" and not self.planner.plan.is_plan_finished(): - # task_result = TaskResult(code=str(commands), result=outputs, is_success=is_success) - # self.planner.plan.current_task.update_task_result(task_result=task_result) - self.planner.plan.finish_current_task() - command_output = "Current task is finished. " + if cmd["command_name"] == "Plan.finish_current_task": + if not self.planner.plan.is_plan_finished(): + self.planner.plan.finish_current_task() + command_output = "Current task is finished. If all tasks are finished, use 'end' to stop." elif cmd["command_name"] == "end": self._set_state(-1) @@ -420,6 +421,21 @@ class RoleZero(Role): ) return plan_status, current_task + def _format_plan_status(self, plan_status): + """format plan status""" + # Example: + # [GOAL] create a 2048 game + # [TASK_ID 1] (finished) Create a Product Requirement Document (PRD) for the 2048 game. This task depends on tasks[]. [Assign to Alice] + # [TASK_ID 2] ( ) Design the system architecture for the 2048 game. This task depends on tasks[1]. [Assign to Bob] + plan_status_formated = f"[GOAL] {plan_status['goal']}\n" + if len(plan_status["tasks"]) > 0: + plan_status_formated += "[Plan]\n" + for task in plan_status["tasks"]: + plan_status_formated += f"[TASK_ID {task['task_id']}] ({'finished' if task['is_finished'] else ' '}){task['instruction']} This task depends on tasks{task['dependent_task_ids']}. [Assign to {task['assignee']}]\n" + else: + plan_status_formated += "No Plan \n" + return plan_status_formated + def _retrieve_experience(self) -> str: """Default implementation of experience retrieval. Can be overwritten in subclasses.""" context = [str(msg) for msg in self.rc.memory.get(self.memory_k)] From 22841804a575c1812f211e07398f0461ca53c95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Wed, 14 Aug 2024 16:02:35 +0800 Subject: [PATCH 2/5] fix format issues --- metagpt/prompts/di/role_zero.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index b6faa8cb3..22222478d 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -38,7 +38,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. - # Example {example} @@ -46,7 +45,8 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet # Instruction {instruction} """ - +EXAMPLE = "" +# Example CMD_PROMPT = """ {current_state} From 91a0637174ef9f170605fbb2582f0d89ede18210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Wed, 14 Aug 2024 16:07:11 +0800 Subject: [PATCH 3/5] fix format issues --- metagpt/prompts/di/role_zero.py | 5 ++--- metagpt/roles/di/role_zero.py | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 22222478d..3da073dfd 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -38,15 +38,14 @@ 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. + # Example {example} - # Instruction {instruction} """ -EXAMPLE = "" -# Example + CMD_PROMPT = """ {current_state} diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 1fa1930e8..39f0cbd1c 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -155,7 +155,7 @@ class RoleZero(Role): ### 2. Plan Status ### plan_status, current_task = self._get_plan_status() - plan_status_formated = self._format_plan_status(plan_status) + formatted_plan_status = self._format_plan_status(plan_status) ### 3. Tool/Command Info ### tools = await self.tool_recommender.recommend_tools() @@ -170,7 +170,7 @@ class RoleZero(Role): ### Make Decision Dynamically ### prompt = self.cmd_prompt.format( current_state=self.cmd_prompt_current_state, - plan_status=plan_status_formated, + plan_status=formatted_plan_status, current_task=current_task, requirements_constraints=self.requirements_constraints, ) @@ -427,14 +427,14 @@ class RoleZero(Role): # [GOAL] create a 2048 game # [TASK_ID 1] (finished) Create a Product Requirement Document (PRD) for the 2048 game. This task depends on tasks[]. [Assign to Alice] # [TASK_ID 2] ( ) Design the system architecture for the 2048 game. This task depends on tasks[1]. [Assign to Bob] - plan_status_formated = f"[GOAL] {plan_status['goal']}\n" + formatted_plan_status = f"[GOAL] {plan_status['goal']}\n" if len(plan_status["tasks"]) > 0: - plan_status_formated += "[Plan]\n" + formatted_plan_status += "[Plan]\n" for task in plan_status["tasks"]: - plan_status_formated += f"[TASK_ID {task['task_id']}] ({'finished' if task['is_finished'] else ' '}){task['instruction']} This task depends on tasks{task['dependent_task_ids']}. [Assign to {task['assignee']}]\n" + formatted_plan_status += f"[TASK_ID {task['task_id']}] ({'finished' if task['is_finished'] else ' '}){task['instruction']} This task depends on tasks{task['dependent_task_ids']}. [Assign to {task['assignee']}]\n" else: - plan_status_formated += "No Plan \n" - return plan_status_formated + formatted_plan_status += "No Plan \n" + return formatted_plan_status def _retrieve_experience(self) -> str: """Default implementation of experience retrieval. Can be overwritten in subclasses.""" From c757d3985211e2865840acaaa1ecd2e253099e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Wed, 14 Aug 2024 16:09:37 +0800 Subject: [PATCH 4/5] fix format issues --- metagpt/prompts/di/role_zero.py | 1 - 1 file changed, 1 deletion(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 3da073dfd..c26bad164 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -38,7 +38,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. - # Example {example} From 31082399c99553f225237db720b0858ce67cd21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Wed, 14 Aug 2024 20:39:53 +0800 Subject: [PATCH 5/5] combine _format_plan_status and _get_plan_status --- metagpt/roles/di/role_zero.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 39f0cbd1c..e12bd97c9 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -155,8 +155,6 @@ class RoleZero(Role): ### 2. Plan Status ### plan_status, current_task = self._get_plan_status() - formatted_plan_status = self._format_plan_status(plan_status) - ### 3. Tool/Command Info ### tools = await self.tool_recommender.recommend_tools() tool_info = json.dumps({tool.name: tool.schemas for tool in tools}) @@ -170,7 +168,7 @@ class RoleZero(Role): ### Make Decision Dynamically ### prompt = self.cmd_prompt.format( current_state=self.cmd_prompt_current_state, - plan_status=formatted_plan_status, + plan_status=plan_status, current_task=current_task, requirements_constraints=self.requirements_constraints, ) @@ -419,10 +417,7 @@ class RoleZero(Role): if self.planner.plan.current_task else "" ) - return plan_status, current_task - - def _format_plan_status(self, plan_status): - """format plan status""" + # format plan status # Example: # [GOAL] create a 2048 game # [TASK_ID 1] (finished) Create a Product Requirement Document (PRD) for the 2048 game. This task depends on tasks[]. [Assign to Alice] @@ -434,7 +429,7 @@ class RoleZero(Role): formatted_plan_status += f"[TASK_ID {task['task_id']}] ({'finished' if task['is_finished'] else ' '}){task['instruction']} This task depends on tasks{task['dependent_task_ids']}. [Assign to {task['assignee']}]\n" else: formatted_plan_status += "No Plan \n" - return formatted_plan_status + return formatted_plan_status, current_task def _retrieve_experience(self) -> str: """Default implementation of experience retrieval. Can be overwritten in subclasses."""