mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-14 15:25:17 +02:00
update prompt
This commit is contained in:
parent
db22ed214f
commit
6743a4f3b1
10 changed files with 381 additions and 36 deletions
|
|
@ -16,7 +16,7 @@ from typing import Optional
|
|||
from pydantic import Field
|
||||
|
||||
from metagpt.actions import Action, ActionOutput
|
||||
from metagpt.actions.design_api_an import DESIGN_API_NODE
|
||||
from metagpt.actions.design_api_an import DESIGN_API_NODE, REFINE_DESIGN_NODES
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.const import (
|
||||
DATA_API_DESIGN_FILE_REPO,
|
||||
|
|
@ -87,7 +87,7 @@ class WriteDesign(Action):
|
|||
|
||||
async def _merge(self, prd_doc, system_design_doc, schema=CONFIG.prompt_schema):
|
||||
context = NEW_REQ_TEMPLATE.format(old_design=system_design_doc.content, context=prd_doc.content)
|
||||
node = await DESIGN_API_NODE.fill(context=context, llm=self.llm, schema=schema)
|
||||
node = await REFINE_DESIGN_NODES.fill(context=context, llm=self.llm, schema=schema)
|
||||
system_design_doc.content = node.instruct_content.json(ensure_ascii=False)
|
||||
return system_design_doc
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from typing import List
|
|||
|
||||
from metagpt.actions.action_node import ActionNode
|
||||
from metagpt.logs import logger
|
||||
from metagpt.utils.mermaid import MMC1, MMC2
|
||||
from metagpt.utils.mermaid import MMC1, MMC1_INC_AND_REFINE, MMC2
|
||||
|
||||
IMPLEMENTATION_APPROACH = ActionNode(
|
||||
key="Implementation approach",
|
||||
|
|
@ -18,6 +18,24 @@ IMPLEMENTATION_APPROACH = ActionNode(
|
|||
example="We will ...",
|
||||
)
|
||||
|
||||
INC_IMPLEMENTATION_APPROACH = ActionNode(
|
||||
key="Incremental Implementation approach",
|
||||
expected_type=str,
|
||||
instruction="Analyze the challenging aspects of the requirements and select a suitable open-source framework. "
|
||||
"Outline the incremental steps involved in the implementation process with a list of detailed strategies.",
|
||||
example="we will ...",
|
||||
)
|
||||
|
||||
REFINE_IMPLEMENTATION_APPROACH = ActionNode(
|
||||
key="Implementation Approach",
|
||||
expected_type=str,
|
||||
instruction="Update and extend the original implementation approach to reflect the evolving challenges and requirements "
|
||||
"due to incremental development. Provide detailed strategies for incremental steps in the implementation process."
|
||||
"etain any content unrelated to incremental development for coherence and clarity.",
|
||||
example="We will refine ...",
|
||||
)
|
||||
|
||||
|
||||
PROJECT_NAME = ActionNode(
|
||||
key="Project name", expected_type=str, instruction="The project name with underline", example="game_2048"
|
||||
)
|
||||
|
|
@ -29,6 +47,14 @@ FILE_LIST = ActionNode(
|
|||
example=["main.py", "game.py"],
|
||||
)
|
||||
|
||||
REFINE_FILE_LIST = ActionNode(
|
||||
key="File List",
|
||||
expected_type=List[str],
|
||||
instruction="Update and expand the original file list, including only relative paths. "
|
||||
"Ensure that the refined file list reflects the evolving structure of the project due to incremental development.",
|
||||
example=["main.py", "game.py", "utils.py", "new_feature.py"],
|
||||
)
|
||||
|
||||
DATA_STRUCTURES_AND_INTERFACES = ActionNode(
|
||||
key="Data structures and interfaces",
|
||||
expected_type=str,
|
||||
|
|
@ -38,6 +64,27 @@ DATA_STRUCTURES_AND_INTERFACES = ActionNode(
|
|||
example=MMC1,
|
||||
)
|
||||
|
||||
INC_DATA_STRUCTURES_AND_INTERFACES = ActionNode(
|
||||
key="Incremental Data structures and interfaces",
|
||||
expected_type=str,
|
||||
instruction="Extend the existing mermaid classDiagram code syntax to incorporate new classes, "
|
||||
"methods (including __init__), and functions with precise type annotations. Clearly delineate additional "
|
||||
"relationships between classes, maintaining adherence to PEP8 standards. Enhance the level of detail in data "
|
||||
"structures, ensuring a comprehensive API design that seamlessly integrates with the existing structure.",
|
||||
example=MMC1_INC_AND_REFINE,
|
||||
)
|
||||
|
||||
REFINE_DATA_STRUCTURES_AND_INTERFACES = ActionNode(
|
||||
key="Data Structures and Interfaces",
|
||||
expected_type=str,
|
||||
instruction="Update and extend the existing mermaid classDiagram code syntax to incorporate new classes, "
|
||||
"methods (including __init__), and functions with precise type annotations. Delineate additional "
|
||||
"relationships between classes, ensuring clarity and adherence to PEP8 standards. Further enhance the "
|
||||
"detail in data structures for a comprehensive API design that seamlessly integrates with the evolving structure."
|
||||
"Retain any content unrelated to incremental development for coherence and clarity.",
|
||||
example=MMC1_INC_AND_REFINE,
|
||||
)
|
||||
|
||||
PROGRAM_CALL_FLOW = ActionNode(
|
||||
key="Program call flow",
|
||||
expected_type=str,
|
||||
|
|
@ -53,6 +100,31 @@ ANYTHING_UNCLEAR = ActionNode(
|
|||
example="Clarification needed on third-party API integration, ...",
|
||||
)
|
||||
|
||||
INC_DESIGN_CONTEXT = """
|
||||
### Legacy Content
|
||||
{old_design}
|
||||
|
||||
### New Requirements
|
||||
{requirements}
|
||||
|
||||
### PRD Increment Content
|
||||
{prd_increment}
|
||||
"""
|
||||
|
||||
REFINE_DESIGN_CONTEXT = """
|
||||
Role: You are a professional Architect tasked with overseeing incremental development.
|
||||
Based on new requirements, review and refine the system design. Integrate existing architecture with incremental design changes, ensuring the refined design encompasses all architectural elements, enhancements, and adjustments. Retain content unrelated to incremental development needs for coherence and clarity.
|
||||
|
||||
### New Requirements
|
||||
{requirements}
|
||||
|
||||
### Legacy Content
|
||||
{old_design}
|
||||
|
||||
### Design Increment Content
|
||||
{design_increment}
|
||||
"""
|
||||
|
||||
NODES = [
|
||||
IMPLEMENTATION_APPROACH,
|
||||
# PROJECT_NAME,
|
||||
|
|
@ -62,11 +134,24 @@ NODES = [
|
|||
ANYTHING_UNCLEAR,
|
||||
]
|
||||
|
||||
INC_NODES = [INC_IMPLEMENTATION_APPROACH, INC_DATA_STRUCTURES_AND_INTERFACES]
|
||||
|
||||
REFINE_NODES = [
|
||||
REFINE_IMPLEMENTATION_APPROACH,
|
||||
# PROJECT_NAME,
|
||||
REFINE_FILE_LIST,
|
||||
REFINE_DATA_STRUCTURES_AND_INTERFACES,
|
||||
PROGRAM_CALL_FLOW,
|
||||
ANYTHING_UNCLEAR,
|
||||
]
|
||||
|
||||
DESIGN_API_NODE = ActionNode.from_children("DesignAPI", NODES)
|
||||
INC_DESIGN_NODES = ActionNode.from_children("Incremental Design API", INC_NODES)
|
||||
REFINE_DESIGN_NODES = ActionNode.from_children("Refine Design API", REFINE_NODES)
|
||||
|
||||
|
||||
def main():
|
||||
prompt = DESIGN_API_NODE.compile(context="")
|
||||
prompt = REFINE_DESIGN_NODES.compile(context="12313")
|
||||
logger.info(prompt)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ from pydantic import Field
|
|||
|
||||
from metagpt.actions import ActionOutput
|
||||
from metagpt.actions.action import Action
|
||||
from metagpt.actions.project_management_an import PM_NODE
|
||||
from metagpt.actions.project_management_an import PM_NODE, REFINE_PM_NODES
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.const import (
|
||||
PACKAGE_REQUIREMENTS_FILENAME,
|
||||
|
|
@ -101,7 +101,7 @@ class WriteTasks(Action):
|
|||
|
||||
async def _merge(self, system_design_doc, task_doc, schema=CONFIG.prompt_schema) -> Document:
|
||||
context = NEW_REQ_TEMPLATE.format(context=system_design_doc.content, old_tasks=task_doc.content)
|
||||
node = await PM_NODE.fill(context, self.llm, schema)
|
||||
node = await REFINE_PM_NODES.fill(context, self.llm, schema)
|
||||
task_doc.content = node.instruct_content.json(ensure_ascii=False)
|
||||
return task_doc
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,31 @@ LOGIC_ANALYSIS = ActionNode(
|
|||
],
|
||||
)
|
||||
|
||||
INC_LOGIC_ANALYSIS = ActionNode(
|
||||
key="Increment Logic Analysis",
|
||||
expected_type=List[List[str]],
|
||||
instruction="Provide a list of files with the classes/methods/functions to be implemented or modified incrementally. Include thorough dependency analysis, consider potential impacts on existing code, and document necessary imports.",
|
||||
example=[
|
||||
["new_feature.py", "Introduces NewFeature class and related functions"],
|
||||
["utils.py", "Modifies existing utility functions to support incremental changes"],
|
||||
],
|
||||
)
|
||||
|
||||
REFINE_LOGIC_ANALYSIS = ActionNode(
|
||||
key="Logic Analysis",
|
||||
expected_type=List[List[str]],
|
||||
instruction="Review and refine the logic analysis by merging the Legacy Content and Incremental Content. "
|
||||
"Provide a comprehensive list of files with classes/methods/functions to be implemented or modified incrementally. "
|
||||
"Include thorough dependency analysis, consider potential impacts on existing code, and document necessary imports."
|
||||
"Retain any content unrelated to incremental development for coherence and clarity.",
|
||||
example=[
|
||||
["game.py", "Contains Game class and ... functions"],
|
||||
["main.py", "Contains main function, from game import Game"],
|
||||
["new_feature.py", "Introduces NewFeature class and related functions"],
|
||||
["utils.py", "Modifies existing utility functions to support incremental changes"],
|
||||
],
|
||||
)
|
||||
|
||||
TASK_LIST = ActionNode(
|
||||
key="Task list",
|
||||
expected_type=List[str],
|
||||
|
|
@ -42,6 +67,23 @@ TASK_LIST = ActionNode(
|
|||
example=["game.py", "main.py"],
|
||||
)
|
||||
|
||||
INC_TASK_LIST = ActionNode(
|
||||
key="Incremental Task list",
|
||||
expected_type=List[str],
|
||||
instruction="Break down the incremental development tasks into a prioritized list of filenames. "
|
||||
"Organize the tasks based on dependency order, ensuring a systematic and efficient implementation.",
|
||||
example=["new_feature.py", "utils.py", "main.py"],
|
||||
)
|
||||
|
||||
REFINE_TASK_LIST = ActionNode(
|
||||
key="Task list",
|
||||
expected_type=List[str],
|
||||
instruction="Review and refine the combined task list after the merger of Legacy Content and Incremental Content. "
|
||||
"Ensure that tasks are organized in a logical and prioritized order, considering dependencies for a streamlined and"
|
||||
" efficient development process.",
|
||||
example=["game.py", "utils.py", "new_feature.py", "main.py"],
|
||||
)
|
||||
|
||||
FULL_API_SPEC = ActionNode(
|
||||
key="Full API spec",
|
||||
expected_type=str,
|
||||
|
|
@ -54,9 +96,27 @@ SHARED_KNOWLEDGE = ActionNode(
|
|||
key="Shared Knowledge",
|
||||
expected_type=str,
|
||||
instruction="Detail any shared knowledge, like common utility functions or configuration variables.",
|
||||
example="'game.py' contains functions shared across the project.",
|
||||
example="`game.py` contains functions shared across the project.",
|
||||
)
|
||||
|
||||
INC_SHARED_KNOWLEDGE = ActionNode(
|
||||
key="Increment Shared Knowledge",
|
||||
expected_type=str,
|
||||
instruction="Document any new shared knowledge generated during incremental development. This includes common "
|
||||
"utility functions, configuration variables, or any information vital for team collaboration.",
|
||||
example="`new_module.py` introduces shared utility functions for improved code reusability.",
|
||||
)
|
||||
|
||||
REFINE_SHARED_KNOWLEDGE = ActionNode(
|
||||
key="Shared Knowledge",
|
||||
expected_type=str,
|
||||
instruction="Update and expand shared knowledge to reflect any new elements introduced during incremental development. "
|
||||
"This includes common utility functions, configuration variables, or any information vital for team collaboration."
|
||||
"Retain any content unrelated to incremental development for coherence and clarity.",
|
||||
example="`new_module.py` enhances shared utility functions for improved code reusability and collaboration.",
|
||||
)
|
||||
|
||||
|
||||
ANYTHING_UNCLEAR_PM = ActionNode(
|
||||
key="Anything UNCLEAR",
|
||||
expected_type=str,
|
||||
|
|
@ -64,6 +124,31 @@ ANYTHING_UNCLEAR_PM = ActionNode(
|
|||
example="Clarification needed on how to start and initialize third-party libraries.",
|
||||
)
|
||||
|
||||
INC_PM_CONTEXT = """
|
||||
### Legacy Content
|
||||
{old_tasks}
|
||||
|
||||
### New Requirements
|
||||
{requirements}
|
||||
|
||||
### Design Increment Content
|
||||
{design_increment}
|
||||
"""
|
||||
|
||||
REFINE_PM_CONTEXT = """
|
||||
Role: You are a professional Project Manager tasked with overseeing incremental development.
|
||||
Based on New Requirements, refine the project context to account for incremental development. Ensure the context offers a comprehensive overview of the project's evolving scope, covering both legacy content and incremental content. Retain any content unrelated to incremental development.
|
||||
|
||||
### New Requirements
|
||||
{requirements}
|
||||
|
||||
### Legacy Content
|
||||
{old_tasks}
|
||||
|
||||
### Increment Content
|
||||
{tasks_increment}
|
||||
"""
|
||||
|
||||
NODES = [
|
||||
REQUIRED_PYTHON_PACKAGES,
|
||||
REQUIRED_OTHER_LANGUAGE_PACKAGES,
|
||||
|
|
@ -74,8 +159,21 @@ NODES = [
|
|||
ANYTHING_UNCLEAR_PM,
|
||||
]
|
||||
|
||||
INC_NODES = [INC_LOGIC_ANALYSIS, INC_TASK_LIST, INC_SHARED_KNOWLEDGE]
|
||||
|
||||
REFINE_NODES = [
|
||||
REQUIRED_PYTHON_PACKAGES,
|
||||
REQUIRED_OTHER_LANGUAGE_PACKAGES,
|
||||
REFINE_LOGIC_ANALYSIS,
|
||||
REFINE_TASK_LIST,
|
||||
FULL_API_SPEC,
|
||||
REFINE_SHARED_KNOWLEDGE,
|
||||
ANYTHING_UNCLEAR_PM,
|
||||
]
|
||||
|
||||
PM_NODE = ActionNode.from_children("PM_NODE", NODES)
|
||||
INC_PM_NODES = ActionNode.from_children("Incremental_PM_NODES", INC_NODES)
|
||||
REFINE_PM_NODES = ActionNode.from_children("Refine_PM_NODES", REFINE_NODES)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from metagpt.const import (
|
|||
BUGFIX_FILENAME,
|
||||
CODE_SUMMARIES_FILE_REPO,
|
||||
DOCS_FILE_REPO,
|
||||
REQUIREMENT_FILENAME,
|
||||
TASK_FILE_REPO,
|
||||
TEST_OUTPUTS_FILE_REPO,
|
||||
)
|
||||
|
|
@ -115,6 +116,8 @@ class WriteCode(Action):
|
|||
test_detail = RunCodeResult.loads(test_doc.content)
|
||||
logs = test_detail.stderr
|
||||
|
||||
docs_file_repo = CONFIG.git_repo.new_file_repository(relative_path=DOCS_FILE_REPO)
|
||||
requirement_doc = await docs_file_repo.get(filename=REQUIREMENT_FILENAME)
|
||||
guideline = kwargs.get("guideline", "")
|
||||
if bug_feedback:
|
||||
code_context = coding_context.code_doc.content
|
||||
|
|
@ -125,6 +128,7 @@ class WriteCode(Action):
|
|||
|
||||
if guideline:
|
||||
prompt = WRITE_CODE_INCREMENT_TEMPLATE.format(
|
||||
requirement=requirement_doc.content if requirement_doc else "",
|
||||
guideline=guideline,
|
||||
design=coding_context.design_doc.content if coding_context.design_doc else "",
|
||||
tasks=coding_context.task_doc.content if coding_context.task_doc else "",
|
||||
|
|
@ -175,7 +179,7 @@ class WriteCode(Action):
|
|||
doc = await old_file_repo.get(filename=filename) # 使用原始代码
|
||||
else:
|
||||
continue
|
||||
codes.append(f"----- Legacy {filename}\n```{doc.content}```")
|
||||
codes.insert(0, f"-----Now, {filename} need to be rewritten\n```{doc.content}```\n=====")
|
||||
|
||||
else:
|
||||
doc = await src_file_repo.get(filename=filename) # 使用先前生成的代码
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ GUIDELINE = ActionNode(
|
|||
INCREMENTAL_CHANGE = ActionNode(
|
||||
key="Incremental Change",
|
||||
expected_type=str,
|
||||
instruction="Write Incremental Change by making a code draft that how to implement incremental development based on the context and Code Guideline.",
|
||||
example="""1. Extend `Calculator` class in `calculator.py` with new methods for subtraction, multiplication, and division.
|
||||
instruction="Write Incremental Change by making a code draft that how to implement incremental development including detailed steps based on the context.",
|
||||
example="""- calculator.py: Enhance the functionality of `calculator.py` by extending it to incorporate methods for subtraction, multiplication, and division. Implement robust error handling for the division operation to mitigate potential issues related to division by zero.
|
||||
```python
|
||||
## calculator.py
|
||||
class Calculator:
|
||||
|
|
@ -43,7 +43,8 @@ class Calculator:
|
|||
raise ValueError('Cannot divide by zero')
|
||||
return num1 / num2
|
||||
```
|
||||
2. Implement new endpoints in `main.py` for the subtraction, multiplication, and division methods.
|
||||
|
||||
- main.py: Integrate new API endpoints for subtraction, multiplication, and division into the existing codebase of `main.py`. Ensure seamless integration with the overall application architecture and maintain consistency with coding standards.
|
||||
```python
|
||||
## main.py
|
||||
from flask import Flask, request, jsonify
|
||||
|
|
@ -95,9 +96,6 @@ Role: You are a professional software engineer, and your main task is to craft c
|
|||
### Requirement
|
||||
{requirement}
|
||||
|
||||
### Prd
|
||||
{prd}
|
||||
|
||||
### Design
|
||||
{design}
|
||||
|
||||
|
|
@ -110,12 +108,13 @@ Role: You are a professional software engineer, and your main task is to craft c
|
|||
|
||||
WRITE_CODE_INCREMENT_TEMPLATE = """
|
||||
NOTICE
|
||||
Role: You are a professional engineer; The main goal is to complete incremental development by combining Legacy Code and Guideline to rewrite the complete code.
|
||||
Language: Please use the same language as the user requirement, but the title and code should be still in English. For example, if the user speaks Chinese, the specific text of your answer should also be in Chinese.
|
||||
ATTENTION: Use '##' to SPLIT SECTIONS, not '#'. Output format carefully referenced "Format example".
|
||||
Role: You are a professional engineer; The main goal is to complete incremental development by combining legacy code and Incremental Change, ensuring the integration of new features.
|
||||
|
||||
# Context
|
||||
## Guideline
|
||||
## New Requirement
|
||||
{requirement}
|
||||
|
||||
## Incremental Change
|
||||
{guideline}
|
||||
|
||||
## Design
|
||||
|
|
@ -148,18 +147,17 @@ ATTENTION: Use '##' to SPLIT SECTIONS, not '#'. Output format carefully referenc
|
|||
...
|
||||
```
|
||||
|
||||
# Instruction: Based on the context, follow "Format example", write code.
|
||||
|
||||
## Rewrite Complete Code: Only Write one file {filename}, Write code using triple quotes, based on the following attentions and context.
|
||||
# Instruction: Based on the context, follow "Format example", write or rewrite code.
|
||||
## Write/Rewrite Code: Only write one file {filename}, write or rewrite complete code using triple quotes based on the following attentions and context.
|
||||
### Important Attention: If Legacy Code files contain "{filename} to be rewritten", you are required to merge the Incremental Change into the {filename} file and retain any content unrelated to incremental development to maintain clarity and coherence, when rewriting "{filename} to be rewritten".
|
||||
1. Only One file: do your best to implement THIS ONLY ONE FILE.
|
||||
2. COMPLETE CODE: Your code will be part of the entire project, so please implement complete, reliable, reusable code snippets.
|
||||
3. Set default value: If there is any setting, ALWAYS SET A DEFAULT VALUE, ALWAYS USE STRONG TYPE AND EXPLICIT VARIABLE. AVOID circular import.
|
||||
4. Follow design: YOU MUST FOLLOW "Data structures and interfaces". DONT CHANGE ANY DESIGN. Do not use public member functions that do not exist in your design.
|
||||
5. Follow Guideline: If Legacy Code files contain {filename}, you are required to follow the Guideline to merge the Incremental Change into the Legacy {filename} file when rewriting {filename} file.
|
||||
5. Merge Incremental Change: If there is any Incremental Change, you must merge it into the code file.
|
||||
6. CAREFULLY CHECK THAT YOU DONT MISS ANY NECESSARY CLASS/FUNCTION IN THIS FILE.
|
||||
7. Before using a external variable/module, make sure you import it first.
|
||||
8. Write out EVERY CODE DETAIL, DON'T LEAVE TODO.
|
||||
9. Attention: Implement the functionality required within the current file's scope, reusing existing code whenever possible. For instance, main.py achieves its purpose by instantiating an already implemented class, rather than manually implementing a class in main.py.
|
||||
"""
|
||||
|
||||
CODE_GUIDE_CONTEXT_EXAMPLE = """
|
||||
|
|
@ -194,7 +192,7 @@ class Calculator:
|
|||
return num1 + num2
|
||||
"""
|
||||
|
||||
GUIDE_NODES = [GUIDELINE, INCREMENTAL_CHANGE]
|
||||
GUIDE_NODES = [INCREMENTAL_CHANGE]
|
||||
|
||||
WRITE_CODE_GUIDE_NODE = ActionNode.from_children("WriteCodeGuide", GUIDE_NODES)
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ from metagpt.actions import Action, ActionOutput
|
|||
from metagpt.actions.action_node import ActionNode
|
||||
from metagpt.actions.fix_bug import FixBug
|
||||
from metagpt.actions.write_prd_an import (
|
||||
REFINE_PRD_NODE,
|
||||
REFINE_PRD_SIMPLE_CONTEXT,
|
||||
WP_IS_RELATIVE_NODE,
|
||||
WP_ISSUE_TYPE_NODE,
|
||||
WRITE_PRD_NODE,
|
||||
|
|
@ -135,8 +137,14 @@ class WritePRD(Action):
|
|||
async def _merge(self, new_requirement_doc, prd_doc, schema=CONFIG.prompt_schema) -> Document:
|
||||
if not CONFIG.project_name:
|
||||
CONFIG.project_name = Path(CONFIG.project_path).name
|
||||
prompt = NEW_REQ_TEMPLATE.format(requirements=new_requirement_doc.content, old_prd=prd_doc.content)
|
||||
node = await WRITE_PRD_NODE.fill(context=prompt, llm=self.llm, schema=schema)
|
||||
|
||||
project_name = CONFIG.project_name if CONFIG.project_name else ""
|
||||
prompt = REFINE_PRD_SIMPLE_CONTEXT.format(
|
||||
requirements=new_requirement_doc.content,
|
||||
old_prd=prd_doc.content,
|
||||
project_name=project_name,
|
||||
)
|
||||
node = await REFINE_PRD_NODE.fill(context=prompt, llm=self.llm, schema=schema)
|
||||
prd_doc.content = node.instruct_content.json(ensure_ascii=False)
|
||||
await self._rename_workspace(node)
|
||||
return prd_doc
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@ ORIGINAL_REQUIREMENTS = ActionNode(
|
|||
example="Create a 2048 game",
|
||||
)
|
||||
|
||||
REFINE_REQUIREMENTS = ActionNode(
|
||||
key="Original Requirements",
|
||||
expected_type=str,
|
||||
instruction="Update and expand the original user's requirements to reflect the evolving needs of the project."
|
||||
"Retain any content unrelated to incremental development",
|
||||
example="Create a 2048 game with a new feature that ...",
|
||||
)
|
||||
|
||||
PROJECT_NAME = ActionNode(
|
||||
key="Project Name",
|
||||
expected_type=str,
|
||||
|
|
@ -38,6 +46,13 @@ PROJECT_NAME = ActionNode(
|
|||
example="game_2048",
|
||||
)
|
||||
|
||||
REFINE_PROJECT_NAME = ActionNode(
|
||||
key="Project Name",
|
||||
expected_type=str,
|
||||
instruction="Update the project name based on the context.",
|
||||
example="game_2048_new",
|
||||
)
|
||||
|
||||
PRODUCT_GOALS = ActionNode(
|
||||
key="Product Goals",
|
||||
expected_type=List[str],
|
||||
|
|
@ -45,6 +60,19 @@ PRODUCT_GOALS = ActionNode(
|
|||
example=["Create an engaging user experience", "Improve accessibility, be responsive", "More beautiful UI"],
|
||||
)
|
||||
|
||||
REFINE_PRODUCT_GOALS = ActionNode(
|
||||
key="Product Goals",
|
||||
expected_type=List[str],
|
||||
instruction="Update and expand the original product goals to reflect the evolving needs due to incremental "
|
||||
"development.Ensure that the refined goals align with the current project direction and contribute to its success."
|
||||
"Retain any content unrelated to incremental development",
|
||||
example=[
|
||||
"Enhance user engagement through new features",
|
||||
"Optimize performance for scalability",
|
||||
"Integrate innovative UI enhancements",
|
||||
],
|
||||
)
|
||||
|
||||
USER_STORIES = ActionNode(
|
||||
key="User Stories",
|
||||
expected_type=List[str],
|
||||
|
|
@ -58,6 +86,21 @@ USER_STORIES = ActionNode(
|
|||
],
|
||||
)
|
||||
|
||||
REFINE_USER_STORIES = ActionNode(
|
||||
key="User Stories",
|
||||
expected_type=List[str],
|
||||
instruction="Update and expand the original scenario-based user stories to reflect the evolving needs due to "
|
||||
"incremental development, no less than 7. Ensure that the refined user stories capture incremental features and "
|
||||
"improvements. Retain any content unrelated to incremental development",
|
||||
example=[
|
||||
"As a player, I want to choose difficulty levels to challenge my skills",
|
||||
"As a player, I want a visually appealing score display after each game for a better gaming experience",
|
||||
"As a player, I want a convenient restart button displayed when I lose to quickly start a new game",
|
||||
"As a player, I want an enhanced and aesthetically pleasing UI to elevate the overall gaming experience",
|
||||
"As a player, I want the ability to play the game seamlessly on my mobile phone for on-the-go entertainment",
|
||||
],
|
||||
)
|
||||
|
||||
COMPETITIVE_ANALYSIS = ActionNode(
|
||||
key="Competitive Analysis",
|
||||
expected_type=List[str],
|
||||
|
|
@ -104,6 +147,14 @@ REQUIREMENT_POOL = ActionNode(
|
|||
example=[["P0", "The main code ..."], ["P0", "The game algorithm ..."]],
|
||||
)
|
||||
|
||||
REFINE_REQUIREMENT_POOL = ActionNode(
|
||||
key="Requirement Pool",
|
||||
expected_type=List[List[str]],
|
||||
instruction="List no less than 7 requirements with their priority (P0, P1, P2). "
|
||||
"Cover both legacy content and incremental content. Retain any content unrelated to incremental development",
|
||||
example=[["P0", "The main code ..."], ["P0", "The game algorithm ..."]],
|
||||
)
|
||||
|
||||
UI_DESIGN_DRAFT = ActionNode(
|
||||
key="UI Design draft",
|
||||
expected_type=str,
|
||||
|
|
@ -121,8 +172,10 @@ ANYTHING_UNCLEAR = ActionNode(
|
|||
ISSUE_TYPE = ActionNode(
|
||||
key="issue_type",
|
||||
expected_type=str,
|
||||
instruction="Answer BUG/REQUIREMENT. If it is a bugfix, answer BUG, otherwise answer Requirement",
|
||||
example="BUG",
|
||||
instruction="Answer BUG/REFINE/OVERHAUL. If it is a bugfix, answer BUG;"
|
||||
"if it is a minor improvement, answer REFINE;"
|
||||
"if it is a major overhaul, answer OVERHAUL that most likely not answer in most cases.",
|
||||
example="REFINE",
|
||||
)
|
||||
|
||||
IS_RELATIVE = ActionNode(
|
||||
|
|
@ -137,6 +190,50 @@ REASON = ActionNode(
|
|||
)
|
||||
|
||||
|
||||
REFINE_PRD_CONTEXT = """
|
||||
Role: You are a professional Product Manager tasked with overseeing incremental development.
|
||||
Based on New Requirements, output a New PRD that seamlessly integrates both the Legacy Content and the Incremental Content. Ensure the resulting document captures the complete scope of features, enhancements, and retain content unrelated to incremental development needs for coherence and clarity.
|
||||
|
||||
### New Project Name
|
||||
{project_name}
|
||||
|
||||
### New Requirements
|
||||
{requirements}
|
||||
|
||||
### Legacy Content
|
||||
{old_prd}
|
||||
|
||||
### PRD Incremental Content
|
||||
{prd_increment}
|
||||
|
||||
### Search Information
|
||||
-
|
||||
"""
|
||||
|
||||
REFINE_PRD_SIMPLE_CONTEXT = """
|
||||
You are a professional Product Manager tasked with overseeing incremental development.
|
||||
|
||||
### New Project Name
|
||||
{project_name}
|
||||
|
||||
### New Requirements
|
||||
{requirements}
|
||||
|
||||
### Legacy Content
|
||||
{old_prd}
|
||||
|
||||
### Search Information
|
||||
-
|
||||
"""
|
||||
|
||||
INCREMENTAL_DEVELOPMENT_ANALYSIS = ActionNode(
|
||||
key="Requirement Analysis",
|
||||
expected_type=List[str],
|
||||
instruction="Propose the comprehensive incremental development requirement analysis on new features and enhanced features for New Requirements.",
|
||||
example=["Require add/update/modify ..."],
|
||||
)
|
||||
|
||||
|
||||
NODES = [
|
||||
LANGUAGE,
|
||||
PROGRAMMING_LANGUAGE,
|
||||
|
|
@ -152,13 +249,33 @@ NODES = [
|
|||
ANYTHING_UNCLEAR,
|
||||
]
|
||||
|
||||
REFINE_NODES = [
|
||||
LANGUAGE,
|
||||
PROGRAMMING_LANGUAGE,
|
||||
REFINE_REQUIREMENTS,
|
||||
REFINE_PROJECT_NAME,
|
||||
REFINE_PRODUCT_GOALS,
|
||||
REFINE_USER_STORIES,
|
||||
COMPETITIVE_ANALYSIS,
|
||||
COMPETITIVE_QUADRANT_CHART,
|
||||
INCREMENTAL_DEVELOPMENT_ANALYSIS,
|
||||
REFINE_REQUIREMENT_POOL,
|
||||
UI_DESIGN_DRAFT,
|
||||
ANYTHING_UNCLEAR,
|
||||
]
|
||||
|
||||
INCREMENT_PRD_NODES = [INCREMENTAL_DEVELOPMENT_ANALYSIS, REQUIREMENT_POOL]
|
||||
|
||||
WRITE_PRD_NODE = ActionNode.from_children("WritePRD", NODES)
|
||||
REFINE_PRD_NODE = ActionNode.from_children("RefinePRD", REFINE_NODES)
|
||||
INCREMENT_NODE = ActionNode.from_children("IncrementPRD", INCREMENT_PRD_NODES)
|
||||
WP_ISSUE_TYPE_NODE = ActionNode.from_children("WP_ISSUE_TYPE", [ISSUE_TYPE, REASON])
|
||||
WP_IS_RELATIVE_NODE = ActionNode.from_children("WP_IS_RELATIVE", [IS_RELATIVE, REASON])
|
||||
|
||||
|
||||
def main():
|
||||
prompt = WRITE_PRD_NODE.compile(context="")
|
||||
# prompt = WRITE_PRD_NODE.compile(context="")
|
||||
prompt = INCREMENT_NODE.compile(context=REFINE_PRD_CONTEXT)
|
||||
logger.info(prompt)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ from metagpt.config import CONFIG
|
|||
from metagpt.const import (
|
||||
CODE_SUMMARIES_FILE_REPO,
|
||||
CODE_SUMMARIES_PDF_FILE_REPO,
|
||||
PRDS_FILE_REPO,
|
||||
SYSTEM_DESIGN_FILE_REPO,
|
||||
TASK_FILE_REPO,
|
||||
)
|
||||
|
|
@ -313,20 +312,18 @@ class Engineer(Role):
|
|||
logger.info("Writing code guideline..")
|
||||
|
||||
requirement = str(self._rc.memory.get_by_role("Human")[0])
|
||||
prd_file_repo = CONFIG.git_repo.new_file_repository(PRDS_FILE_REPO)
|
||||
# prd_file_repo = CONFIG.git_repo.new_file_repository(PRDS_FILE_REPO)
|
||||
design_file_repo = CONFIG.git_repo.new_file_repository(SYSTEM_DESIGN_FILE_REPO)
|
||||
task_file_repo = CONFIG.git_repo.new_file_repository(TASK_FILE_REPO)
|
||||
prd = await prd_file_repo.get_all()
|
||||
prd = "\n".join([doc.content for doc in prd])
|
||||
# prd = await prd_file_repo.get_all()
|
||||
# prd = "\n".join([doc.content for doc in prd])
|
||||
design = await design_file_repo.get_all()
|
||||
design = "\n".join([doc.content for doc in design])
|
||||
tasks = await task_file_repo.get_all()
|
||||
tasks = "\n".join([doc.content for doc in tasks])
|
||||
old_codes = await self.get_old_codes()
|
||||
|
||||
context = CODE_GUIDE_CONTEXT.format(
|
||||
requirement=requirement, prd=prd, tasks=tasks, design=design, code=old_codes
|
||||
)
|
||||
context = CODE_GUIDE_CONTEXT.format(requirement=requirement, tasks=tasks, design=design, code=old_codes)
|
||||
node = await WriteCodeGuide().run(context=context)
|
||||
guideline = node.instruct_content.json(ensure_ascii=False)
|
||||
return guideline
|
||||
|
|
|
|||
|
|
@ -120,6 +120,44 @@ MMC1 = """classDiagram
|
|||
SearchEngine --> Summary
|
||||
Index --> KnowledgeBase"""
|
||||
|
||||
MMC1_INC_AND_REFINE = """classDiagram
|
||||
class Main {
|
||||
-SearchEngine search_engine
|
||||
+main() str
|
||||
+newMethod() str # Incremental change
|
||||
}
|
||||
class SearchEngine {
|
||||
-Index index
|
||||
-Ranking ranking
|
||||
-Summary summary
|
||||
+search(query: str) str
|
||||
+newMethod() str # Incremental change
|
||||
}
|
||||
class Index {
|
||||
-KnowledgeBase knowledge_base
|
||||
+create_index(data: dict)
|
||||
+query_index(query: str) list
|
||||
+newMethod() list # Incremental change
|
||||
}
|
||||
class Ranking {
|
||||
+rank_results(results: list) list
|
||||
+newMethod() list # Incremental change
|
||||
}
|
||||
class Summary {
|
||||
+summarize_results(results: list) str
|
||||
+newMethod() str # Incremental change
|
||||
}
|
||||
class KnowledgeBase {
|
||||
+update(data: dict)
|
||||
+fetch_data(query: str) dict
|
||||
+newMethod() # Incremental change
|
||||
}
|
||||
Main --> SearchEngine
|
||||
SearchEngine --> Index
|
||||
SearchEngine --> Ranking
|
||||
SearchEngine --> Summary
|
||||
Index --> KnowledgeBase"""
|
||||
|
||||
MMC2 = """sequenceDiagram
|
||||
participant M as Main
|
||||
participant SE as SearchEngine
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue