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] =?UTF-8?q?fixbug:u=E4=BC=98=E5=8C=96=E4=BA=86=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=89=A7=E8=A1=8C=E7=9A=84=E9=94=99=E8=AF=AF=E5=92=8C?= =?UTF-8?q?engineer=E6=8F=90=E6=97=A9=E7=BB=93=E6=9D=9F=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=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)]