make quick think msg also public

This commit is contained in:
garylin2099 2024-10-14 15:45:59 +08:00
parent d925d1381a
commit b57f6c4035
3 changed files with 11 additions and 6 deletions

View file

@ -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"}:

View file

@ -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

View file

@ -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):