more confilt resolutions

This commit is contained in:
brucemeek 2023-08-09 14:47:28 -05:00
parent 6eb4d26224
commit 0ad84a4d42
7 changed files with 100 additions and 69 deletions

View file

@ -16,7 +16,10 @@ from metagpt.schema import Message
class Environment(BaseModel):
"""Environment that carries a set of roles. Roles can publish messages to the environment, which can be observed by other roles."""
"""环境,承载一批角色,角色可以向环境发布消息,可以被其他角色观察到
Environment, hosting a batch of roles, roles can publish messages to the environment, and can be observed by other roles
"""
roles: dict[str, Role] = Field(default_factory=dict)
memory: Memory = Field(default_factory=Memory)
@ -26,23 +29,31 @@ class Environment(BaseModel):
arbitrary_types_allowed = True
def add_role(self, role: Role):
"""Add a Role to the current environment."""
"""增加一个在当前环境的角色
Add a role in the current environment
"""
role.set_env(self)
self.roles[role.profile] = role
def add_roles(self, roles: Iterable[Role]):
"""Add a batch of Roles to the current environment."""
"""增加一批在当前环境的角色
Add a batch of characters in the current environment
"""
for role in roles:
self.add_role(role)
def publish_message(self, message: Message):
"""Publish a message to the current environment."""
# self.message_queue.put(message)
"""向当前环境发布信息
Post information to the current environment
"""
# self.message_queue.put(message)
self.memory.add(message)
self.history += f"\n{message}"
async def run(self, k=1):
"""Process the run of all Roles once."""
"""处理一次所有信息的运行
Process all Role runs at once
"""
# while not self.message_queue.empty():
# message = self.message_queue.get()
# rsp = await self.manager.handle(message, self)
@ -56,9 +67,13 @@ class Environment(BaseModel):
await asyncio.gather(*futures)
def get_roles(self) -> dict[str, Role]:
"""Get all Roles within the environment."""
"""获得环境内的所有角色
Process all Role runs at once
"""
return self.roles
def get_role(self, name: str) -> Role:
"""Get a specified Role within the environment."""
"""获得环境内的指定角色
get all the environment roles
"""
return self.roles.get(name, None)