🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
optimize direct chat logic
garylin20992083233d413b
diff --git a/metagpt/environment/base_env.py b/metagpt/environment/base_env.pyindex 5d6d3a286..0776ae9ff 100644--- a/metagpt/environment/base_env.py+++ b/metagpt/environment/base_env.py@@ -159,7 +159,7 @@ class Environment(ExtEnv):"""增加一个在当前环境的角色Add a role in the current environment"""- self.roles[role.profile] = role+ self.roles[role.name] = rolerole.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] = rolefor role in roles: # setup system message with rolesrole.context = self.contextdiff --git a/metagpt/environment/mgx/mgx_env.py b/metagpt/environment/mgx/mgx_env.pyindex 97bca6b8c..ab515e070 100644--- a/metagpt/environment/mgx/mgx_env.py+++ b/metagpt/environment/mgx/mgx_env.py@@ -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 Timif 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 (