save code steps early

This commit is contained in:
yzlin 2023-12-13 13:48:18 +08:00
parent 7c1809af1e
commit 92d59ea31b
3 changed files with 8 additions and 12 deletions

View file

@ -23,9 +23,7 @@ from metagpt.utils.common import create_func_config
class BaseWriteAnalysisCode(Action):
async def run(
self, context: List[Message], plan: Plan = None, task_guide: str = ""
) -> str:
async def run(self, context: List[Message], plan: Plan = None) -> str:
"""Run of a code writing action, used in data analysis or modeling
Args:
@ -85,7 +83,6 @@ class WriteCodeByGenerate(BaseWriteAnalysisCode):
self,
context: [List[Message]],
plan: Plan = None,
code_steps: str = "",
system_msg: str = None,
**kwargs,
) -> str:
@ -155,11 +152,11 @@ class WriteCodeWithTools(BaseWriteAnalysisCode):
self,
context: List[Message],
plan: Plan = None,
code_steps: str = "",
data_desc: str = "",
) -> str:
task_type = plan.current_task.task_type
task = plan.current_task.instruction
code_steps = plan.current_task.code_steps
available_tools = registry.get_all_schema_by_module(task_type)
available_tools = [
{k: tool[k] for k in ["name", "description"] if k in tool}

View file

@ -59,7 +59,7 @@ class MLEngineer(Role):
logger.info(f"ready to take on task {task}")
# take on current task
code, result, success, code_steps = await self._write_and_exec_code()
code, result, success = await self._write_and_exec_code()
# ask for acceptance, users can other refuse and change tasks in the plan
review, task_result_confirmed = await self._ask_review(trigger=ReviewConst.TASK_REVIEW_TRIGGER)
@ -73,7 +73,6 @@ class MLEngineer(Role):
# tick off this task and record progress
task.code = code
task.result = result
task.code_steps = code_steps
self.plan.finish_current_task()
self.working_memory.clear()
@ -102,7 +101,7 @@ class MLEngineer(Role):
return rsp
async def _write_and_exec_code(self, max_retry: int = 3):
code_steps = (
self.plan.current_task.code_steps = (
await WriteCodeSteps().run(self.plan)
if self.use_code_steps
else ""
@ -121,12 +120,12 @@ class MLEngineer(Role):
if not self.use_tools or self.plan.current_task.task_type == "other":
# code = "print('abc')"
code = await WriteCodeByGenerate().run(
context=context, plan=self.plan, code_steps=code_steps, temperature=0.0
context=context, plan=self.plan, temperature=0.0
)
cause_by = WriteCodeByGenerate
else:
code = await WriteCodeWithTools().run(
context=context, plan=self.plan, code_steps=code_steps, data_desc=""
context=context, plan=self.plan, data_desc=""
)
cause_by = WriteCodeWithTools
@ -151,7 +150,7 @@ class MLEngineer(Role):
if ReviewConst.CHANGE_WORD[0] in review:
counter = 0 # redo the task again with help of human suggestions
return code, result, success, code_steps
return code, result, success
async def _ask_review(self, auto_run: bool = None, trigger: str = ReviewConst.TASK_REVIEW_TRIGGER):
auto_run = auto_run or self.auto_run

View file

@ -78,10 +78,10 @@ class Task(BaseModel):
dependent_task_ids: list[str] = [] # Tasks prerequisite to this Task
instruction: str = ""
task_type: str = ""
code_steps: str = ""
code: str = ""
result: str = ""
is_finished: bool = False
code_steps: str = ""
class Plan(BaseModel):