From dbdfd29cea5bdd7ef87c16160bd217a61f4ad7d6 Mon Sep 17 00:00:00 2001 From: garylin2099 Date: Sun, 4 Aug 2024 17:33:04 +0800 Subject: [PATCH] equip engineer2 with terminal --- metagpt/prompts/di/role_zero.py | 2 +- metagpt/roles/di/engineer2.py | 8 +++++++- metagpt/roles/di/role_zero.py | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 721fe7e60..9b467bafd 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -115,7 +115,7 @@ Decide if the latest user message previously is a quick question. Quick questions include common-sense, legal, logical, math, multiple-choice questions, greetings, or casual chat that you can answer directly. Questions about you or your team info are also quick questions. Time- or location-sensitive questions such as wheather or news inquiry are NOT quick questions. Moreover, you should output a keyword SEARCH to indicate the need for a google search. -Software development tasks are NOT quick questions. +Software development tasks are NOT quick questions. Code execution, however trivial, is NOT a quick question. However, these programming-related tasks are quick questions: writing trivial code snippets (fewer than 30 lines), filling a single function or class, explaining concepts, writing tutorials and documentation. Respond with a concise thought then a YES if the question is a quick question, otherwise, a NO or a SEARCH. Your response: """ diff --git a/metagpt/roles/di/engineer2.py b/metagpt/roles/di/engineer2.py index fbade0421..f6c3a6658 100644 --- a/metagpt/roles/di/engineer2.py +++ b/metagpt/roles/di/engineer2.py @@ -1,9 +1,12 @@ from __future__ import annotations +from pydantic import Field + from metagpt.actions.write_code_review import ReviewAndRewriteCode from metagpt.prompts.di.engineer2 import ENGINEER2_INSTRUCTION from metagpt.roles.di.role_zero import RoleZero from metagpt.strategy.experience_retriever import ENGINEER_EXAMPLE +from metagpt.tools.libs.terminal import Terminal class Engineer2(RoleZero): @@ -12,13 +15,16 @@ class Engineer2(RoleZero): goal: str = "Take on game, app, and web development." instruction: str = ENGINEER2_INSTRUCTION - tools: list[str] = ["Plan", "Editor:write,read", "RoleZero", "ReviewAndRewriteCode"] + terminal: Terminal = Field(default_factory=Terminal, exclude=True) + + tools: list[str] = ["Plan", "Editor:write,read", "RoleZero", "Terminal:run_command", "ReviewAndRewriteCode"] def _update_tool_execution(self): review = ReviewAndRewriteCode() self.tool_execution_map.update( { + "Terminal.run_command": self.terminal.run_command, "ReviewAndRewriteCode.run": review.run, "ReviewAndRewriteCode": review.run, } diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 3228f4ab2..4e932649c 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -64,7 +64,6 @@ class RoleZero(Role): # Equipped with three basic tools by default for optional use editor: Editor = Editor() browser: Browser = Browser() - # terminal: Terminal = Terminal() # FIXME: TypeError: cannot pickle '_thread.lock' object # Experience experience_retriever: ExpRetriever = DummyExpRetriever()