From 075a82e6f499856927d9b7465c2804e035231241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Thu, 8 Aug 2024 20:44:12 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=B0=86=E8=A7=92=E8=89=B2=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=EF=BC=8C=E8=A7=92=E8=89=B2instruction=E5=92=8C?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E5=8A=A0=E5=85=A5=E5=BC=80=E5=A7=8B=E7=9A=84?= =?UTF-8?q?system=5Fprompt=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/prompts/di/role_zero.py | 36 ++++++++++++++++++++++----------- metagpt/roles/di/role_zero.py | 25 ++++++++++++++++------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 8443a7960..de4bdb066 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -11,9 +11,14 @@ Note: 5. Avoid repeating tasks you have already completed. And end loop when all requirements are met. """ # To ensure compatibility with hard-coded experience, do not add any other content between "# Example" and "# Instruction". -CMD_PROMPT = """ + +#################### # Latest Observation -{latest_observation} +# {latest_observation} + + +########################### +INSTRUCTION_GUIDANCE = """ # Data Structure class Task(BaseModel): @@ -30,11 +35,6 @@ class Task(BaseModel): {available_commands} Special Command: Use {{"command_name": "end"}} to do nothing or indicate completion of all requirements and the end of actions. -# Current Plan -{plan_status} - -# Current Task -{current_task} # Example {example} @@ -42,6 +42,22 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet # Instruction {instruction} +""" + + +# {thought_guidance} +# 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. + +CMD_PROMPT = """ +# Current Plan +{plan_status} + +# Current Task +{current_task} + +# Restrictions +{requirements_constraints} + Pay close attention to the Example provided, you can reuse the example for your current situation if it fits. You may use any of the available commands to create a plan or update the plan. You may output mutiple commands, they will be executed sequentially. @@ -49,14 +65,9 @@ If you finish current task, you will automatically take the next task in the exi Review the latest plan's outcome, focusing on achievements. If your completed task matches the current, consider it finished. In your response, include at least one command. -# Restrictions -{requirements_constraints} - # Your commands in a json array, in the following output format with correct command_name and args. If there is nothing to do, use the pass or end command: Some text indicating your thoughts before JSON is required, such as what tasks have been completed, what tasks are next, how you should update the plan status, respond to inquiry, or seek for help. Then a json array of commands. You must output ONE and ONLY ONE json array. DON'T output multiple json arrays with thoughts between them. Output should adhere to the following format. -{thought_guidance} -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. ```json [ {{ @@ -68,6 +79,7 @@ Finally, combine your thoughts, describe what you want to do conscisely in 20 wo ``` Notice: your output JSON data section must start with **```json [** """ + THOUGHT_GUIDANCE = """ First, describe the actions you have taken recently. Second, describe the messages you have received recently, with a particular emphasis on messages from users. If necessary, develop a plan to address the new user requirements. diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 773124dcc..388eca13e 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -19,6 +19,7 @@ from metagpt.logs import logger from metagpt.prompts.di.role_zero import ( ASK_HUMAN_COMMAND, CMD_PROMPT, + INSTRUCTION_GUIDANCE, JSON_REPAIR_PROMPT, QUICK_THINK_PROMPT, REGENERATE_PROMPT, @@ -47,6 +48,7 @@ class RoleZero(Role): profile: str = "RoleZero" goal: str = "" system_msg: list[str] = None # Use None to conform to the default value at llm.aask + instruction_system_prpomt: str = INSTRUCTION_GUIDANCE cmd_prompt: str = CMD_PROMPT thought_guidance: str = THOUGHT_GUIDANCE instruction: str = ROLE_INSTRUCTION @@ -152,18 +154,25 @@ class RoleZero(Role): tools = await self.tool_recommender.recommend_tools() tool_info = json.dumps({tool.name: tool.schemas for tool in tools}) - ### Make Decision Dynamically ### - memory = self.rc.memory.get(self.memory_k) instruction = self.instruction.strip() - prompt = self.cmd_prompt.format( + instruction_system_prpomt = self.instruction_system_prpomt.format( example=example, available_commands=tool_info, + instruction=instruction, task_type_desc=self.task_type_desc, + ) + guidance_system_msgs = [instruction_system_prpomt] + if self.system_msg: + guidance_system_msgs = self.system_msg + guidance_system_msgs + + # print(("\n"+"="*10+"\n").join(guidance_system_msgs)) + ### Make Decision Dynamically ### + memory = self.rc.memory.get(self.memory_k) + prompt = self.cmd_prompt.format( plan_status=plan_status, current_task=current_task, - instruction=instruction, - thought_guidance=self.thought_guidance, - latest_observation=memory[-1].content, + # thought_guidance=self.thought_guidance, + # latest_observation=memory[-1].content, requirements_constraints=self.requirements_constraints, ) memory = await self.parse_browser_actions(memory) @@ -175,7 +184,9 @@ class RoleZero(Role): current_task=current_task, instruction=instruction, ) - self.command_rsp = await self.llm_cached_aask(req=req, system_msgs=self.system_msg, state_data=state_data) + self.command_rsp = await self.llm_cached_aask( + req=req, system_msgs=guidance_system_msgs, state_data=state_data + ) self.command_rsp = await self._check_duplicates(req, self.command_rsp) From ea990d8d6876b93daaee1779284575a232c9915e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Thu, 8 Aug 2024 21:10:08 +0800 Subject: [PATCH 2/5] combine_system_prompt --- metagpt/roles/di/role_zero.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 388eca13e..8093eda40 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -163,16 +163,13 @@ class RoleZero(Role): ) guidance_system_msgs = [instruction_system_prpomt] if self.system_msg: - guidance_system_msgs = self.system_msg + guidance_system_msgs + guidance_system_msgs = [self.system_msg[0] + guidance_system_msgs[0]] - # print(("\n"+"="*10+"\n").join(guidance_system_msgs)) ### Make Decision Dynamically ### memory = self.rc.memory.get(self.memory_k) prompt = self.cmd_prompt.format( plan_status=plan_status, current_task=current_task, - # thought_guidance=self.thought_guidance, - # latest_observation=memory[-1].content, requirements_constraints=self.requirements_constraints, ) memory = await self.parse_browser_actions(memory) From f338d168ca5183c1a7e958fc87b0a295ee203896 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 18:58:51 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=90=88=E5=B9=B6teamleader=EF=BC=8Cswe-ag?= =?UTF-8?q?ent=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 | 15 +++--- metagpt/prompts/di/swe_agent.py | 81 +++++++++++++++---------------- metagpt/prompts/di/team_leader.py | 8 +-- metagpt/roles/di/role_zero.py | 25 ++++------ metagpt/roles/di/swe_agent.py | 7 +-- metagpt/roles/di/team_leader.py | 2 - 6 files changed, 60 insertions(+), 78 deletions(-) diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index de4bdb066..a92a3c075 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -12,13 +12,16 @@ Note: """ # To ensure compatibility with hard-coded experience, do not add any other content between "# Example" and "# Instruction". -#################### +########################## ignore guidance + # Latest Observation # {latest_observation} +# {thought_guidance} +# 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. ########################### -INSTRUCTION_GUIDANCE = """ +SYSTEM_PROMPT = """ # Data Structure class Task(BaseModel): @@ -44,10 +47,6 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet {instruction} """ - -# {thought_guidance} -# 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. - CMD_PROMPT = """ # Current Plan {plan_status} @@ -58,7 +57,6 @@ CMD_PROMPT = """ # Restrictions {requirements_constraints} - Pay close attention to the Example provided, you can reuse the example for your current situation if it fits. You may use any of the available commands to create a plan or update the plan. You may output mutiple commands, they will be executed sequentially. If you finish current task, you will automatically take the next task in the existing plan, use Plan.finish_task, DON'T append a new task. @@ -112,6 +110,9 @@ JSON_REPAIR_PROMPT = """ ## json data {json_data} +## json decode error +{json_decode_error} + ## Output Format ```json diff --git a/metagpt/prompts/di/swe_agent.py b/metagpt/prompts/di/swe_agent.py index 7455cf30a..87332f9ef 100644 --- a/metagpt/prompts/di/swe_agent.py +++ b/metagpt/prompts/di/swe_agent.py @@ -4,48 +4,6 @@ You can find the original examples from the SWE-agent project here: https://github.com/princeton-nlp/SWE-agent/tree/main/config/configs """ -SWE_AGENT_SYSTEM_TEMPLATE = """ -SETTING: You are an autonomous programmer, and you're working directly in the environment line with a special interface. - -The special interface consists of a file editor that shows you 100 lines of a file at a time. - -Please note that THE EDIT COMMAND REQUIRES PROPER INDENTATION. Pay attention to the original indentation when replacing the function. -If you'd like to add the line ' print(x)' you must fully write that out, with all those spaces before the code! Indentation is important and code that is not indented correctly will fail and require fixing before it can be run. -Always review your changes post-edit to ensure they accurately reflect your intentions. If the changes are not as desired, don't hesitate to issue another command to correct them. - -Your output should always contain a section of reasoning and a command described in JSON format. - -Use \\n to represent line breaks, ensuring the command conforms to the JSON format and is displayed on a single line. Except for the `edit` command, each parameter of the command needs to be enclosed in single quotes. -As shown in the example below: - -First I'll start by using ls to see what files are in the current directory. Then maybe we can look at some relevant files to see what they look like. - -```json -{{ - "command_name": "Bash.run", - "args": {{ - "cmd": "ls -a" - }} -}} -``` - -You should only include a *SINGLE* command in the command section and then wait for a response from the shell before continuing with more discussion and commands. Everything you include in the DISCUSSION section will be saved for future reference. -If you'd like to issue two commands at once, PLEASE DO NOT DO THAT! Please instead first submit just the first command, and then after receiving a response you'll be able to issue the second command. -Remember, YOU CAN ONLY ENTER ONE COMMAND AT A TIME. You should always wait for feedback after every command. - -You can use any bash commands you want (e.g., find, grep, cat, ls, cd) or any custom special tools (including `edit`) by calling Bash.run. Edit all the files you need. -You should carefully observe the behavior and results of the previous action, and avoid triggering repeated errors. - -However, the Bash.run does NOT support interactive session commands (e.g. python, vim), so please do not invoke them. - -In addition to the terminal, I also provide additional tools. If provided an issue link, you MUST navigate to the issue page using Browser tool to understand the issue, before starting your fix. - -# INSTRUCTIONS: -Your first action must be to check if the repository exists at the current path. If it exists, navigate to the repository path. If the repository doesn't exist, please download it and then navigate to it. -All subsequent actions must be performed within this repository path. Do not leave this directory to execute any actions at any time. -Your terminal session has started, and you can use any bash commands or the special interface to help you. Edit all the files you need. -""" - MINIMAL_EXAMPLE = """ ## Example of a actions trajectory User Requirement and Issue: Fix the bug in the repo. Because the environment is not available, you DO NOT need to run and modify any existing test case files or add new test case files to ensure that the bug is fixed. @@ -227,6 +185,45 @@ IMPORTANT_TIPS = """ """ NEXT_STEP_TEMPLATE = f""" +SETTING: You are an autonomous programmer, and you're working directly in the environment line with a special interface. + +The special interface consists of a file editor that shows you 100 lines of a file at a time. + +Please note that THE EDIT COMMAND REQUIRES PROPER INDENTATION. Pay attention to the original indentation when replacing the function. +If you'd like to add the line ' print(x)' you must fully write that out, with all those spaces before the code! Indentation is important and code that is not indented correctly will fail and require fixing before it can be run. +Always review your changes post-edit to ensure they accurately reflect your intentions. If the changes are not as desired, don't hesitate to issue another command to correct them. + +Your output should always contain a section of reasoning and a command described in JSON format. + +Use \\n to represent line breaks, ensuring the command conforms to the JSON format and is displayed on a single line. Except for the `edit` command, each parameter of the command needs to be enclosed in single quotes. +As shown in the example below: + +First I'll start by using ls to see what files are in the current directory. Then maybe we can look at some relevant files to see what they look like. + +```json +{{ + "command_name": "Bash.run", + "args": {{ + "cmd": "ls -a" + }} +}} +``` + +You should only include a *SINGLE* command in the command section and then wait for a response from the shell before continuing with more discussion and commands. Everything you include in the DISCUSSION section will be saved for future reference. +If you'd like to issue two commands at once, PLEASE DO NOT DO THAT! Please instead first submit just the first command, and then after receiving a response you'll be able to issue the second command. +Remember, YOU CAN ONLY ENTER ONE COMMAND AT A TIME. You should always wait for feedback after every command. + +You can use any bash commands you want (e.g., find, grep, cat, ls, cd) or any custom special tools (including `edit`) by calling Bash.run. Edit all the files you need. +You should carefully observe the behavior and results of the previous action, and avoid triggering repeated errors. + +However, the Bash.run does NOT support interactive session commands (e.g. python, vim), so please do not invoke them. + +In addition to the terminal, I also provide additional tools. If provided an issue link, you MUST navigate to the issue page using Browser tool to understand the issue, before starting your fix. + +# INSTRUCTIONS: +Your first action must be to check if the repository exists at the current path. If it exists, navigate to the repository path. If the repository doesn't exist, please download it and then navigate to it. +All subsequent actions must be performed within this repository path. Do not leave this directory to execute any actions at any time. +Your terminal session has started, and you can use any bash commands or the special interface to help you. Edit all the files you need. # Example of Output These examples are provided to demonstrate the output style that expected to be several stages including Locate issue, Fix the bug, Test the fix(Optional), and Submit the changes. It is included to show you how to correctly use the interface. You do not need to follow exactly what is done in the Example. The separator is "-----". ----- Beginning of Examples ----- diff --git a/metagpt/prompts/di/team_leader.py b/metagpt/prompts/di/team_leader.py index 2dd69d189..ad473dfff 100644 --- a/metagpt/prompts/di/team_leader.py +++ b/metagpt/prompts/di/team_leader.py @@ -1,16 +1,12 @@ from metagpt.prompts.di.role_zero import THOUGHT_GUIDANCE -SYSTEM_PROMPT = """ -You are a team leader, and you are responsible for drafting tasks and routing tasks to your team members. -When drafting and routing tasks, ALWAYS include necessary or important info inside the instruction, such as path, link, environment to team members, because you are their sole info source. -Each time you do something, reply to human letting them know what you did. -""" - TL_INSTRUCTION = """ You are a team leader, and you are responsible for drafting tasks and routing tasks to your team members. Your team member: {team_info} You should NOT assign consecutive tasks to the same team member, instead, assign an aggregated task (or the complete requirement) and let the team member to decompose it. +When drafting and routing tasks, ALWAYS include necessary or important info inside the instruction, such as path, link, environment to team members, because you are their sole info source. +Each time you do something, reply to human letting them know what you did. When creating a new plan involving multiple members, create all tasks at once. If plan is created, you should track the progress based on team member feedback message, and update plan accordingly, such as Plan.finish_current_task, Plan.reset_task, Plan.replace_task, etc. You should use TeamLeader.publish_team_message to team members, asking them to start their task. DONT omit any necessary info such as path, link, environment, programming language, framework, requirement, constraint from original content to team members because you are their sole info source. diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 8093eda40..af15fb745 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -19,11 +19,11 @@ from metagpt.logs import logger from metagpt.prompts.di.role_zero import ( ASK_HUMAN_COMMAND, CMD_PROMPT, - INSTRUCTION_GUIDANCE, JSON_REPAIR_PROMPT, QUICK_THINK_PROMPT, REGENERATE_PROMPT, ROLE_INSTRUCTION, + SYSTEM_PROMPT, THOUGHT_GUIDANCE, ) from metagpt.roles import Role @@ -47,8 +47,7 @@ class RoleZero(Role): name: str = "Zero" profile: str = "RoleZero" goal: str = "" - system_msg: list[str] = None # Use None to conform to the default value at llm.aask - instruction_system_prpomt: str = INSTRUCTION_GUIDANCE + system_prompt: str = SYSTEM_PROMPT # Use None to conform to the default value at llm.aask cmd_prompt: str = CMD_PROMPT thought_guidance: str = THOUGHT_GUIDANCE instruction: str = ROLE_INSTRUCTION @@ -154,25 +153,23 @@ class RoleZero(Role): tools = await self.tool_recommender.recommend_tools() tool_info = json.dumps({tool.name: tool.schemas for tool in tools}) + ### Role Instruction ### instruction = self.instruction.strip() - instruction_system_prpomt = self.instruction_system_prpomt.format( - example=example, - available_commands=tool_info, - instruction=instruction, - task_type_desc=self.task_type_desc, + system_prompt = self.system_prompt.format( + task_type_desc=self.task_type_desc, available_commands=tool_info, example=example, instruction=instruction ) - guidance_system_msgs = [instruction_system_prpomt] - if self.system_msg: - guidance_system_msgs = [self.system_msg[0] + guidance_system_msgs[0]] ### Make Decision Dynamically ### - memory = self.rc.memory.get(self.memory_k) prompt = self.cmd_prompt.format( plan_status=plan_status, current_task=current_task, requirements_constraints=self.requirements_constraints, ) + + ### Recent Observation ### + memory = self.rc.memory.get(self.memory_k) memory = await self.parse_browser_actions(memory) + req = self.llm.format_msg(memory + [UserMessage(content=prompt)]) async with ThoughtReporter(enable_llm_stream=True) as reporter: await reporter.async_report({"type": "react"}) @@ -181,9 +178,7 @@ class RoleZero(Role): current_task=current_task, instruction=instruction, ) - self.command_rsp = await self.llm_cached_aask( - req=req, system_msgs=guidance_system_msgs, state_data=state_data - ) + self.command_rsp = await self.llm_cached_aask(req=req, system_msgs=[system_prompt], state_data=state_data) self.command_rsp = await self._check_duplicates(req, self.command_rsp) diff --git a/metagpt/roles/di/swe_agent.py b/metagpt/roles/di/swe_agent.py index 2384ac147..c8081066e 100644 --- a/metagpt/roles/di/swe_agent.py +++ b/metagpt/roles/di/swe_agent.py @@ -3,11 +3,7 @@ import json from pydantic import Field from metagpt.logs import logger -from metagpt.prompts.di.swe_agent import ( - MINIMAL_EXAMPLE, - NEXT_STEP_TEMPLATE, - SWE_AGENT_SYSTEM_TEMPLATE, -) +from metagpt.prompts.di.swe_agent import 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 @@ -17,7 +13,6 @@ class SWEAgent(RoleZero): name: str = "Swen" profile: str = "Issue Solver" goal: str = "Resolve GitHub issue or bug in any existing codebase" - system_msg: str = [SWE_AGENT_SYSTEM_TEMPLATE] _instruction: str = NEXT_STEP_TEMPLATE tools: list[str] = [ "Bash", diff --git a/metagpt/roles/di/team_leader.py b/metagpt/roles/di/team_leader.py index f495c4aaa..12b4b3a18 100644 --- a/metagpt/roles/di/team_leader.py +++ b/metagpt/roles/di/team_leader.py @@ -4,7 +4,6 @@ from metagpt.actions.di.run_command import RunCommand from metagpt.prompts.di.team_leader import ( FINISH_CURRENT_TASK_CMD, QUICK_THINK_SYSTEM_PROMPT, - SYSTEM_PROMPT, TL_INSTRUCTION, TL_THOUGHT_GUIDANCE, ) @@ -19,7 +18,6 @@ class TeamLeader(RoleZero): name: str = "Mike" profile: str = "Team Leader" goal: str = "Manage a team to assist users" - system_msg: list[str] = [SYSTEM_PROMPT] thought_guidance: str = TL_THOUGHT_GUIDANCE # TeamLeader only reacts once each time, but may encounter errors or need to ask human, thus allowing 2 more turns max_react_loop: int = 3 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 4/5] =?UTF-8?q?=20=E5=90=88=E5=B9=B6teamleader=20=E5=92=8C?= =?UTF-8?q?sweagent=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): """ From 812d6a825d21047f96a241cb9c8d23b471d4004c 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 20:47:41 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=88=E5=B9=B6swe-age?= =?UTF-8?q?nt=E7=B3=BB=E7=BB=9F=E6=8F=90=E7=A4=BA=E8=AF=8D=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metagpt/prompts/di/swe_agent.py | 4 ++-- metagpt/roles/di/swe_agent.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/metagpt/prompts/di/swe_agent.py b/metagpt/prompts/di/swe_agent.py index a737d4a72..7151199ad 100644 --- a/metagpt/prompts/di/swe_agent.py +++ b/metagpt/prompts/di/swe_agent.py @@ -239,6 +239,6 @@ Avoid repeating the same command. Instead, please think about the current situat CURRENT_BASH_STATE = """ # Output Next Step The current bash state is: -(Open file: {{open_file}}) -(Current directory: {{working_dir}}) +(Open file: {open_file}) +(Current directory: {working_dir}) """ diff --git a/metagpt/roles/di/swe_agent.py b/metagpt/roles/di/swe_agent.py index 13fc87c60..e1d2c9613 100644 --- a/metagpt/roles/di/swe_agent.py +++ b/metagpt/roles/di/swe_agent.py @@ -53,7 +53,7 @@ class SWEAgent(RoleZero): """ state_output = await self.terminal.run("state") bash_state = json.loads(state_output) - self.cmd_prompt_current_state = CURRENT_BASH_STATE.formate(**bash_state).strip() + self.cmd_prompt_current_state = CURRENT_BASH_STATE.format(**bash_state).strip() async def _parse_commands_for_eval(self): """