From b57f6c4035f102882be266e7e600af7e46afd343 Mon Sep 17 00:00:00 2001 From: garylin2099 Date: Mon, 14 Oct 2024 15:45:59 +0800 Subject: [PATCH] make quick think msg also public --- metagpt/environment/mgx/mgx_env.py | 4 +++- metagpt/roles/di/role_zero.py | 7 ++++--- metagpt/roles/di/team_leader.py | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/metagpt/environment/mgx/mgx_env.py b/metagpt/environment/mgx/mgx_env.py index c1567fe9a..f360cd605 100644 --- a/metagpt/environment/mgx/mgx_env.py +++ b/metagpt/environment/mgx/mgx_env.py @@ -40,8 +40,10 @@ class MGXEnv(Environment, SerializationMixin): # tl.rc.memory.add(self.move_message_info_to_content(message)) elif message.sent_from in self.direct_chat_roles: - # direct chat response from a certain role to human user, team leader and other roles in the env should not be involved, no need to publish + # if chat is not public, direct chat response from a certain role to human user, team leader and other roles in the env should not be involved, no need to publish self.direct_chat_roles.remove(message.sent_from) + if self.is_public_chat: + self._publish_message(message) elif publicer == tl.profile: if message.send_to == {"no one"}: diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index 7e09481b1..74f189b71 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -29,6 +29,7 @@ from metagpt.prompts.di.role_zero import ( QUICK_THINK_EXAMPLES, QUICK_THINK_PROMPT, QUICK_THINK_SYSTEM_PROMPT, + QUICK_THINK_TAG, REGENERATE_PROMPT, REPORT_TO_HUMAN_PROMPT, ROLE_INSTRUCTION, @@ -397,12 +398,12 @@ class RoleZero(Role): answer = await SearchEnhancedQA().run(query) if answer: - self.rc.memory.add(AIMessage(content=answer, cause_by=RunCommand)) + self.rc.memory.add(AIMessage(content=answer, cause_by=QUICK_THINK_TAG)) await self.reply_to_human(content=answer) rsp_msg = AIMessage( - content="Complete run", + content=answer, sent_from=self.name, - cause_by=RunCommand, + cause_by=QUICK_THINK_TAG, ) return rsp_msg, intent_result diff --git a/metagpt/roles/di/team_leader.py b/metagpt/roles/di/team_leader.py index 0724ffdea..7a8b8b5be 100644 --- a/metagpt/roles/di/team_leader.py +++ b/metagpt/roles/di/team_leader.py @@ -6,6 +6,7 @@ from pydantic import Field from metagpt.actions.di.run_command import RunCommand from metagpt.const import TEAMLEADER_NAME +from metagpt.prompts.di.role_zero import QUICK_THINK_TAG from metagpt.prompts.di.team_leader import ( FINISH_CURRENT_TASK_CMD, TL_INFO, @@ -61,13 +62,14 @@ class TeamLeader(RoleZero): return await super()._think() def publish_message(self, msg: Message, send_to="no one"): - """Overwrite Role.publish_message, send to no one if called within Role.run, send to the specified role if called dynamically.""" + """Overwrite Role.publish_message, send to no one if called within Role.run (except for quick think), send to the specified role if called dynamically.""" if not msg: return if not self.rc.env: # If env does not exist, do not publish the message return - msg.send_to = send_to + if msg.cause_by != QUICK_THINK_TAG: + msg.send_to = send_to self.rc.env.publish_message(msg, publicer=self.profile) def publish_team_message(self, content: str, send_to: str):