🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
Merge branch 'dev' into kaggle_team
yzlinf7989b0ce099
diff --cc metagpt/roles/ml_engineer.pyindex abd14c7fb,65583638e..4e818ca3c--- a/metagpt/roles/ml_engineer.py+++ b/metagpt/roles/ml_engineer.py@@@ -11,10 -11,59 +12,10 @@@ from metagpt.memory import Memorfrom metagpt.logs import loggerfrom metagpt.actions.write_plan import WritePlanfrom metagpt.actions.write_analysis_code import WriteCodeByGenerate, WriteCodeWithTools- from metagpt.actions.ml_da_action import AskReview, SummarizeAnalysis, Reflect, ReviewConst, truncate++from metagpt.actions.ml_da_action import AskReview, SummarizeAnalysis, Reflect, ReviewConstfrom metagpt.actions.execute_code import ExecutePyCode--STRUCTURAL_CONTEXT = """-## User Requirement-{user_requirement}-## Current Plan-{tasks}-## Current Task-{current_task}-"""---def truncate(result: str, keep_len: int = 1000) -> str:- desc = "Truncated to show only the last 1000 characters\n"- if result.startswith(desc):- result = result[-len(desc) :]-- if len(result) > keep_len:- result = result[-keep_len:]-- if not result.startswith(desc):- return desc + result- return desc---def remove_escape_and_color_codes(input_str):- # 使用正则表达式去除转义字符和颜色代码- pattern = re.compile(r'\x1b\[[0-9;]*[mK]')- result = pattern.sub('', input_str)- return result---class AskReview(Action):- async def run(self, context: List[Message], plan: Plan = None):- logger.info("Current overall plan:")- logger.info(- "\n".join([f"{task.task_id}: {task.instruction}, is_finished: {task.is_finished}" for task in plan.tasks])- )-- logger.info("most recent context:")- latest_action = context[-1].cause_by.__name__ if context[-1].cause_by else ""- prompt = f"\nPlease review output from {latest_action}:\n" \- "If you want to change a task in the plan, say 'change task task_id, ... (things to change)'\n" \- "If you confirm the output and wish to continue with the current process, type CONFIRM\n" \- "If you want to terminate the process, type exit:\n"- rsp = input(prompt)-- if rsp.lower() in ("exit"):- exit()-- confirmed = rsp.lower() in ("confirm", "yes", "y")-- return rsp, confirmed+from metagpt.roles.kaggle_manager import DownloadData, SubmitResult+from metagpt.prompts.ml_engineer import STRUCTURAL_CONTEXTclass WriteTaskGuide(Action):@@@ -122,11 -142,11 +123,9 @@@ class MLEngineer(Role))result, success = await self.execute_code.run(code)-- # truncated the result-- print(truncate(result))-- # print(result)++ print(result)self.working_memory.add(- Message(content=truncate(remove_escape_and_color_codes(result)), role="user", cause_by=ExecutePyCode)+ Message(content=result, role="user", cause_by=ExecutePyCode))if "!pip" in code: