Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

Merge branch 'mgx_ops' into add_swe_agent_ablilities_to_engineer2

黄伟韬2837dc16cec6
diff --cc metagpt/roles/di/engineer2.py
index bee5aa04d,7a862dfcd..92ecb633d
--- a/metagpt/roles/di/engineer2.py
+++ b/metagpt/roles/di/engineer2.py
@@@ -33,45 -25,16 +33,46 @@@ class Engineer2(RoleZero)
profile: str = "Engineer"
goal: str = "Take on game, app, and web development."
instruction: str = ENGINEER2_INSTRUCTION
-
+ cmd_prompt: str = ENGINEER2_CMD_PROMPT
terminal: Terminal = Field(default_factory=Terminal, exclude=True)
- tools: list[str] = ["Plan", "Editor:read", "RoleZero", "Terminal:run_command", "SearchEnhancedQA", "Engineer2"]
+ tools: list[str] = [
+ "Plan",
+ "Editor",
+ "RoleZero",
- "Terminal",
++ "Terminal:run_command",
+ "Browser:goto,scroll",
+ "git_create_pull",
++ "SearchEnhancedQA",
+ "Engineer2",
+ ]
+ # SWE Agent parameter
+ run_eval: bool = False
+ output_diff: str = ""
+ max_react_loop: int = 40
+
+ async def _think(self) -> bool:
+ await self._format_instruction()
+ res = await super()._think()
+ return res
+
+ async def _format_instruction(self):
+ """
+ Formats the instruction message for the Engineer2.
+ Uses Editor's state to format the `_instruction` template.
+ """
+ bash_working_dir = await self.terminal.run_command("pwd")
+ bash_state = {"working_dir": bash_working_dir}
+ editor_state = {"open_file": self.editor.current_file, "working_dir": self.editor.working_dir}
+ self.cmd_prompt_current_state = CURRENT_EDITOR_STATE.format(
+ **editor_state
+ ).strip() + CURRENT_TERMINAL_STATE.format(**bash_state)
def _update_tool_execution(self):
- # validate = ValidateAndRewriteCode()
self.tool_execution_map.update(
{
- "Terminal.run_command": self.terminal.run_command,
+ "Terminal.run_command": self.eval_terminal_run if self.run_eval else self.terminal.run_command,
+ "git_create_pull": git_create_pull,
"Engineer2.write_new_code": self.write_new_code,
# "ValidateAndRewriteCode.run": validate.run,
# "ValidateAndRewriteCode": validate.run,