Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

add static coding instrction in engineer prompt

黄伟韬2637af2a40bf
diff --git a/metagpt/prompts/di/engineer2.py b/metagpt/prompts/di/engineer2.py
index 016884d2b..5c43d401b 100644
--- a/metagpt/prompts/di/engineer2.py
+++ b/metagpt/prompts/di/engineer2.py
@@ -108,8 +108,11 @@ WRITE_CODE_PROMPT = """
# Current Coding File
{file_path}
-# Further Instruction
-{instruction}
+# File Description
+{file_description}
+
+# Instruction
+Your task is to write the {file_name} according to the User Requirement.
# Output
While some concise thoughts are helpful, code is absolutely required. Always output one and only one code block in your response. Output code in the following format:
diff --git a/metagpt/roles/di/engineer2.py b/metagpt/roles/di/engineer2.py
index 3d80e6a26..2404949cb 100644
--- a/metagpt/roles/di/engineer2.py
+++ b/metagpt/roles/di/engineer2.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import os
from pathlib import Path
from pydantic import Field
@@ -113,19 +114,20 @@ class Engineer2(RoleZero):
command_output += await super()._run_special_command(cmd)
return command_output
- async def write_new_code(self, path: str, instruction: str = "Write code for the current file.") -> str:
+ async def write_new_code(self, path: str, file_description: str = "") -> str:
"""Write a new code file.
Args:
path (str): The absolute path of the file to be created.
- instruction (optional, str): Further hints or notice other than the current task instruction, must be very concise and can be empty. Defaults to "".
+ file_description (optional, str): Further hints or notice other than the current task description, must be very concise and can be empty. Defaults to "".
"""
plan_status, _ = self._get_plan_status()
prompt = WRITE_CODE_PROMPT.format(
user_requirement=self.planner.plan.goal,
- file_path=path,
plan_status=plan_status,
- instruction=instruction,
+ file_path=path,
+ file_description=file_description,
+ file_name=os.path.basename(path),
)
# Sometimes the Engineer repeats the last command to respond.
# Replace the last command with a manual prompt to guide the Engineer to write new code.