Merge branch 'fix_duplicate' into 'mgx_ops'

a hard rule to prevent duplication

See merge request pub/MetaGPT!261
This commit is contained in:
林义章 2024-07-29 07:10:06 +00:00
commit 305aff0a4f
3 changed files with 19 additions and 1 deletions

View file

@ -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}

View file

@ -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)

View file

@ -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] = [