Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

refactor: According to RFC 113, add message dispatching functionality.

莘权 马47d47d274e5d
diff --git a/metagpt/environment.py b/metagpt/environment.py
index fb564e1ab..81b5c2ac7 100644
--- a/metagpt/environment.py
+++ b/metagpt/environment.py
@@ -19,6 +19,7 @@ from pydantic import BaseModel, Field
from metagpt.logs import logger
from metagpt.roles import Role
from metagpt.schema import Message
+from metagpt.utils.common import is_subscribed
class Environment(BaseModel):
@@ -63,7 +64,7 @@ class Environment(BaseModel):
found = False
# According to the routing feature plan in Chapter 2.2.3.2 of RFC 113
for obj, subscribed_tags in self.consumers.items():
- if message.contain_any(subscribed_tags):
+ if is_subscribed(message, subscribed_tags):
obj.put_message(message)
found = True
if not found:
diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py
index cd42b1412..798acf214 100644
--- a/metagpt/utils/common.py
+++ b/metagpt/utils/common.py
@@ -15,6 +15,7 @@ import platform
import re
from typing import List, Tuple, Union
+from metagpt.const import MESSAGE_ROUTE_TO_ALL
from metagpt.logs import logger
@@ -336,3 +337,14 @@ def any_to_str_set(val) -> set:
else:
res.add(any_to_str(val))
return res
+
+
+def is_subscribed(message, tags):
+ """Return whether it's consumer"""
+ if MESSAGE_ROUTE_TO_ALL in message.send_to:
+ return True
+
+ for t in tags:
+ if t in message.send_to:
+ return True
+ return False