🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
fix publish msg bug
yzlind8ede20235da
diff --git a/metagpt/roles/di/team_leader.py b/metagpt/roles/di/team_leader.pyindex 3f3a86f76..a24d85dc1 100644--- a/metagpt/roles/di/team_leader.py+++ b/metagpt/roles/di/team_leader.py@@ -8,7 +8,7 @@ from metagpt.environment.mgx.mgx_env import MGXEnvfrom metagpt.prompts.di.team_leader import CMD_PROMPT, prepare_command_promptfrom metagpt.roles import Rolefrom metagpt.schema import Message, Task, TaskResult-from metagpt.strategy.experience_retriever import SimplePlanningExpRetriever+from metagpt.strategy.experience_retriever import SimpleExpRetrieverfrom metagpt.strategy.planner import Plannerfrom metagpt.strategy.thinking_command import Commandfrom metagpt.utils.common import CodeParser@@ -37,7 +37,7 @@ class TeamLeader(Role):def _run_env_command(self, cmd):assert isinstance(self.rc.env, MGXEnv), "TeamLeader should only be used in an MGXEnv"if cmd["command_name"] == Command.PUBLISH_MESSAGE.cmd_name:- self.rc.env.publish_message(Message(sent_from=self.profile, **cmd["args"]), publicer=self.profile)+ self.publish_message(Message(sent_from=self.profile, **cmd["args"]))elif cmd["command_name"] == Command.ASK_HUMAN.cmd_name:self.rc.env.ask_human(**cmd["args"])elif cmd["command_name"] == Command.REPLY_TO_HUMAN.cmd_name:@@ -89,7 +89,7 @@ class TeamLeader(Role):if role.profile == "TeamLeader":continueteam_info += f"{role.name}: {role.profile}, {role.goal}\n"- example = SimplePlanningExpRetriever().retrieve()+ example = SimpleExpRetriever().retrieve()prompt = CMD_PROMPT.format(plan_status=plan_status,@@ -111,3 +111,12 @@ class TeamLeader(Role):self.run_commands(self.commands)self.task_result = TaskResult(result="Success", is_success=True)return Message(content="Commands executed", role="assistant")++ def publish_message(self, msg):+ """If the role belongs to env, then the role's messages will be broadcast to env"""+ if not msg:+ return+ if not self.rc.env:+ # If env does not exist, do not publish the message+ return+ self.rc.env.publish_message(msg, publicer=self.profile)