Add a "finish current task" command before the "end" command for the engineer and the data analyst.

This commit is contained in:
黄伟韬 2024-07-31 14:52:34 +08:00
parent 1cff6752b8
commit 28059f14df
4 changed files with 28 additions and 10 deletions

View file

@ -10,6 +10,7 @@ EXTRA_INSTRUCTION = """
7. When you are making plan. It is highly recommend to plan and append all the tasks in first response once time.
8. Don't finish_current_task multiple times for the same task.
9. Finish current task timely, such as when the code is written and executed successfully.
10. When using the command 'end', add the command 'finish_current_task' before it.
"""
TASK_TYPE_DESC = "\n".join([f"- **{tt.type_name}**: {tt.value.desc}" for tt in TaskType])

View file

@ -39,6 +39,7 @@ Fifth, describe if you should terminate, you should use **end** command to termi
- All tasks are finished and current task is empty
- You are repetitively replying to human
Sixth, when planning, describe the requirements as they pertain to software development, data analysis, or other areas. If the requirements is a software development and no specific restrictions are mentioned, you must create a Product Requirements Document (PRD), write a System Design document, develop a project schedule, and then begin coding. List the steps you will undertake. Plan these steps in a single response.
Seventh, describe the technologies you must use.
Finally, combine your thoughts, describe what you want to do conscisely in 20 words, including which process you will taked and whether you will end, then follow your thoughts to list the commands, adhering closely to the instructions provided.
"""
QUICK_THINK_SYSTEM_PROMPT = """

View file

@ -3,7 +3,7 @@ from __future__ import annotations
from pydantic import Field, model_validator
from metagpt.actions.di.execute_nb_code import ExecuteNbCode
from metagpt.actions.di.write_analysis_code import WriteAnalysisCode, CheckData
from metagpt.actions.di.write_analysis_code import CheckData, WriteAnalysisCode
from metagpt.logs import logger
from metagpt.prompts.di.data_analyst import (
CODE_STATUS,
@ -111,15 +111,11 @@ class DataAnalyst(RoleZero):
return output
async def _check_data(self):
if (
not self.planner.plan.get_finished_tasks()
or self.planner.plan.current_task.task_type
not in [
TaskType.DATA_PREPROCESS.type_name,
TaskType.FEATURE_ENGINEERING.type_name,
TaskType.MODEL_TRAIN.type_name,
]
):
if not self.planner.plan.get_finished_tasks() or self.planner.plan.current_task.task_type not in [
TaskType.DATA_PREPROCESS.type_name,
TaskType.FEATURE_ENGINEERING.type_name,
TaskType.MODEL_TRAIN.type_name,
]:
return
logger.info("Check updated data")
code = await CheckData().run(self.planner.plan)
@ -130,3 +126,13 @@ class DataAnalyst(RoleZero):
print(result)
data_info = DATA_INFO.format(info=result)
self.rc.working_memory.add(Message(content=data_info, role="user", cause_by=CheckData))
async def _run_special_command(self, cmd) -> str:
"""command requiring special check or parsing."""
# finish current task before end.
command_output = ""
if cmd["command_name"] == "end" and not self.planner.plan.is_plan_finished():
self.planner.plan.finish_current_task()
command_output += "Current task is finished. \n"
command_output += await super()._run_special_command(cmd)
return command_output

View file

@ -26,3 +26,13 @@ class Engineer2(RoleZero):
def _retrieve_experience(self) -> str:
return ENGINEER_EXAMPLE
async def _run_special_command(self, cmd) -> str:
"""command requiring special check or parsing."""
# finish current task before end.
command_output = ""
if cmd["command_name"] == "end" and not self.planner.plan.is_plan_finished():
self.planner.plan.finish_current_task()
command_output += "Current task is finished. \n"
command_output += await super()._run_special_command(cmd)
return command_output