From 11faaf0651bf53ae59b19bf6e0c6672eb1f87a92 Mon Sep 17 00:00:00 2001 From: mannaandpoem <1580466765@qq.com> Date: Tue, 2 Jan 2024 22:57:42 +0800 Subject: [PATCH] Modify style and format --- metagpt/actions/design_api.py | 8 +- metagpt/actions/design_api_an.py | 69 ++++++++--------- metagpt/actions/project_management.py | 4 +- metagpt/actions/project_management_an.py | 51 +++++++------ metagpt/actions/write_code.py | 6 +- ...guide_an.py => write_code_guideline_an.py} | 43 +++++------ metagpt/actions/write_prd.py | 4 +- metagpt/actions/write_prd_an.py | 75 ++++++++----------- metagpt/roles/engineer.py | 9 ++- metagpt/utils/mermaid.py | 4 +- 10 files changed, 130 insertions(+), 143 deletions(-) rename metagpt/actions/{write_code_guide_an.py => write_code_guideline_an.py} (87%) diff --git a/metagpt/actions/design_api.py b/metagpt/actions/design_api.py index 0cc3395ed..082474098 100644 --- a/metagpt/actions/design_api.py +++ b/metagpt/actions/design_api.py @@ -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, REFINE_DESIGN_NODES +from metagpt.actions.design_api_an import DESIGN_API_NODE, REFINED_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 REFINE_DESIGN_NODES.fill(context=context, llm=self.llm, schema=schema) + node = await REFINED_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 @@ -114,7 +114,7 @@ class WriteDesign(Action): @staticmethod async def _save_data_api_design(design_doc): m = json.loads(design_doc.content) - data_api_design = m.get("Data structures and interfaces") + data_api_design = m.get("Data structures and interfaces") or m.get("Refined Data structures and interfaces") if not data_api_design: return pathname = CONFIG.git_repo.workdir / DATA_API_DESIGN_FILE_REPO / Path(design_doc.filename).with_suffix("") @@ -124,7 +124,7 @@ class WriteDesign(Action): @staticmethod async def _save_seq_flow(design_doc): m = json.loads(design_doc.content) - seq_flow = m.get("Program call flow") + seq_flow = m.get("Program call flow") or m.get("Refined Program call flow") if not seq_flow: return pathname = CONFIG.git_repo.workdir / Path(SEQ_FLOW_FILE_REPO) / Path(design_doc.filename).with_suffix("") diff --git a/metagpt/actions/design_api_an.py b/metagpt/actions/design_api_an.py index 5f17d4656..fcfaff9c3 100644 --- a/metagpt/actions/design_api_an.py +++ b/metagpt/actions/design_api_an.py @@ -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, MMC1_INC_AND_REFINE, MMC2, MMC2_INC +from metagpt.utils.mermaid import MMC1, MMC1_REFINE, MMC2, MMC2_REFINE IMPLEMENTATION_APPROACH = ActionNode( key="Implementation approach", @@ -18,7 +18,7 @@ IMPLEMENTATION_APPROACH = ActionNode( example="We will ...", ) -INC_IMPLEMENTATION_APPROACH = ActionNode( +INCREMENTAL_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. " @@ -26,12 +26,12 @@ INC_IMPLEMENTATION_APPROACH = ActionNode( example="we will ...", ) -REFINE_IMPLEMENTATION_APPROACH = ActionNode( - key="Implementation Approach", +REFINED_IMPLEMENTATION_APPROACH = ActionNode( + key="Refined 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.", + 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. Retain any content unrelated to incremental development for coherence and clarity.", example="We will refine ...", ) @@ -46,13 +46,13 @@ FILE_LIST = ActionNode( example=["main.py", "game.py"], ) -REFINE_FILE_LIST = ActionNode( - key="File List", +REFINED_FILE_LIST = ActionNode( + key="Refined 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." - "Only output filename!Do not include comments in the list.", - example=["main.py", "game.py", "utils.py", "new_feature.py"], + "Only output filename! Do not include comments in the list.", + example=["main.py", "game.py", "new_feature.py"], ) DATA_STRUCTURES_AND_INTERFACES = ActionNode( @@ -64,25 +64,25 @@ DATA_STRUCTURES_AND_INTERFACES = ActionNode( example=MMC1, ) -INC_DATA_STRUCTURES_AND_INTERFACES = ActionNode( +INCREMENTAL_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, + example=MMC1_REFINE, ) -REFINE_DATA_STRUCTURES_AND_INTERFACES = ActionNode( - key="Data Structures and Interfaces", +REFINED_DATA_STRUCTURES_AND_INTERFACES = ActionNode( + key="Refined 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, + example=MMC1_REFINE, ) PROGRAM_CALL_FLOW = ActionNode( @@ -93,13 +93,13 @@ PROGRAM_CALL_FLOW = ActionNode( example=MMC2, ) -REFINE_PROGRAM_CALL_FLOW = ActionNode( - key="Program call flow", +REFINED_PROGRAM_CALL_FLOW = ActionNode( + key="Refined Program call flow", expected_type=str, instruction="Extend the existing sequenceDiagram code syntax with detailed information, accurately covering the" "CRUD and initialization of each object. Ensure correct syntax usage and reflect the incremental changes introduced" "in the classes and API defined above.Retain content unrelated to incremental development for coherence and clarity", - example=MMC2_INC, + example=MMC2_REFINE, ) ANYTHING_UNCLEAR = ActionNode( @@ -110,13 +110,13 @@ ANYTHING_UNCLEAR = ActionNode( ) INC_DESIGN_CONTEXT = """ -### Legacy Content +## Legacy Content {old_design} -### New Requirements +## New Requirements {requirements} -### PRD Increment Content +## PRD Increment Content {prd_increment} """ @@ -124,43 +124,44 @@ 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 +# Context +## New Requirements {requirements} -### Legacy Content +## Legacy Content {old_design} -### Design Increment Content +## Design Increment Content {design_increment} """ NODES = [ IMPLEMENTATION_APPROACH, # PROJECT_NAME, - FILE_LIST, + REFINED_FILE_LIST, DATA_STRUCTURES_AND_INTERFACES, PROGRAM_CALL_FLOW, ANYTHING_UNCLEAR, ] -INC_NODES = [INC_IMPLEMENTATION_APPROACH, INC_DATA_STRUCTURES_AND_INTERFACES, REFINE_PROGRAM_CALL_FLOW] +INC_NODES = [INCREMENTAL_IMPLEMENTATION_APPROACH, INCREMENTAL_DATA_STRUCTURES_AND_INTERFACES, REFINED_PROGRAM_CALL_FLOW] REFINE_NODES = [ - REFINE_IMPLEMENTATION_APPROACH, + REFINED_IMPLEMENTATION_APPROACH, # PROJECT_NAME, - REFINE_FILE_LIST, - REFINE_DATA_STRUCTURES_AND_INTERFACES, - REFINE_PROGRAM_CALL_FLOW, + FILE_LIST, + REFINED_DATA_STRUCTURES_AND_INTERFACES, + REFINED_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) +INCREMENTAL_DESIGN_NODES = ActionNode.from_children("Incremental_Design_API", INC_NODES) +REFINED_DESIGN_NODES = ActionNode.from_children("Refined_Design_API", REFINE_NODES) def main(): - prompt = REFINE_DESIGN_NODES.compile(context="12313") + prompt = REFINED_DESIGN_NODES.compile(context="...") logger.info(prompt) diff --git a/metagpt/actions/project_management.py b/metagpt/actions/project_management.py index 5d2791ea8..f124ba8df 100644 --- a/metagpt/actions/project_management.py +++ b/metagpt/actions/project_management.py @@ -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, REFINE_PM_NODES +from metagpt.actions.project_management_an import PM_NODE, REFINED_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 REFINE_PM_NODES.fill(context, self.llm, schema) + node = await REFINED_PM_NODES.fill(context, self.llm, schema) task_doc.content = node.instruct_content.json(ensure_ascii=False) return task_doc diff --git a/metagpt/actions/project_management_an.py b/metagpt/actions/project_management_an.py index 27d238e9f..467d26b4e 100644 --- a/metagpt/actions/project_management_an.py +++ b/metagpt/actions/project_management_an.py @@ -35,18 +35,20 @@ LOGIC_ANALYSIS = ActionNode( ], ) -INC_LOGIC_ANALYSIS = ActionNode( - key="Increment Logic Analysis", +INCREMENTAL_LOGIC_ANALYSIS = ActionNode( + key="Incremental 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.", + 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", +REFINED_LOGIC_ANALYSIS = ActionNode( + key="Refined 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. " @@ -67,7 +69,7 @@ TASK_LIST = ActionNode( example=["game.py", "main.py"], ) -INC_TASK_LIST = ActionNode( +INCREMENTAL_TASK_LIST = ActionNode( key="Incremental Task list", expected_type=List[str], instruction="Break down the incremental development tasks into a prioritized list of filenames." @@ -76,8 +78,8 @@ INC_TASK_LIST = ActionNode( example=["new_feature.py", "utils.py", "main.py"], ) -REFINE_TASK_LIST = ActionNode( - key="Task list", +REFINED_TASK_LIST = ActionNode( + key="Refined 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" @@ -100,20 +102,20 @@ SHARED_KNOWLEDGE = ActionNode( example="`game.py` contains functions shared across the project.", ) -INC_SHARED_KNOWLEDGE = ActionNode( - key="Increment Shared Knowledge", +INCREMENTAL_SHARED_KNOWLEDGE = ActionNode( + key="Incremental 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", +REFINED_SHARED_KNOWLEDGE = ActionNode( + key="Refined 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.", + 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.", ) @@ -140,13 +142,14 @@ 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 +# Context +## New Requirements {requirements} -### Legacy Content +## Legacy Content {old_tasks} -### Increment Content +## Increment Content {tasks_increment} """ @@ -160,21 +163,21 @@ NODES = [ ANYTHING_UNCLEAR_PM, ] -INC_NODES = [INC_LOGIC_ANALYSIS, INC_TASK_LIST, INC_SHARED_KNOWLEDGE] +INC_NODES = [INCREMENTAL_LOGIC_ANALYSIS, INCREMENTAL_TASK_LIST, INCREMENTAL_SHARED_KNOWLEDGE] REFINE_NODES = [ REQUIRED_PYTHON_PACKAGES, REQUIRED_OTHER_LANGUAGE_PACKAGES, - REFINE_LOGIC_ANALYSIS, - REFINE_TASK_LIST, + REFINED_LOGIC_ANALYSIS, + REFINED_TASK_LIST, FULL_API_SPEC, - REFINE_SHARED_KNOWLEDGE, + REFINED_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) +INCREMENTAL_PM_NODES = ActionNode.from_children("Incremental_PM_NODES", INC_NODES) +REFINED_PM_NODES = ActionNode.from_children("Refined_PM_NODES", REFINE_NODES) def main(): diff --git a/metagpt/actions/write_code.py b/metagpt/actions/write_code.py index 33ae2e5b3..4183db19d 100644 --- a/metagpt/actions/write_code.py +++ b/metagpt/actions/write_code.py @@ -21,7 +21,7 @@ from pydantic import Field from tenacity import retry, stop_after_attempt, wait_random_exponential from metagpt.actions.action import Action -from metagpt.actions.write_code_guide_an import WRITE_CODE_INCREMENT_TEMPLATE +from metagpt.actions.write_code_guideline_an import REFINED_TEMPLATE from metagpt.config import CONFIG from metagpt.const import ( BUGFIX_FILENAME, @@ -127,7 +127,7 @@ class WriteCode(Action): code_context = await self.get_codes(coding_context.task_doc, exclude=self.context.filename) if guideline: - prompt = WRITE_CODE_INCREMENT_TEMPLATE.format( + prompt = REFINED_TEMPLATE.format( requirement=requirement_doc.content if requirement_doc else "", guideline=guideline, design=coding_context.design_doc.content if coding_context.design_doc else "", @@ -164,7 +164,7 @@ class WriteCode(Action): if not task_doc.content: task_doc.content = FileRepository.get_file(filename=task_doc.filename, relative_path=TASK_FILE_REPO) m = json.loads(task_doc.content) - code_filenames = m.get("Task list", []) + code_filenames = m.get("Task list", []) if mode == "normal" else m.get("Refined Task list", []) codes = [] src_file_repo = CONFIG.git_repo.new_file_repository(relative_path=CONFIG.src_workspace) diff --git a/metagpt/actions/write_code_guide_an.py b/metagpt/actions/write_code_guideline_an.py similarity index 87% rename from metagpt/actions/write_code_guide_an.py rename to metagpt/actions/write_code_guideline_an.py index b21e66098..d68b02d38 100644 --- a/metagpt/actions/write_code_guide_an.py +++ b/metagpt/actions/write_code_guideline_an.py @@ -7,18 +7,13 @@ """ import asyncio -from pydantic import Field - from metagpt.actions.action import Action from metagpt.actions.action_node import ActionNode -from metagpt.llm import LLM -from metagpt.provider.base_gpt_api import BaseGPTAPI -from metagpt.schema import Document GUIDELINE = ActionNode( - key="Code Guideline", + key="Guideline", expected_type=list[str], - instruction="Developing comprehensive and incremental software development plans while providing detailed code guidance.", + instruction="Developing comprehensive and incremental development plans while providing detailed code guideline.", example=[ "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.", "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.", @@ -28,7 +23,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 including detailed steps based on the context.", + 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 @@ -81,8 +77,8 @@ if __name__ == '__main__': ```""", ) -CODE_GUIDE_CONTEXT = """ -### NOTICE +CODE_GUIDELINE_CONTEXT = """ +NOTICE Role: You are a professional software engineer, and your main task is to craft comprehensive incremental development plans and provide detailed code guidance with triple quote, based on the following attentions and context. Output format carefully referenced "Format example". 1. Determine the scope of responsibilities of each file and what classes and methods need to be implemented. 2. Import all referenced classes. @@ -93,20 +89,21 @@ Role: You are a professional software engineer, and your main task is to craft c 7. Examine the code closely to find and fix errors, and confirm that the logic is sound to ensure smooth user interaction while meeting all specified requirements. 8. Attention: Code files in the task list may have a different number of files compared to legacy code files. This requires integrating legacy code files that do not appear in the task list into the code files of the task list. Therefore, when writing code guidance and incremental changes for the code files in the task list, also include how to seamlessly merge and adjust legacy code files. -### Requirement +# Context +## Requirement {requirement} -### Design +## Design {design} -### Tasks +## Tasks {tasks} -### Legacy Code +## Legacy Code {code} """ -WRITE_CODE_INCREMENT_TEMPLATE = """ +REFINED_TEMPLATE = """ NOTICE 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. @@ -161,7 +158,7 @@ Role: You are a professional engineer; The main goal is to complete incremental """ CODE_GUIDE_CONTEXT_EXAMPLE = """ -### Legacy Code +# Legacy Code ## main.py from flask import Flask, request, jsonify @@ -194,21 +191,17 @@ class Calculator: GUIDE_NODES = [INCREMENTAL_CHANGE] -WRITE_CODE_GUIDE_NODE = ActionNode.from_children("WriteCodeGuide", GUIDE_NODES) +WRITE_CODE_GUIDELINE_NODE = ActionNode.from_children("WriteCodeGuideline", GUIDE_NODES) -class WriteCodeGuide(Action): - name: str = "WriteCodeGuide" - context: Document = Field(default_factory=Document) - llm: BaseGPTAPI = Field(default_factory=LLM) - +class WriteCodeGuideline(Action): async def run(self, context): - return await WRITE_CODE_GUIDE_NODE.fill(context=context, llm=self.llm, schema="json") + return await WRITE_CODE_GUIDELINE_NODE.fill(context=context, llm=self.llm, schema="json") def main(): - action = WriteCodeGuide() - return asyncio.run(action.run(CODE_GUIDE_CONTEXT)) + action = WriteCodeGuideline() + return asyncio.run(action.run(CODE_GUIDELINE_CONTEXT)) if __name__ == "__main__": diff --git a/metagpt/actions/write_prd.py b/metagpt/actions/write_prd.py index dc1af0735..a070e7a96 100644 --- a/metagpt/actions/write_prd.py +++ b/metagpt/actions/write_prd.py @@ -24,7 +24,7 @@ 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, + REFINE_PRD_TEMPLATE, WP_IS_RELATIVE_NODE, WP_ISSUE_TYPE_NODE, WRITE_PRD_NODE, @@ -139,7 +139,7 @@ class WritePRD(Action): CONFIG.project_name = Path(CONFIG.project_path).name project_name = CONFIG.project_name if CONFIG.project_name else "" - prompt = REFINE_PRD_SIMPLE_CONTEXT.format( + prompt = REFINE_PRD_TEMPLATE.format( requirements=new_requirement_doc.content, old_prd=prd_doc.content, project_name=project_name, diff --git a/metagpt/actions/write_prd_an.py b/metagpt/actions/write_prd_an.py index 79046bb7d..f645225c7 100644 --- a/metagpt/actions/write_prd_an.py +++ b/metagpt/actions/write_prd_an.py @@ -31,8 +31,8 @@ ORIGINAL_REQUIREMENTS = ActionNode( example="Create a 2048 game", ) -REFINE_REQUIREMENTS = ActionNode( - key="Original Requirements", +REFINED_REQUIREMENTS = ActionNode( + key="Refined 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", @@ -46,13 +46,6 @@ 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], @@ -60,8 +53,8 @@ PRODUCT_GOALS = ActionNode( example=["Create an engaging user experience", "Improve accessibility, be responsive", "More beautiful UI"], ) -REFINE_PRODUCT_GOALS = ActionNode( - key="Product Goals", +REFINED_PRODUCT_GOALS = ActionNode( + key="Refined 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." @@ -86,11 +79,11 @@ USER_STORIES = ActionNode( ], ) -REFINE_USER_STORIES = ActionNode( - key="User Stories", +REFINED_USER_STORIES = ActionNode( + key="Refined 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 " + "incremental development, no less than 5. 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", @@ -140,6 +133,14 @@ REQUIREMENT_ANALYSIS = ActionNode( example="", ) +INCREMENTAL_REQUIREMENT_ANALYSIS = ActionNode( + key="Incremental 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 ..."], +) + REQUIREMENT_POOL = ActionNode( key="Requirement Pool", expected_type=List[List[str]], @@ -147,8 +148,8 @@ REQUIREMENT_POOL = ActionNode( example=[["P0", "The main code ..."], ["P0", "The game algorithm ..."]], ) -REFINE_REQUIREMENT_POOL = ActionNode( - key="Requirement Pool", +REFINED_REQUIREMENT_POOL = ActionNode( + key="Refined 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", @@ -192,25 +193,18 @@ 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 +# Context +## New Requirements {requirements} -### Legacy Content +## Legacy Content {old_prd} -### PRD Incremental Content +## PRD Incremental Content {prd_increment} - -### Search Information -- """ -REFINE_PRD_SIMPLE_CONTEXT = """ -You are a professional Product Manager tasked with overseeing incremental development. - +REFINE_PRD_TEMPLATE = """ ### New Project Name {project_name} @@ -224,13 +218,6 @@ You are a professional Product Manager tasked with overseeing incremental develo - """ -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, @@ -250,30 +237,30 @@ NODES = [ REFINE_NODES = [ LANGUAGE, PROGRAMMING_LANGUAGE, - REFINE_REQUIREMENTS, - REFINE_PROJECT_NAME, - REFINE_PRODUCT_GOALS, - REFINE_USER_STORIES, + REFINED_REQUIREMENTS, + PROJECT_NAME, + REFINED_PRODUCT_GOALS, + REFINED_USER_STORIES, COMPETITIVE_ANALYSIS, COMPETITIVE_QUADRANT_CHART, - INCREMENTAL_DEVELOPMENT_ANALYSIS, - REFINE_REQUIREMENT_POOL, + INCREMENTAL_REQUIREMENT_ANALYSIS, + REFINED_REQUIREMENT_POOL, UI_DESIGN_DRAFT, ANYTHING_UNCLEAR, ] -INCREMENT_PRD_NODES = [INCREMENTAL_DEVELOPMENT_ANALYSIS, REQUIREMENT_POOL] +INCREMENT_PRD_NODES = [INCREMENTAL_REQUIREMENT_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) +INCREMENTAL_PRD_NODE = ActionNode.from_children("IncrementalPRD", 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 = INCREMENT_NODE.compile(context=REFINE_PRD_CONTEXT) + prompt = INCREMENTAL_PRD_NODE.compile(context=REFINE_PRD_CONTEXT) logger.info(prompt) diff --git a/metagpt/roles/engineer.py b/metagpt/roles/engineer.py index 4aa8f209d..d3584e987 100644 --- a/metagpt/roles/engineer.py +++ b/metagpt/roles/engineer.py @@ -28,7 +28,10 @@ from typing import Set from metagpt.actions import Action, WriteCode, WriteCodeReview, WriteTasks from metagpt.actions.fix_bug import FixBug from metagpt.actions.summarize_code import SummarizeCode -from metagpt.actions.write_code_guide_an import CODE_GUIDE_CONTEXT, WriteCodeGuide +from metagpt.actions.write_code_guideline_an import ( + CODE_GUIDELINE_CONTEXT, + WriteCodeGuideline, +) from metagpt.config import CONFIG from metagpt.const import ( CODE_SUMMARIES_FILE_REPO, @@ -323,8 +326,8 @@ class Engineer(Role): tasks = "\n".join([doc.content for doc in tasks]) old_codes = await self.get_old_codes() - context = CODE_GUIDE_CONTEXT.format(requirement=requirement, tasks=tasks, design=design, code=old_codes) - node = await WriteCodeGuide().run(context=context) + context = CODE_GUIDELINE_CONTEXT.format(requirement=requirement, tasks=tasks, design=design, code=old_codes) + node = await WriteCodeGuideline().run(context=context) guideline = node.instruct_content.json(ensure_ascii=False) return guideline diff --git a/metagpt/utils/mermaid.py b/metagpt/utils/mermaid.py index d1cd1b328..76adbf5a7 100644 --- a/metagpt/utils/mermaid.py +++ b/metagpt/utils/mermaid.py @@ -120,7 +120,7 @@ MMC1 = """classDiagram SearchEngine --> Summary Index --> KnowledgeBase""" -MMC1_INC_AND_REFINE = """classDiagram +MMC1_REFINE = """classDiagram class Main { -SearchEngine search_engine +main() str @@ -176,7 +176,7 @@ MMC2 = """sequenceDiagram S-->>SE: return summary SE-->>M: return summary""" -MMC2_INC = """sequenceDiagram +MMC2_REFINE = """sequenceDiagram participant M as Main participant SE as SearchEngine participant I as Index