Open nkrj01 opened 4 months ago
looks like message is still observed even if cause_by is set to type(todo). Can @iorisa check this?
I think in current implementation of publish_message does not take care of role watch actions.
As in metagpt/environment/base_env.py#L187
for role, addrs in self.member_addrs.items():
if is_send_to(message, addrs):
role.put_message(message)
found = True
It should be
for role, addrs in self.member_addrs.items():
if is_send_to(message, addrs) and role.is_watch(message.cause_by):
role.put_message(message)
found = True
Create this pull request: https://github.com/geekan/MetaGPT/pull/1314
PS: I am a bit new, I don't know if it will break other examples or not.
Bug description When I put two agents (AgentA and AgentB) in an environment, AgentB is automatically picks up the published message of AgentA even though _watch function is not set to AgentAAction.
AgentAAction: take a string and publish one letter at a time AgentBAction: given any string simple add the word "Add"
There is no LLM functionality here.
Code is shown below:
Defining AgentA
from metagpt.actions import Action, UserRequirement from metagpt.roles import Role from metagpt.logs import logger from metagpt.schema import Message
class AgentAAction(Action): name: str = "AgentAAction"
class AgentA(Role): name: str = "AgentA" profile: str = "AgentA"
Defining AgentB
class AgentBAction(Action): name: str = "AgentBAction"
class AgentB(Role): name: str = "AgentB" profile: str = "AgentB"
from metagpt.context import Context import asyncio from metagpt.environment import Environment
agentA = AgentA() agentB = AgentB() context = Context() # Load config2.yaml env = Environment(context=context) env.add_roles([agentA, agentB]) env.publish_message(Message(content='APPLE', send_to=AgentA)) env.publish_message(Message(content='CAT', send_to=AgentB)) # Send the user's message to Agent A to start the process. await env.run()
print all the messages in the memory of agentB
for index, memory in enumerate(agentB.get_memories(k=0)): print(f'{index}: {memory}')
Output: 0: user: CAT 1: AgentA: A 2: AgentA: P 3: AgentA: P 4: AgentA: L 5: AgentA: E 6: AgentB: CATAdd 7: AgentB: AAdd 8: AgentB: PAdd 9: AgentB: PAdd 10: AgentB: LAdd 11: AgentB: EAdd
Ideally the output should just be: 0: user: CAT 1: user: CATadd
Bug solved method
Environment information
Windows 12
Screenshots or logs