mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-02 14:45:17 +02:00
Merge branch 'mgx_ops' into basic_ability
This commit is contained in:
commit
4cc47366f8
94 changed files with 3333 additions and 1200 deletions
|
|
@ -1,44 +1,26 @@
|
|||
CMD_PROMPT = """
|
||||
# Data Structure
|
||||
class Task(BaseModel):
|
||||
task_id: str = ""
|
||||
dependent_task_ids: list[str] = []
|
||||
instruction: str = ""
|
||||
task_type: str = ""
|
||||
assignee: str = "David"
|
||||
from metagpt.strategy.task_type import TaskType
|
||||
|
||||
# Available Commands
|
||||
{available_commands}
|
||||
|
||||
# Current Plan
|
||||
{plan_status}
|
||||
|
||||
# Example
|
||||
{example}
|
||||
|
||||
# Instructions
|
||||
Based on the context, write a plan or modify an existing plan to achieve the goal. A plan consists of one to 3 tasks.
|
||||
If plan is created, you should track the progress and update the plan accordingly, such as finish_current_task, append_task, reset_task, replace_task, etc.
|
||||
Pay close attention to new user message, review the conversation history, use reply_to_human to respond to new user requirement.
|
||||
Note:
|
||||
1. If you keeping encountering errors, unexpected situation, or you are not sure of proceeding, use ask_human to ask for help.
|
||||
2. Carefully review your progress at the current task, if your actions so far has not fulfilled the task instruction, you should continue with current task. Otherwise, finish current task.
|
||||
3. Each time you finish a task, use reply_to_human to report your progress.
|
||||
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 finish_task, DON'T append a new task.
|
||||
|
||||
# Your commands in a json array, in the following output format, always output a json array, if there is nothing to do, use the pass command:
|
||||
Some text indicating your thoughts, such as how you should update the plan status, respond to inquiry, or seek for help. Then a json array of commands.
|
||||
```json
|
||||
[
|
||||
{{
|
||||
"command_name": str,
|
||||
"args": {{"arg_name": arg_value, ...}}
|
||||
}},
|
||||
...
|
||||
]
|
||||
```
|
||||
Notice: your output JSON data section must start with **```json [**
|
||||
BROWSER_INSTRUCTION = """
|
||||
4. Carefully choose to use or not use the browser tool to assist you in web tasks.
|
||||
- When no click action is required, no need to use the browser tool to navigate to the webpage before scraping.
|
||||
- If you need detail HTML content, write code to get it but not to use the browser tool.
|
||||
- Make sure the command_name are certainly in Available Commands when you use the browser tool.
|
||||
"""
|
||||
|
||||
TASK_TYPE_DESC = "\n".join([f"- **{tt.type_name}**: {tt.value.desc}" for tt in TaskType])
|
||||
|
||||
|
||||
CODE_STATUS = """
|
||||
**Code written**:
|
||||
{code}
|
||||
|
||||
**Execution status**: {status}
|
||||
**Execution result**: {result}
|
||||
"""
|
||||
|
||||
|
||||
BROWSER_INFO = """
|
||||
Here are ordered web actions in the browser environment, note that you can not use the browser tool in the current environment.
|
||||
{browser_actions}
|
||||
The latest url is the one you should use to view the page. If view page has been done, directly use the variable and html content in executing result.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ EXTRA_INSTRUCTION = """
|
|||
11. Write out EVERY CODE DETAIL, DON'T LEAVE TODO.
|
||||
12. To modify code in a file, read the entire file, make changes, and update the file with the complete code, ensuring that no line numbers are included in the final write.
|
||||
13. When a system design or project schedule is provided, at the end of the plan, add a CodeRview Task for each file; for example, if there are three files, add three CodeRview Tasks. For each CodeRview Task, just call ReviewAndRewriteCode.run.
|
||||
14. When you are making plan.it is hightly recommand to plan all the coding plan and reviews plan in first response.
|
||||
"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ When presented a current task, tackle the task using the available commands.
|
|||
Pay close attention to new user message, review the conversation history, use RoleZero.reply_to_human to respond to new user requirement.
|
||||
Note:
|
||||
1. If you keeping encountering errors, unexpected situation, or you are not sure of proceeding, use RoleZero.ask_human to ask for help.
|
||||
2. Carefully review your progress at the current task, if your actions so far has not fulfilled the task instruction, you should continue with current task. Otherwise, finish current task.
|
||||
2. Carefully review your progress at the current task, if your actions so far has not fulfilled the task instruction, you should continue with current task. Otherwise, finish current task by Plan.finish_current_task explicitly.
|
||||
3. Each time you finish a task, use RoleZero.reply_to_human to report your progress.
|
||||
4. Don't forget to append task first when all existing tasks are finished and new tasks are required.
|
||||
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 "# Available Commands".
|
||||
CMD_PROMPT = """
|
||||
# Data Structure
|
||||
class Task(BaseModel):
|
||||
|
|
@ -17,6 +19,9 @@ class Task(BaseModel):
|
|||
instruction: str = ""
|
||||
task_type: str = ""
|
||||
assignee: str = ""
|
||||
|
||||
# Available Task Types
|
||||
{task_type_desc}
|
||||
|
||||
# Available Commands
|
||||
{available_commands}
|
||||
|
|
@ -37,9 +42,10 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet
|
|||
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.
|
||||
Pay close attention to what you have done. Be different with your previous action.
|
||||
|
||||
# Your commands in a json array, in the following output format. If there is nothing to do, use the pass or end command:
|
||||
Some text indicating your thoughts, such as 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.
|
||||
# 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.
|
||||
```json
|
||||
[
|
||||
{{
|
||||
|
|
@ -49,6 +55,7 @@ Some text indicating your thoughts, such as how you should update the plan statu
|
|||
...
|
||||
]
|
||||
```
|
||||
Notice: your output JSON data must be a command list.
|
||||
Notice: your output JSON data section must start with **```json [**
|
||||
"""
|
||||
|
||||
|
|
@ -58,9 +65,9 @@ JSON_REPAIR_PROMPT = """
|
|||
|
||||
## Output Format
|
||||
```json
|
||||
Formatted JSON data
|
||||
|
||||
```
|
||||
Help check if there are any formatting issues with the JSON data? If so, please help format it
|
||||
Help check if there are any formatting issues with the JSON data? If so, please help format it.
|
||||
"""
|
||||
|
||||
QUICK_THINK_PROMPT = """
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ 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 {WINDOW} lines of a file at a time.
|
||||
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.
|
||||
|
|
@ -50,7 +50,8 @@ 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.
|
||||
|
||||
### Read and understand issue(Require):
|
||||
### Read and understand issue:
|
||||
Thought: Firstly, I need to review the detailed information of this issue in order to understand the problem that needs fixing.
|
||||
{{
|
||||
"command_name": "Browser.goto",
|
||||
"args": {{
|
||||
|
|
@ -60,43 +61,99 @@ User Requirement and Issue: Fix the bug in the repo. Because the environment is
|
|||
->
|
||||
|
||||
### Locate issue(Require): Locate the issue in the code by searching for the relevant file, function, or class and open the file to view the code.
|
||||
Thought: I need to come under the repo path
|
||||
{{
|
||||
"command_name": "Bash.run",
|
||||
"args": {{
|
||||
"cmd": "cd /workspace/django__django_3.0"
|
||||
"cmd": "cd /workspace/MetaGPT"
|
||||
}}
|
||||
}}
|
||||
->
|
||||
|
||||
Bash.run(cmd='search_dir_and_preview ASCIIUsernameValidator')
|
||||
Thought: Let's start by locating the `openai_api.py` file.\nFirst, let's search for the `openai_api.py` file.
|
||||
{{
|
||||
"command_name": "Bash.run",
|
||||
"args": {{
|
||||
"cmd": "open /workspace/django__django_3.0/django/contrib/auth/validators.py"
|
||||
"cmd": "find_file 'openai_api.py'"
|
||||
}}
|
||||
}}
|
||||
->
|
||||
|
||||
Thought: We have located both the `openai_api.py` file. Let's start by opening the `openai_api.py` file to apply the necessary changes.",
|
||||
{{
|
||||
"command_name": "Bash.run",
|
||||
"args": {{
|
||||
"cmd": "open '/workspace/MetaGPT/provider/openai_api.py'"
|
||||
}}
|
||||
}}
|
||||
->
|
||||
|
||||
### Fix the Bug(Require): Fix the bug in the code by editing the relevant function, class or code snippet.
|
||||
Thought: Now that I've found the bug, let's fix it by edit.
|
||||
{{
|
||||
"command_name": "Bash.run",
|
||||
"args": {{
|
||||
"cmd": "edit 10:20 <<EOF\n regex = r'\A[\w.@+-]+\Z'\n message = _( \n 'Enter a valid username. This value may contain only English letters, ' \n 'numbers, and @/./+/-/_ characters.'\n )\n flags = re.ASCII\n\n@deconstructible\nclass UnicodeUsernameValidator(validators.RegexValidator):\n regex = r'\A[\w.@+-]+\Z'\nEOF"
|
||||
"cmd": "edit 93:95 <<EOF\n usage = None\n collected_messages = []\n async for chunk in response:\n if chunk.usage is not None:\n usage = CompletionUsage(**chunk.usage)\n chunk_message = chunk.choices[0].delta.content or '' if chunk.choices else '' # extract the message\n finish_reason = (\n chunk.choices[0].finish_reason if chunk.choices and hasattr(chunk.choices[0], 'finish_reason') else None\n )\n log_llm_stream(chunk_message)\nEOF"
|
||||
}}
|
||||
}}
|
||||
->
|
||||
Thought: Due to a syntax error related to an undefined name 'Image', we need to address this issue even though it is not directly related to our work. Let's try importing the package to fix it.
|
||||
{{
|
||||
"command_name": "Bash.run",
|
||||
"args": {{
|
||||
"cmd": "edit 14:14 <<EOF\nfrom PIL.Image import Image\nEOF"
|
||||
}}
|
||||
}}
|
||||
->
|
||||
|
||||
### Submit the Changes(Require): Submit the changes to the repository.
|
||||
### Save the Changes (Required): After all changes have been made, save them to the repository.
|
||||
> You must choose one of the following two methods.
|
||||
|
||||
#### Just save the changes locally, it only need one action.
|
||||
Thought: The bug has been fixed. Let's submit the changes.
|
||||
{{
|
||||
"command_name": "Bash.run",
|
||||
"args": {{
|
||||
"cmd": "submit"
|
||||
}}
|
||||
}}
|
||||
Bash.run(cmd='submit')
|
||||
->
|
||||
|
||||
#### Save the changes and commit them to the remote repository.
|
||||
|
||||
##### Push the changes from the local repository to the remote repository.
|
||||
Thought: All changes have been saved, let's push the code to the remote repository.
|
||||
{{
|
||||
"command_name": "end",
|
||||
"command_name": "git_push",
|
||||
"args": {{
|
||||
"local_path": "/workspace/MetaGPT",
|
||||
"app_name": "github",
|
||||
"comments": "Fix Issue #1275: produced TypeError: openai.types.completion_usage.CompletionUsage() argument after ** must be a mapping, not NoneType"",
|
||||
"new_branch": "test-fix"
|
||||
}}
|
||||
}}
|
||||
->
|
||||
|
||||
##### Create a pull request (Optional): Merge the changes from the new branch into the master branch.
|
||||
Thought: Now that the changes have been pushed to the remote repository, due to the user's requirement, let's create a pull request to merge the changes into the master branch.
|
||||
[{{
|
||||
"command_name": "git_create_pull",
|
||||
"args": {{
|
||||
"base": "master",
|
||||
"head": "test-fix",
|
||||
"base_repo_name": "garylin2099/MetaGPT",
|
||||
"head_repo_name": "seeker-jie/MetaGPT",
|
||||
"app_name": "github",
|
||||
"title": "Fix Issue #1275: produced TypeError: openai.types.completion_usage.CompletionUsage() argument after ** must be a mapping, not NoneType"",
|
||||
"body": "This pull request addresses issue #1275 by ensuring that chunk.usage is not None before passing it to CompletionUsage."
|
||||
}}
|
||||
}}]
|
||||
->
|
||||
|
||||
### Finally
|
||||
Thought: All task has been done, let's end the conversation.
|
||||
{{
|
||||
"command_name": "end"
|
||||
}}
|
||||
"""
|
||||
|
||||
|
|
@ -162,7 +219,10 @@ IMPORTANT_TIPS = """
|
|||
- If a search command fails, modify the search criteria and check for typos or incorrect paths, then try again.
|
||||
- Based on feedback of observation or bash command in trajectory to guide adjustments in your search strategy.
|
||||
|
||||
13. If the task results in succeed, fail, or NO PROGRESS, output `submit`.
|
||||
13. Save the code change:
|
||||
- If you need to submit changes to the remote repository, first use the regular git commit command to save the changes locally, then select a command from the `Available Commands: [git_push, git_create_pull]` to submit the changes to the remote repository.
|
||||
|
||||
- If you don't need to submit code changes to the remote repository. use the command Bash.run('submit') to commit the changes locally.
|
||||
|
||||
14. If provided an issue link, you MUST go to the issue page using Browser tool to understand the issue before starting your fix.
|
||||
|
||||
|
|
@ -185,5 +245,4 @@ The current bash state is:
|
|||
(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:"
|
||||
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -28,7 +28,10 @@ your code
|
|||
```
|
||||
"""
|
||||
|
||||
REFLECTION_SYSTEM_MSG = """You are an AI Python assistant. You will be given your previous implementation code of a task, runtime error results, and a hint to change the implementation appropriately. Write your full implementation."""
|
||||
REFLECTION_SYSTEM_MSG = """
|
||||
You are an AI Python assistant. You will be given your previous implementation code of a task, runtime error results, and a hint to change the implementation appropriately. Write your full implementation.
|
||||
When occuring ModuleNotFoundError, always install the required package. And use Terminal tool if available.
|
||||
"""
|
||||
|
||||
DEBUG_REFLECTION_EXAMPLE = '''
|
||||
[previous impl]:
|
||||
|
|
|
|||
|
|
@ -53,3 +53,9 @@ The current task is about converting image into webpage code. please note the fo
|
|||
- Single-Step Code Generation: Execute the entire code generation process in a single step, encompassing HTML, CSS, and JavaScript. Avoid fragmenting the code generation into multiple separate steps to maintain consistency and simplify the development workflow.
|
||||
- Save webpages: Be sure to use the save method provided.
|
||||
"""
|
||||
|
||||
# Prompt for taking on "web_scraping" tasks
|
||||
WEB_SCRAPING_PROMPT = """
|
||||
- Remember to view and print the necessary HTML content in a separate task to understand the structure first before scraping data. Such as `html_content = await view_page_element_to_scrape(...)\nprint(html_content)`.
|
||||
- Since the data required by user may not correspond directly to the actual HTML element names, you should thoroughly analyze the HTML structure and meanings of all elements in the executing result first. Ensure the `class_` in your code should derived from the actual HTML structure directly, not based on your knowledge. To ensure it, analyse the most suitable location of the 'class_' in the actual HTML content before code.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue