From d788722bc2e9f4ce7f77c43cba6dae867e8a643f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Fri, 9 Aug 2024 19:51:00 +0800 Subject: [PATCH] =?UTF-8?q?=20=E5=90=88=E5=B9=B6teamleader=20=E5=92=8Cswea?= =?UTF-8?q?gent=E7=9A=84=E5=8E=9F=E7=B3=BB=E7=BB=9F=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/prompts/di/role_zero.py | 2 ++ metagpt/prompts/di/swe_agent.py | 6 ++++-- metagpt/roles/di/role_zero.py | 2 ++ metagpt/roles/di/swe_agent.py | 8 ++++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index a92a3c075..9742cab4a 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -48,6 +48,8 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet """ CMD_PROMPT = """ +{current_state} + # Current Plan {plan_status} diff --git a/metagpt/prompts/di/swe_agent.py b/metagpt/prompts/di/swe_agent.py index 87332f9ef..a737d4a72 100644 --- a/metagpt/prompts/di/swe_agent.py +++ b/metagpt/prompts/di/swe_agent.py @@ -233,10 +233,12 @@ These examples are provided to demonstrate the output style that expected to be # IMPORTANT TIPS {IMPORTANT_TIPS} + +Avoid repeating the same command. Instead, please think about the current situation and provide the next bash command to execute in JSON format:" +""" +CURRENT_BASH_STATE = """ # Output Next Step The current bash state is: (Open file: {{open_file}}) (Current directory: {{working_dir}}) - -Avoid repeating the same command. Instead, please think about the current situation and provide the next bash command to execute in JSON format:" """ diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index af15fb745..75d070822 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -49,6 +49,7 @@ class RoleZero(Role): goal: str = "" system_prompt: str = SYSTEM_PROMPT # Use None to conform to the default value at llm.aask cmd_prompt: str = CMD_PROMPT + cmd_prompt_current_state: str = "" thought_guidance: str = THOUGHT_GUIDANCE instruction: str = ROLE_INSTRUCTION task_type_desc: str = None @@ -161,6 +162,7 @@ class RoleZero(Role): ### Make Decision Dynamically ### prompt = self.cmd_prompt.format( + current_state=self.cmd_prompt_current_state, plan_status=plan_status, current_task=current_task, requirements_constraints=self.requirements_constraints, diff --git a/metagpt/roles/di/swe_agent.py b/metagpt/roles/di/swe_agent.py index c8081066e..13fc87c60 100644 --- a/metagpt/roles/di/swe_agent.py +++ b/metagpt/roles/di/swe_agent.py @@ -3,7 +3,11 @@ import json from pydantic import Field from metagpt.logs import logger -from metagpt.prompts.di.swe_agent import MINIMAL_EXAMPLE, NEXT_STEP_TEMPLATE +from metagpt.prompts.di.swe_agent import ( + CURRENT_BASH_STATE, + MINIMAL_EXAMPLE, + NEXT_STEP_TEMPLATE, +) from metagpt.roles.di.role_zero import RoleZero from metagpt.tools.libs.git import git_create_pull from metagpt.tools.libs.terminal import Bash @@ -49,7 +53,7 @@ class SWEAgent(RoleZero): """ state_output = await self.terminal.run("state") bash_state = json.loads(state_output) - self.instruction = self._instruction.format(**bash_state).strip() + self.cmd_prompt_current_state = CURRENT_BASH_STATE.formate(**bash_state).strip() async def _parse_commands_for_eval(self): """