mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
Merge branch 'fix_lang_inconsistency_mgx_output_user_input' into 'mgx_ops'
优化了 teamleader 自组织步骤的问题。解决了输入输出语言不一致的问题。 See merge request pub/MetaGPT!258
This commit is contained in:
commit
1e805de588
7 changed files with 95 additions and 10 deletions
68
metagpt/actions/anaylze_requirements.py
Normal file
68
metagpt/actions/anaylze_requirements.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
from metagpt.actions import Action
|
||||
|
||||
ANALYZE_REQUIREMENTS = """
|
||||
# Example
|
||||
{examples}
|
||||
|
||||
# Requirements
|
||||
{requirements}
|
||||
|
||||
# Instructions
|
||||
{instructions}
|
||||
|
||||
# Output Format
|
||||
{output_format}
|
||||
|
||||
Follow the instructions and output format. Do not include any additional content.
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
Example 1
|
||||
Requirements:
|
||||
Create 2048 game. Do not write PRD.
|
||||
Outputs:
|
||||
[User Restrictions] : Do not write PRD.
|
||||
[Language Restrictions] : The response must be in the language specified by English.
|
||||
|
||||
Example 2
|
||||
Requirements:
|
||||
创建一个贪吃蛇,只需要给出设计文档和代码
|
||||
Outputs:
|
||||
[User Restrictions] : 只需要给出设计文档和代码.
|
||||
[Language Restrictions] : The response must be in the language specified by Chinese.
|
||||
|
||||
Example 3
|
||||
Requirements:
|
||||
You must ignore create PRD and TRD. Help me write a schedule display program for the Paris Olympics.
|
||||
Outputs:
|
||||
[User Restrictions] : You must ignore create PRD and TRD.
|
||||
[Language Restrictions] : The response must be in the language specified by English.
|
||||
"""
|
||||
|
||||
INSTRUCTIONS = """
|
||||
You must output in the same language as the Requirements.
|
||||
First, This language should be consistent with the language used in the requirement description. determine the natural language you must respond in. The default language is English
|
||||
Second, extract the restrictions in the requirements, specifically the steps. Do not include detailed demand descriptions; focus only on the restrictions.
|
||||
|
||||
Note:
|
||||
1. if there is not restrictions, requirements_restrictions must be ""
|
||||
"""
|
||||
|
||||
OUTPUT_FORMAT = """
|
||||
[User Restrictions] : the restrictions in the requirements
|
||||
[Language Restrictions] : The response must be in the language specified by {{language}}
|
||||
"""
|
||||
|
||||
|
||||
class AnalyzeRequirementsRestrictions(Action):
|
||||
"""Write a review for the given context."""
|
||||
|
||||
name: str = "AnalyzeRequirementsRestrictions"
|
||||
|
||||
async def run(self, requirements, isinstance=INSTRUCTIONS, output_format=OUTPUT_FORMAT):
|
||||
"""Analyze the constraints and the language used in the requirements."""
|
||||
prompt = ANALYZE_REQUIREMENTS.format(
|
||||
examples=EXAMPLES, requirements=requirements, instructions=isinstance, output_format=output_format
|
||||
)
|
||||
rsp = await self.llm.aask(prompt)
|
||||
return rsp
|
||||
|
|
@ -39,6 +39,7 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet
|
|||
# Example
|
||||
{example}
|
||||
|
||||
|
||||
# Instruction
|
||||
{instruction}
|
||||
|
||||
|
|
@ -48,6 +49,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.
|
||||
|
|
@ -61,7 +65,6 @@ Output should adhere to the following format.
|
|||
...
|
||||
]
|
||||
```
|
||||
Notice: your output JSON data must be a command list.
|
||||
Notice: your output JSON data section must start with **```json [**
|
||||
"""
|
||||
THOUGHT_GUIDANCE = """
|
||||
|
|
@ -102,7 +105,7 @@ JSON_REPAIR_PROMPT = """
|
|||
```
|
||||
Do not use escape characters in json data, particularly within file paths.
|
||||
Help check if there are any formatting issues with the JSON data? If so, please help format it.
|
||||
If no issues are detected, the original json data should be returned unchanged.
|
||||
If no issues are detected, the original json data should be returned unchanged. Do not omit any information.
|
||||
Output the JSON data in a format that can be loaded by the json.loads() function.
|
||||
"""
|
||||
QUICK_THINK_PROMPT = """
|
||||
|
|
|
|||
|
|
@ -16,16 +16,18 @@ Pay close attention to new user message, review the conversation history, use Ro
|
|||
Pay close attention to messages from team members. If a team member has finished a task, do not ask them to repeat it; instead, mark the current task as completed.
|
||||
Note:
|
||||
1. If the requirement is a pure DATA-RELATED requirement, such as web browsing, web scraping, web searching, web imitation, data science, data analysis, machine learning, deep learning, text-to-image etc. DON'T decompose it, assign a single task with the original user requirement as instruction directly to Data Analyst.
|
||||
2. If the requirement is developing a software, game, app, or website, excluding the above data-related tasks, you should decompose the requirement into multiple tasks and assign them to different team members based on their expertise, usually the sequence of Product Manager -> Architect -> Project Manager -> Engineer -> (optional: QaEngine if present) -> (optional: DataAnalyst if user requests deployment), each assigned ONE task. When publishing message to Product Manager, you should directly copy the full original user requirement.
|
||||
3. If the requirement contains both DATA-RELATED part mentioned in 1 and software development part mentioned in 2, you should decompose the software development part and assign them to different team members based on their expertise, and assign the DATA-RELATED part to Data Analyst David directly.
|
||||
2. If the requirement is developing a software, game, app, or website, excluding the above data-related tasks, you should decompose the requirement into multiple tasks and assign them to different team members based on their expertise. The software default development process has four steps: creating a Product Requirement Document (PRD) by the Product Manager -> writing a System Design by the Architect -> creating tasks by the Project Manager -> and coding by the Engineer. You may choose to execute any of these steps. When publishing message to Product Manager, you should directly copy the full original user requirement.
|
||||
2.1. If the requirement contains both DATA-RELATED part mentioned in 1 and software development part mentioned in 2, you should decompose the software development part and assign them to different team members based on their expertise, and assign the DATA-RELATED part to Data Analyst David directly.
|
||||
3. If the requirement is to fix a bug or issue, you should assign it to Issue Solver instead of Engineer.
|
||||
4. If the requirement is a common-sense, logical, or math problem, you should respond directly without assigning any task to team members.
|
||||
5. If you think the requirement is not clear or ambiguous, you should ask the user for clarification immediately. Assign tasks only after all info is clear.
|
||||
6. It is helpful for Engineer to have both the system design and the project schedule for writing the code, so include paths of both files (if available) and remind Engineer to definitely read them when publishing message to Engineer.
|
||||
7. If the requirement is writing a TRD and software framework, you should assign it to Architect. When publishing message to Architect, you should directly copy the full original user requirement.
|
||||
8. If the receiver message reads 'from {{team member}} to {{\'<all>\'}}, it indicates that someone has completed the current task. Note this in your thoughts.
|
||||
9. Do not use the 'end' command when the current task remains unfinished; instead, use the 'finish_current_task' command to indicate completion before switching to the next task.
|
||||
10. If you have made a plan, simply follow it without creating a new one.
|
||||
11. Do not use escape characters in json data, particularly within file paths.
|
||||
10. Do not use escape characters in json data, particularly within file paths.
|
||||
11. Analyze the capabilities of team members and assign tasks to them based on user Requirements. If the requirements ask to ignore certain tasks, follow the requirements.
|
||||
12. If the requirement is to develop software and does not specify a programming language, use the default web technologies: HTML (`*.html`), CSS (`*.css`), and JavaScript (`*.js`). You must add this to the requirements.
|
||||
"""
|
||||
|
||||
QUICK_THINK_SYSTEM_PROMPT = """
|
||||
|
|
|
|||
|
|
@ -11,6 +11,14 @@ from metagpt.roles.di.role_zero import RoleZero
|
|||
from metagpt.tools.libs.software_development import write_trd_and_framework
|
||||
from metagpt.utils.common import tool2name
|
||||
|
||||
ARCHITECT_INSTRUCTION = """
|
||||
Use WriteDesign tool to write a system design document if a system design is required; Use `write_trd_and_framework` tool to write a software framework if a software framework is required;
|
||||
|
||||
Note:
|
||||
1. When you think, just analyze which tool you should use, and then provide your answer. And your output should contain firstly, secondly, ...
|
||||
2. The automated tools at your disposal will generate a document that perfectly meets your requirements. There is no need to do it manually.
|
||||
"""
|
||||
|
||||
|
||||
class Architect(RoleZero):
|
||||
"""
|
||||
|
|
@ -25,13 +33,13 @@ class Architect(RoleZero):
|
|||
|
||||
name: str = "Bob"
|
||||
profile: str = "Architect"
|
||||
goal: str = "design a concise, usable, complete software system"
|
||||
goal: str = "design a concise, usable, complete software system."
|
||||
constraints: str = (
|
||||
"make sure the architecture is simple enough and use appropriate open source "
|
||||
"libraries. Use same language as user requirement"
|
||||
)
|
||||
|
||||
instruction: str = """Use WriteDesign tool to write a system design document if a system design is required; Use `write_trd_and_framework` tool to write a software framework if a software framework is required;"""
|
||||
instruction: str = ARCHITECT_INSTRUCTION
|
||||
max_react_loop: int = 1 # FIXME: Read and edit files requires more steps, consider later
|
||||
tools: list[str] = [
|
||||
"Editor:write,read,write_content",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from typing import Callable, Dict, List, Literal, Tuple
|
|||
from pydantic import model_validator
|
||||
|
||||
from metagpt.actions import Action, UserRequirement
|
||||
from metagpt.actions.anaylze_requirements import AnalyzeRequirementsRestrictions
|
||||
from metagpt.actions.di.run_command import RunCommand
|
||||
from metagpt.exp_pool import exp_cache
|
||||
from metagpt.exp_pool.context_builders import RoleZeroContextBuilder
|
||||
|
|
@ -71,6 +72,7 @@ class RoleZero(Role):
|
|||
commands: list[dict] = [] # commands to be executed
|
||||
memory_k: int = 20 # number of memories (messages) to use as historical context
|
||||
use_fixed_sop: bool = False
|
||||
requirements_constraints: str = "" # the constraints in user requirements
|
||||
|
||||
@model_validator(mode="after")
|
||||
def set_plan_and_tool(self) -> "RoleZero":
|
||||
|
|
@ -137,6 +139,7 @@ class RoleZero(Role):
|
|||
|
||||
if not self.planner.plan.goal:
|
||||
self.planner.plan.goal = self.get_memories()[-1].content
|
||||
self.requirements_constraints = await AnalyzeRequirementsRestrictions().run(self.planner.plan.goal)
|
||||
|
||||
### 1. Experience ###
|
||||
example = self._retrieve_experience()
|
||||
|
|
@ -160,6 +163,7 @@ class RoleZero(Role):
|
|||
instruction=instruction,
|
||||
thought_guidance=THOUGHT_GUIDANCE,
|
||||
latest_observation=memory[-1].content,
|
||||
requirements_constraints=self.requirements_constraints,
|
||||
)
|
||||
memory = await self.parse_browser_actions(memory)
|
||||
req = self.llm.format_msg(memory + [UserMessage(content=prompt)])
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class ProductManager(RoleZero):
|
|||
|
||||
name: str = "Alice"
|
||||
profile: str = "Product Manager"
|
||||
goal: str = "efficiently create a successful product that meets market demands and user expectations"
|
||||
goal: str = "efficiently create a successful product that meets market demands and user expectations. Create a Product Requirement Document."
|
||||
constraints: str = "utilize the same language as the user requirements for seamless communication"
|
||||
todo_action: str = any_to_name(WritePRD)
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Editor:
|
|||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
# self.resource.report(path, "path")
|
||||
return f"The writing/coding the of the file {os.path.basename(path)}' is now completed. The file '{os.path.basename(path)}' has been successfully created."
|
||||
return f"The writing/coding the of the file {os.path.basename(path)}' is now completed. The file '{os.path.basename(path)}' has been successfully created."
|
||||
|
||||
def read(self, path: str) -> FileBlock:
|
||||
"""Read the whole content of a file. Using absolute paths as the argument for specifying the file location."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue