From 78462d5199925fc0080e175f5787e6cf8b96dc93 Mon Sep 17 00:00:00 2001 From: garylin2099 Date: Mon, 29 Jul 2024 15:07:27 +0800 Subject: [PATCH] hard rule to ask human --- metagpt/prompts/di/role_zero.py | 12 ++++++++++++ metagpt/roles/di/role_zero.py | 6 ++++++ 2 files changed, 18 insertions(+) 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)