mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-29 02:46:24 +02:00
feat: merge mgx_ops
This commit is contained in:
commit
81540fe4d9
13 changed files with 719 additions and 55 deletions
|
|
@ -68,6 +68,12 @@ class SimpleExpRetriever(ExpRetriever):
|
|||
"content": "User request to create a cli snake game. Please create a product requirement document (PRD) outlining the features, user interface, and user experience of the snake game.",
|
||||
"send_to": "Alice"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command_name": "reply_to_human",
|
||||
"args": {
|
||||
"content": "I have assigned the tasks to the team members. Alice will create the PRD, Bob will design the software architecture, Eve will break down the architecture into tasks, Alex will implement the core game logic, and Edward will write comprehensive tests. The team will work on the project accordingly",
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
|
@ -92,6 +98,12 @@ class SimpleExpRetriever(ExpRetriever):
|
|||
"content": "Run data analysis on sklearn Wine recognition dataset, include a plot, and train a model to predict wine class (20% as validation), and show validation accuracy.",
|
||||
"send_to": "David"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command_name": "reply_to_human",
|
||||
"args": {
|
||||
"content": "I have assigned the task to David. He will break down the task further by himself and starts solving it.",
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
|
@ -110,10 +122,16 @@ class SimpleExpRetriever(ExpRetriever):
|
|||
"args": {}
|
||||
},
|
||||
{
|
||||
"command_name": "publish_message",
|
||||
"command_name": "publish_message",
|
||||
"args": {
|
||||
"content": "Please design the software architecture for the snake game based on the PRD created by Alice. The PRD is at 'docs/prd/20240424153821.json'. Include the choice of programming language, libraries, and data flow, etc.",
|
||||
"send_to": "Bob"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command_name": "reply_to_human",
|
||||
"args": {
|
||||
"content": "Please design the software architecture for the snake game based on the PRD created by Alice. The PRD is at 'docs/prd/20240424153821.json'. Include the choice of programming language, libraries, and data flow, etc.",
|
||||
"send_to": "Bob"
|
||||
"content": "Alice has completed the PRD. I have marked her task as finished and sent the PRD to Bob. Bob will work on the software architecture.",
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ from enum import Enum
|
|||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from metagpt.environment.mgx.mgx_env import MGXEnv
|
||||
from metagpt.roles import Role
|
||||
from metagpt.schema import Message, Task
|
||||
|
||||
|
||||
class CommandDef(BaseModel):
|
||||
name: str
|
||||
|
|
@ -66,3 +70,39 @@ def prepare_command_prompt(commands: list[Command]) -> str:
|
|||
for i, command in enumerate(commands):
|
||||
command_prompt += f"{i+1}. {command.value.signature}:\n{command.value.desc}\n\n"
|
||||
return command_prompt
|
||||
|
||||
|
||||
async def run_env_command(role: Role, cmd):
|
||||
assert isinstance(role.rc.env, MGXEnv), "TeamLeader should only be used in an MGXEnv"
|
||||
if cmd["command_name"] == Command.PUBLISH_MESSAGE.cmd_name:
|
||||
role.publish_message(Message(**cmd["args"]))
|
||||
if cmd["command_name"] == Command.ASK_HUMAN.cmd_name:
|
||||
role.rc.working_memory.add(Message(content=cmd["args"]["question"], role="assistant"))
|
||||
human_rsp = await role.rc.env.ask_human(sent_from=role, **cmd["args"])
|
||||
role.rc.working_memory.add(Message(content=human_rsp, role="user"))
|
||||
elif cmd["command_name"] == Command.REPLY_TO_HUMAN.cmd_name:
|
||||
# TODO: consider if the message should go into memory
|
||||
await role.rc.env.reply_to_human(sent_from=role, **cmd["args"])
|
||||
|
||||
|
||||
def run_plan_command(role: Role, cmd):
|
||||
if cmd["command_name"] == Command.APPEND_TASK.cmd_name:
|
||||
role.planner.plan.append_task(Task(**cmd["args"]))
|
||||
elif cmd["command_name"] == Command.RESET_TASK.cmd_name:
|
||||
role.planner.plan.reset_task(**cmd["args"])
|
||||
elif cmd["command_name"] == Command.REPLACE_TASK.cmd_name:
|
||||
role.planner.plan.replace_task(Task(**cmd["args"]))
|
||||
elif cmd["command_name"] == Command.FINISH_CURRENT_TASK.cmd_name:
|
||||
role.planner.plan.current_task.update_task_result(task_result=role.task_result)
|
||||
role.planner.plan.finish_current_task()
|
||||
role.rc.working_memory.clear()
|
||||
|
||||
|
||||
async def run_commands(role: Role, cmds):
|
||||
print(*cmds, sep="\n")
|
||||
for cmd in cmds:
|
||||
await run_env_command(role, cmd)
|
||||
run_plan_command(role, cmd)
|
||||
|
||||
if role.planner.plan.is_plan_finished():
|
||||
role._set_state(-1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue