🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
feat: merge geekan:env_factor
莘权 马fb2167cccff7
diff --cc metagpt/environment.pyindex b3c296dac,2e2aa152a..02eb3d340--- a/metagpt/environment.py+++ b/metagpt/environment.py@@@ -29,8 -22,8 +29,8 @@@ class Environment(BaseModel)"""roles: dict[str, Role] = Field(default_factory=dict)- consumers: dict[Role, Set] = Field(default_factory=dict)- memory: Memory = Field(default_factory=Memory)- history: str = Field(default="")++ members: dict[Role, Set] = Field(default_factory=dict)+ history: str = Field(default="") # For debugclass Config:arbitrary_types_allowed = True@@@ -49,27 -42,13 +49,27 @@@for role in roles:self.add_role(role)- def publish_message(self, message: Message):- """向当前环境发布信息- Post information to the current environment+ def publish_message(self, message: Message) -> bool:"""- # self.message_queue.put(message)- self.memory.add(message)- self.history += f"\n{message}"+ Distribute the message to the recipients.+ In accordance with the Message routing structure design in Chapter 2.2.1 of RFC 116, as already planned+ in RFC 113 for the entire system, the routing information in the Message is only responsible for+ specifying the message recipient, without concern for where the message recipient is located. How to+ route the message to the message recipient is a problem addressed by the transport framework designed+ in RFC 113.+ """+ logger.info(f"publish_message: {message.dump()}")+ found = False+ # According to the routing feature plan in Chapter 2.2.3.2 of RFC 113- for role, subscription in self.consumers.items():++ for role, subscription in self.members.items():+ if is_subscribed(message, subscription):+ role.put_message(message)+ found = True+ if not found:+ logger.warning(f"Message no recipients: {message.dump()}")+ self.history += f"\n{message}" # For debug++ return Trueasync def run(self, k=1):"""处理一次所有信息的运行@@@ -95,19 -77,3 +95,19 @@@get all the environment roles"""return self.roles.get(name, None)++ @property+ def is_idle(self):+ """If true, all actions have been executed."""+ for r in self.roles.values():+ if not r.is_idle:+ return False+ return True++ def get_subscription(self, obj):+ """Get the labels for messages to be consumed by the object."""- return self.consumers.get(obj, {})++ return self.members.get(obj, {})++ def set_subscription(self, obj, tags):+ """Set the labels for message to be consumed by the object"""- self.consumers[obj] = tags++ self.members[obj] = tags