🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
refine code
lidanyang8d6a2801a092
diff --git a/metagpt/roles/di/data_analyst.py b/metagpt/roles/di/data_analyst.pyindex d1ef92c35..25e504e2f 100644--- a/metagpt/roles/di/data_analyst.py+++ b/metagpt/roles/di/data_analyst.py@@ -1,7 +1,5 @@from __future__ import annotations-import re-from pydantic import Field, model_validatorfrom metagpt.actions.di.execute_nb_code import ExecuteNbCode@@ -56,13 +54,11 @@ class DataAnalyst(RoleZero):await self.execute_code.init_code()# plan info- try:- plan_status = self.planner.get_plan_status()- plan_status = re.sub(- r"### execution result.*?(?=## Current Task|## Task Guidance)", "", plan_status, flags=re.DOTALL- )- except AttributeError as e:- return "All tasks have been completed. Please check to end or append task first before writing code."+ if self.planner.current_task:+ # clear task result from plan to save token, since it has been in memory+ plan_status = self.planner.get_plan_status(exclude=["task_result"])+ else:+ return "No current_task found now. Please use command Plan.append_task to add a task first."# tool infoif self.custom_tool_recommender:diff --git a/metagpt/strategy/planner.py b/metagpt/strategy/planner.pyindex fbb5fd838..c54f6be15 100644--- a/metagpt/strategy/planner.py+++ b/metagpt/strategy/planner.py@@ -1,6 +1,7 @@from __future__ import annotationsimport json+from typing import Listfrom pydantic import BaseModel, Field@@ -165,8 +166,9 @@ class Planner(BaseModel):return context_msg + self.working_memory.get()- def get_plan_status(self) -> str:+ def get_plan_status(self, exclude: List[str] = None) -> str:# prepare components of a plan status+ exclude = exclude or []finished_tasks = self.plan.get_finished_tasks()code_written = [remove_comments(task.code) for task in finished_tasks]code_written = "\n\n".join(code_written)@@ -178,11 +180,11 @@ class Planner(BaseModel):# combine components in a promptprompt = PLAN_STATUS.format(- code_written=code_written,- task_results=task_results,+ code_written=code_written if "code" not in exclude else "omit here",+ task_results=task_results if "task_result" not in exclude else "omit here",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 "",+ current_task_code=self.current_task.code if "code" not in exclude else "omit here",+ current_task_result=self.current_task.result if "task_result" not in exclude else "omit here",guidance=guidance,)