Merge remote-tracking branch 'origin/mgx_ops' into feat-intention-fs

This commit is contained in:
Yizhou Chi 2024-08-12 18:16:35 +08:00
commit 502cb469a7
40 changed files with 832 additions and 168 deletions

View file

@ -8,7 +8,6 @@
from metagpt.actions import WritePRD
from metagpt.actions.design_api import WriteDesign
from metagpt.roles.di.role_zero import RoleZero
from metagpt.tools.libs.software_development import write_trd_and_framework
from metagpt.utils.common import tool2name
ARCHITECT_INSTRUCTION = """
@ -33,7 +32,7 @@ class Architect(RoleZero):
name: str = "Bob"
profile: str = "Architect"
goal: str = "design a concise, usable, complete software system. ouput the system design or software framework."
goal: str = "design a concise, usable, complete software system. output the system design."
constraints: str = (
"make sure the architecture is simple enough and use appropriate open source "
"libraries. Use same language as user requirement"
@ -45,7 +44,6 @@ class Architect(RoleZero):
"Editor:write,read,write_content",
"RoleZero",
"WriteDesign",
write_trd_and_framework.__name__,
]
def __init__(self, **kwargs) -> None:
@ -64,7 +62,6 @@ class Architect(RoleZero):
self.tool_execution_map.update(tool2name(WriteDesign, ["run"], write_design.run))
self.tool_execution_map.update(
{
write_trd_and_framework.__name__: write_trd_and_framework,
"run": write_design.run, # alias
}
)

View file

@ -23,6 +23,7 @@ from metagpt.prompts.di.role_zero import (
QUICK_THINK_PROMPT,
REGENERATE_PROMPT,
ROLE_INSTRUCTION,
SYSTEM_PROMPT,
THOUGHT_GUIDANCE,
)
from metagpt.roles import Role
@ -46,8 +47,9 @@ class RoleZero(Role):
name: str = "Zero"
profile: str = "RoleZero"
goal: str = ""
system_msg: list[str] = None # Use None to conform to the default value at llm.aask
system_prompt: str = SYSTEM_PROMPT # Use None to conform to the default value at llm.aask
cmd_prompt: str = CMD_PROMPT
cmd_prompt_current_state: str = ""
thought_guidance: str = THOUGHT_GUIDANCE
instruction: str = ROLE_INSTRUCTION
task_type_desc: str = None
@ -152,21 +154,24 @@ class RoleZero(Role):
tools = await self.tool_recommender.recommend_tools()
tool_info = json.dumps({tool.name: tool.schemas for tool in tools})
### Make Decision Dynamically ###
memory = self.rc.memory.get(self.memory_k)
### Role Instruction ###
instruction = self.instruction.strip()
system_prompt = self.system_prompt.format(
task_type_desc=self.task_type_desc, available_commands=tool_info, example=example, instruction=instruction
)
### Make Decision Dynamically ###
prompt = self.cmd_prompt.format(
example=example,
available_commands=tool_info,
task_type_desc=self.task_type_desc,
current_state=self.cmd_prompt_current_state,
plan_status=plan_status,
current_task=current_task,
instruction=instruction,
thought_guidance=self.thought_guidance,
latest_observation=memory[-1].content,
requirements_constraints=self.requirements_constraints,
)
### Recent Observation ###
memory = self.rc.memory.get(self.memory_k)
memory = await self.parse_browser_actions(memory)
req = self.llm.format_msg(memory + [UserMessage(content=prompt)])
async with ThoughtReporter(enable_llm_stream=True) as reporter:
await reporter.async_report({"type": "react"})
@ -175,7 +180,7 @@ class RoleZero(Role):
current_task=current_task,
instruction=instruction,
)
self.command_rsp = await self.llm_cached_aask(req=req, system_msgs=self.system_msg, state_data=state_data)
self.command_rsp = await self.llm_cached_aask(req=req, system_msgs=[system_prompt], state_data=state_data)
self.command_rsp = await self._check_duplicates(req, self.command_rsp)

View file

@ -4,9 +4,9 @@ from pydantic import Field
from metagpt.logs import logger
from metagpt.prompts.di.swe_agent import (
CURRENT_BASH_STATE,
MINIMAL_EXAMPLE,
NEXT_STEP_TEMPLATE,
SWE_AGENT_SYSTEM_TEMPLATE,
)
from metagpt.roles.di.role_zero import RoleZero
from metagpt.tools.libs.git import git_create_pull
@ -17,7 +17,6 @@ class SWEAgent(RoleZero):
name: str = "Swen"
profile: str = "Issue Solver"
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] = [
"Bash",
@ -54,7 +53,7 @@ class SWEAgent(RoleZero):
"""
state_output = await self.terminal.run("state")
bash_state = json.loads(state_output)
self.instruction = self._instruction.format(**bash_state).strip()
self.cmd_prompt_current_state = CURRENT_BASH_STATE.format(**bash_state).strip()
async def _parse_commands_for_eval(self):
"""

View file

@ -4,7 +4,6 @@ from metagpt.actions.di.run_command import RunCommand
from metagpt.prompts.di.team_leader import (
FINISH_CURRENT_TASK_CMD,
QUICK_THINK_SYSTEM_PROMPT,
SYSTEM_PROMPT,
TL_INSTRUCTION,
TL_THOUGHT_GUIDANCE,
)
@ -19,7 +18,6 @@ class TeamLeader(RoleZero):
name: str = "Mike"
profile: str = "Team Leader"
goal: str = "Manage a team to assist users"
system_msg: list[str] = [SYSTEM_PROMPT]
thought_guidance: str = TL_THOUGHT_GUIDANCE
# 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