From c496b6b5f604cfa46e239b360bf6a2a743114536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Mon, 6 Nov 2023 22:38:43 +0800 Subject: [PATCH] feat: add default subscriptions to all Role --- metagpt/const.py | 1 + metagpt/roles/role.py | 4 ++++ metagpt/schema.py | 3 +++ 3 files changed, 8 insertions(+) diff --git a/metagpt/const.py b/metagpt/const.py index 7b8203bce..2ba875543 100644 --- a/metagpt/const.py +++ b/metagpt/const.py @@ -48,3 +48,4 @@ MESSAGE_ROUTE_FROM = "msg_from" MESSAGE_ROUTE_TO = "msg_to" MESSAGE_ROUTE_CAUSE_BY = "cause_by" MESSAGE_META_ROLE = "role" +MESSAGE_ROUTE_TO_ALL = "" diff --git a/metagpt/roles/role.py b/metagpt/roles/role.py index 9bbba2070..6e8c5e421 100644 --- a/metagpt/roles/role.py +++ b/metagpt/roles/role.py @@ -135,6 +135,10 @@ class Role: def _watch(self, actions: Iterable[Type[Action]]): """Listen to the corresponding behaviors""" tags = {get_class_name(t) for t in actions} + # Add default subscription tags for developers' direct use. + if self.name: + tags.add(self.name) + tags.add(get_object_name(self)) self.subscribe(tags) def subscribe(self, tags: Set[str]): diff --git a/metagpt/schema.py b/metagpt/schema.py index 39a62e706..fb8885614 100644 --- a/metagpt/schema.py +++ b/metagpt/schema.py @@ -22,6 +22,7 @@ from metagpt.const import ( MESSAGE_ROUTE_CAUSE_BY, MESSAGE_ROUTE_FROM, MESSAGE_ROUTE_TO, + MESSAGE_ROUTE_TO_ALL, ) from metagpt.logs import logger from metagpt.utils.common import any_to_str @@ -71,6 +72,8 @@ class Routes(BaseModel): if not to_tags: return True + if MESSAGE_ROUTE_TO_ALL in to_tags: + return True for k in tags: if k in to_tags: return True