mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
合并teamleader,swe-agent的原系统提示词
This commit is contained in:
parent
ea990d8d68
commit
f338d168ca
6 changed files with 60 additions and 78 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 -----
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue