diff --git a/metagpt/actions/write_code.py b/metagpt/actions/write_code.py index c1d56f523..77976a696 100644 --- a/metagpt/actions/write_code.py +++ b/metagpt/actions/write_code.py @@ -123,7 +123,7 @@ class WriteCode(Action): else: code_context = await self.get_codes(coding_context.task_doc, exclude=self.context.filename) - if guideline: # guide write code 也有两种方式,进行尝试 + if guideline: prompt = WRITE_CODE_INCREMENT_TEMPLATE.format( guideline=guideline, design=coding_context.design_doc.content if coding_context.design_doc else "", @@ -165,17 +165,17 @@ class WriteCode(Action): src_file_repo = CONFIG.git_repo.new_file_repository(relative_path=CONFIG.src_workspace) if mode == "guide": - # 从两个repo中取code,并结合在一起 src_files = src_file_repo.all_files old_file_repo = CONFIG.git_repo.new_file_repository(relative_path=CONFIG.old_workspace) old_files = old_file_repo.all_files union_files_list = list(set(src_files) | set(old_files)) for filename in union_files_list: if filename == exclude: - if filename in old_files: + if filename in old_files and filename != "main.py": doc = await old_file_repo.get(filename=filename) # 使用原始代码 else: continue + codes.append(f"----- Legacy {filename}\n```{doc.content}```") else: doc = await src_file_repo.get(filename=filename) # 使用先前生成的代码 @@ -185,7 +185,7 @@ class WriteCode(Action): # else: # continue continue # 跳过 - codes.append(f"----- {filename}\n```{doc.content}```") + codes.append(f"----- {filename}\n```{doc.content}```") else: for filename in code_filenames: diff --git a/metagpt/actions/write_code_guide_an.py b/metagpt/actions/write_code_guide_an.py index 579008732..8bf7da1a6 100644 --- a/metagpt/actions/write_code_guide_an.py +++ b/metagpt/actions/write_code_guide_an.py @@ -18,10 +18,10 @@ from metagpt.schema import Document GUIDELINE = ActionNode( key="Code Guideline", expected_type=list[str], - instruction="crafting comprehensive incremental development plans and providing detailed code guidance", + instruction="Developing comprehensive and incremental software development plans while providing detailed code guidance.", example=[ - "`calculator.py` should be extended to include methods for subtraction, multiplication, and division. Error handling should be implemented for division to prevent division by zero.", - "New endpoints for subtraction, multiplication, and division should be added to `main.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.", + "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.", ], ) @@ -155,10 +155,11 @@ ATTENTION: Use '##' to SPLIT SECTIONS, not '#'. Output format carefully referenc 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. CAREFULLY CHECK THAT YOU DONT MISS ANY NECESSARY CLASS/FUNCTION IN THIS FILE. -6. Before using a external variable/module, make sure you import it first. -7. Write out EVERY CODE DETAIL, DON'T LEAVE TODO. -8. Attention: Make modifications and additions to the legacy code in accordance with the provided guidelines and API. Ensure that the complete code is implemented without any omissions. +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. +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 = """ diff --git a/metagpt/roles/engineer.py b/metagpt/roles/engineer.py index 165ffadc2..2eee4c477 100644 --- a/metagpt/roles/engineer.py +++ b/metagpt/roles/engineer.py @@ -80,7 +80,6 @@ class Engineer(Role): ) n_borg: int = 1 use_code_review: bool = False - use_code_guide: bool = True code_todos: list = [] summarize_todos = [] @@ -138,7 +137,7 @@ class Engineer(Role): return None async def _act_write_code(self): - if self.use_code_guide: + if CONFIG.inc: code_guideline = await self._write_code_guideline() changed_files = await self._act_sp_with_cr(review=self.use_code_review, guideline=code_guideline) else: