From f134126a909622c09b90bec0f3167539097ed54e Mon Sep 17 00:00:00 2001 From: yzlin Date: Mon, 29 Apr 2024 17:34:52 +0800 Subject: [PATCH] make tl always reply to human --- metagpt/prompts/di/team_leader.py | 6 ++++++ metagpt/roles/di/team_leader.py | 8 ++++++-- metagpt/strategy/experience_retriever.py | 24 +++++++++++++++++++++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/metagpt/prompts/di/team_leader.py b/metagpt/prompts/di/team_leader.py index dd9c46618..c5f6a79aa 100644 --- a/metagpt/prompts/di/team_leader.py +++ b/metagpt/prompts/di/team_leader.py @@ -1,3 +1,9 @@ +SYSTEM_PROMPT = """ +You are a team leader, and you are responsible for drafting tasks and routing tasks to your team members. +When drafting and routing tasks, ALWAYS include necessary or important info inside the instruction, such as path, link, environment to team members, because you are their sole info source. +Each time you do something, reply to human letting them know what you did. +""" + CMD_PROMPT = """ # Data Structure class Task(BaseModel): diff --git a/metagpt/roles/di/team_leader.py b/metagpt/roles/di/team_leader.py index b3f0ae78a..0224b11dc 100644 --- a/metagpt/roles/di/team_leader.py +++ b/metagpt/roles/di/team_leader.py @@ -6,7 +6,11 @@ from pydantic import model_validator from metagpt.actions.di.run_command import RunCommand from metagpt.environment.mgx.mgx_env import MGXEnv -from metagpt.prompts.di.team_leader import CMD_PROMPT, FINISH_CURRENT_TASK_CMD +from metagpt.prompts.di.team_leader import ( + CMD_PROMPT, + FINISH_CURRENT_TASK_CMD, + SYSTEM_PROMPT, +) from metagpt.roles import Role from metagpt.schema import Message, Task, TaskResult from metagpt.strategy.experience_retriever import SimpleExpRetriever @@ -92,7 +96,7 @@ class TeamLeader(Role): ) context = self.llm.format_msg(self.get_memories(k=10) + [Message(content=prompt, role="user")]) - rsp = await self.llm.aask(context) + rsp = await self.llm.aask(context, system_msgs=[SYSTEM_PROMPT]) self.commands = json.loads(CodeParser.parse_code(block=None, text=rsp)) self.rc.memory.add(Message(content=rsp, role="assistant")) diff --git a/metagpt/strategy/experience_retriever.py b/metagpt/strategy/experience_retriever.py index e0d2601e3..34ff184ab 100644 --- a/metagpt/strategy/experience_retriever.py +++ b/metagpt/strategy/experience_retriever.py @@ -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.", } } ]