fixbug: rfc243

This commit is contained in:
莘权 马 2024-06-15 15:35:47 +08:00
commit e1b3bd3869
17 changed files with 378 additions and 46 deletions

View file

@ -7,7 +7,18 @@
"""
from metagpt.actions import WritePRD
from metagpt.actions.design_api import WriteDesign
from metagpt.actions.requirement_analysis.framework import (
EvaluateFramework,
WriteFramework,
)
from metagpt.actions.requirement_analysis.trd import (
CompressExternalInterfaces,
DetectInteraction,
EvaluateTRD,
WriteTRD,
)
from metagpt.roles.di.role_zero import RoleZero
from metagpt.utils.common import tool2name
class Architect(RoleZero):
@ -29,9 +40,19 @@ class Architect(RoleZero):
"libraries. Use same language as user requirement"
)
instruction: str = """Use WriteDesign tool to write a system design document"""
instruction: str = """Use WriteDesign tool to write a system design document if a system design is required; Use WriteTRD tool to write a TRD if a TRD is required;"""
max_react_loop: int = 1 # FIXME: Read and edit files requires more steps, consider later
tools: list[str] = ["Editor:write,read,write_content", "RoleZero", "WriteDesign"]
tools: list[str] = [
"Editor:write,read,write_content",
"RoleZero",
"WriteDesign",
"CompressExternalInterfaces",
"DetectInteraction",
"EvaluateTRD",
"WriteTRD",
"WriteFramework",
"EvaluateFramework",
]
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
@ -45,10 +66,17 @@ class Architect(RoleZero):
self._watch({WritePRD})
def _update_tool_execution(self):
wd = WriteDesign()
self.tool_execution_map.update(
{
"WriteDesign.run": wd.run,
"WriteDesign": wd.run, # alias
}
)
write_design = WriteDesign()
self.tool_execution_map.update(tool2name(WriteDesign, ["run"], write_design.run))
compress_external_interfaces = CompressExternalInterfaces()
self.tool_execution_map.update(tool2name(CompressExternalInterfaces, ["run"], compress_external_interfaces.run))
detect_interaction = DetectInteraction()
self.tool_execution_map.update(tool2name(DetectInteraction, ["run"], detect_interaction.run))
evaluate_trd = EvaluateTRD()
self.tool_execution_map.update(tool2name(EvaluateTRD, ["run"], evaluate_trd.run))
write_trd = WriteTRD()
self.tool_execution_map.update(tool2name(WriteTRD, ["run"], write_trd.run))
write_framework = WriteFramework()
self.tool_execution_map.update(tool2name(WriteFramework, ["run"], write_framework.run))
evaluate_framework = EvaluateFramework()
self.tool_execution_map.update(tool2name(EvaluateFramework, ["run"], evaluate_framework.run))

View file

@ -3,7 +3,7 @@ from __future__ import annotations
import inspect
import json
import traceback
from typing import Literal, Tuple
from typing import Callable, Literal, Tuple
from pydantic import model_validator
@ -42,7 +42,7 @@ class RoleZero(Role):
# Tools
tools: list[str] = [] # Use special symbol ["<all>"] to indicate use of all registered tools
tool_recommender: ToolRecommender = None
tool_execution_map: dict[str, callable] = {}
tool_execution_map: dict[str, Callable] = {}
special_tool_commands: list[str] = ["Plan.finish_current_task", "end"]
# Equipped with three basic tools by default for optional use
editor: Editor = Editor()
@ -175,7 +175,7 @@ class RoleZero(Role):
actions_taken += 1
return rsp # return output from the last action
async def _run_commands(self, commands) -> list:
async def _run_commands(self, commands) -> str:
outputs = []
for cmd in commands:
# handle special command first
@ -247,7 +247,7 @@ class RoleZero(Role):
if not isinstance(self.rc.env, MGXEnv):
return "Not in MGXEnv, command will not be executed."
return await self.rc.env.get_human_input(question, sent_from=self)
return await self.rc.env.ask_human(question, sent_from=self)
async def reply_to_human(self, content: str) -> str:
"""Reply to human user with the content provided. Use this when you have a clear answer or solution to the user's question."""

View file

@ -18,7 +18,8 @@ class TeamLeader(RoleZero):
profile: str = "Team Leader"
system_msg: list[str] = [SYSTEM_PROMPT]
max_react_loop: int = 1 # TeamLeader only reacts once each time
# TeamLeader only reacts once each time, but may encounter errors or need to ask human, thus allowing 2 more turns
max_react_loop: int = 3
tools: list[str] = ["Plan", "RoleZero", "TeamLeader"]