Skip to content

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

fixbug: creation of separate indices for each label

莘权 马8137e1af5018
diff --git a/metagpt/memory/memory.py b/metagpt/memory/memory.py
index 7f04be63d..cf3140bdb 100644
--- a/metagpt/memory/memory.py
+++ b/metagpt/memory/memory.py
@@ -26,8 +26,10 @@ class Memory:
if message in self.storage:
return
self.storage.append(message)
- if message.cause_by:
- self.index[message.cause_by].append(message)
+ # According to the design of RFC 116, it allows message filtering based on different labels, thus
+ # necessitating the creation of separate indices for each label.
+ for k in message.tx_to:
+ self.index[k].append(message)
def add_batch(self, messages: Iterable[Message]):
for message in messages:
diff --git a/tests/metagpt/test_role.py b/tests/metagpt/test_role.py
index f0ef4b3d9..829f75bc5 100644
--- a/tests/metagpt/test_role.py
+++ b/tests/metagpt/test_role.py
@@ -64,6 +64,11 @@ async def test_react():
assert role.is_idle
env = Environment()
env.add_role(role)
+ env.publish_message(Message(content="test", tx_to=seed.subscription))
+ assert not role.is_idle
+ while not env.is_idle:
+ await env.run()
+ assert role.is_idle
env.publish_message(Message(content="test", cause_by=seed.subscription))
assert not role.is_idle
while not env.is_idle: