mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
optimize direct chat logic
This commit is contained in:
parent
e450a37daf
commit
2083233d41
2 changed files with 9 additions and 6 deletions
|
|
@ -159,7 +159,7 @@ class Environment(ExtEnv):
|
|||
"""增加一个在当前环境的角色
|
||||
Add a role in the current environment
|
||||
"""
|
||||
self.roles[role.profile] = role
|
||||
self.roles[role.name] = role
|
||||
role.set_env(self)
|
||||
role.context = self.context
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ class Environment(ExtEnv):
|
|||
Add a batch of characters in the current environment
|
||||
"""
|
||||
for role in roles:
|
||||
self.roles[role.profile] = role
|
||||
self.roles[role.name] = role
|
||||
|
||||
for role in roles: # setup system message with roles
|
||||
role.context = self.context
|
||||
|
|
|
|||
|
|
@ -27,19 +27,22 @@ class MGXEnv(Environment):
|
|||
|
||||
def publish_message(self, message: Message, user_defined_recipient: str = "", publicer: str = "") -> bool:
|
||||
"""let the team leader take over message publishing"""
|
||||
tl = self.get_role("Team Leader")
|
||||
tl = self.get_role("Tim") # TeamLeader's name is Tim
|
||||
|
||||
if user_defined_recipient:
|
||||
# human user's direct chat message to a certain role
|
||||
|
||||
if self.get_role(user_defined_recipient).is_idle:
|
||||
# User starts a new direct chat with a certain role, expecting a direct chat response from the role; Other roles including TL should not be involved.
|
||||
# If the role is not idle, it means the user helps the role with its current work, in this case, we handle the role's response message as usual.
|
||||
self.direct_chat_roles.add(user_defined_recipient)
|
||||
|
||||
self._publish_message(message)
|
||||
self.direct_chat_roles.add(user_defined_recipient)
|
||||
# # bypass team leader, team leader only needs to know but not to react (commented out because TL doesn't understand the message well in actual experiments)
|
||||
# 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
|
||||
# NOTE: This is a temp rule to handle direct chat messages and has the following pitfalls:
|
||||
# If human chats with a role directly when the role is undertaking a task assigned by TL, the rule prevents TL from processing the role's response, thus pausing global task progress.
|
||||
self.direct_chat_roles.remove(message.sent_from)
|
||||
|
||||
elif (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue