diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 478f5c0d4..de1673e62 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -80,6 +80,18 @@ Review and reflect on the history carefully, provide a different response. Describe if you should terminate using **end** command, or use **RoleZero.ask_human** to ask human for help, or try a different approach and output different commands. You are NOT allowed to provide the same commands again. Your reflection, then the commands in a json array: """ +ASK_HUMAN_COMMAND = """ +```json +[ + { + "command_name": "RoleZero.ask_human", + "args": { + "question": "I'm a little uncertain about the next step, could you provide me with some guidance?" + } + } +] +``` +""" JSON_REPAIR_PROMPT = """ ## json data {json_data} diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 6d6eb26ce..ad5c2d26a 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -15,6 +15,7 @@ from metagpt.exp_pool.context_builders import RoleZeroContextBuilder from metagpt.exp_pool.serializers import RoleZeroSerializer from metagpt.logs import logger from metagpt.prompts.di.role_zero import ( + ASK_HUMAN_COMMAND, CMD_PROMPT, JSON_REPAIR_PROMPT, QUICK_THINK_PROMPT, @@ -272,6 +273,11 @@ class RoleZero(Role): # If an identical response is detected, it is a bad response, mostly due to LLM repeating generated content # In this case, ask human for help and regenerate # TODO: switch to llm_cached_aask + + # Hard rule to ask human for help + if past_rsp.count(command_rsp) >= 3: + return ASK_HUMAN_COMMAND + # Try correction by self logger.warning(f"Duplicate response detected: {command_rsp}") regenerate_req = req + [UserMessage(content=REGENERATE_PROMPT)] regenerate_req = self.llm.format_msg(regenerate_req) diff --git a/metagpt/roles/di/swe_agent.py b/metagpt/roles/di/swe_agent.py index 7be794265..2384ac147 100644 --- a/metagpt/roles/di/swe_agent.py +++ b/metagpt/roles/di/swe_agent.py @@ -16,7 +16,7 @@ from metagpt.tools.libs.terminal import Bash class SWEAgent(RoleZero): name: str = "Swen" profile: str = "Issue Solver" - goal: str = "Resolve GitHub issue" + goal: str = "Resolve GitHub issue or bug in any existing codebase" system_msg: str = [SWE_AGENT_SYSTEM_TEMPLATE] _instruction: str = NEXT_STEP_TEMPLATE tools: list[str] = [