From 4c4d9547ff553f42fce1ba01a27c418804a3c044 Mon Sep 17 00:00:00 2001 From: lidanyang Date: Tue, 9 Jul 2024 17:01:54 +0800 Subject: [PATCH] support multi write_code steps for one task --- metagpt/schema.py | 4 ++-- metagpt/strategy/planner.py | 10 +++++++++- metagpt/tools/tool_recommend.py | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/metagpt/schema.py b/metagpt/schema.py index 11610b6c3..94e64d7fa 100644 --- a/metagpt/schema.py +++ b/metagpt/schema.py @@ -464,8 +464,8 @@ class Task(BaseModel): self.is_finished = False def update_task_result(self, task_result: TaskResult): - self.code = task_result.code + "\n" + task_result.code - self.result = task_result.result + self.code = self.code + "\n" + task_result.code + self.result = self.result + "\n" + task_result.result self.is_success = task_result.is_success diff --git a/metagpt/strategy/planner.py b/metagpt/strategy/planner.py index 427e41562..95ad1f5cc 100644 --- a/metagpt/strategy/planner.py +++ b/metagpt/strategy/planner.py @@ -40,8 +40,14 @@ PLAN_STATUS = """ ## Current Task {current_task} +## Finished Section of Current Task +### code +{current_task_code} +### execution result +{current_task_result} + ## Task Guidance -Write complete code for 'Current Task'. And avoid duplicating code from 'Finished Tasks', such as repeated import of packages, reading data, etc. +Write code for the incomplete sections of 'Current Task'. And avoid duplicating code from 'Finished Tasks', such as repeated import of packages, reading data, etc. Specifically, {guidance} """ @@ -173,6 +179,8 @@ class Planner(BaseModel): code_written=code_written, task_results=task_results, current_task=self.current_task.instruction, + current_task_code=self.current_task.code if self.current_task.code else "", + current_task_result=self.current_task.result if self.current_task.result else "", guidance=guidance, ) diff --git a/metagpt/tools/tool_recommend.py b/metagpt/tools/tool_recommend.py index ab847d10e..0c596707a 100644 --- a/metagpt/tools/tool_recommend.py +++ b/metagpt/tools/tool_recommend.py @@ -106,11 +106,11 @@ class ToolRecommender(BaseModel): Wrap recommended tools with their info in a string, which can be used directly in a prompt. """ recommended_tools = await self.recommend_tools(**kwargs) + if fix: + recommended_tools.extend([self.tools[tool_name] for tool_name in fix if tool_name in self.tools]) if not recommended_tools: return "" tool_schemas = {tool.name: tool.schemas for tool in recommended_tools} - if fix: - tool_schemas.update({tool.name: tool.schemas for tool in self.tools.values() if tool.name in fix}) return TOOL_INFO_PROMPT.format(tool_schemas=tool_schemas) async def recall_tools(self, context: str = "", plan: Plan = None, topk: int = 20) -> list[Tool]: