feat: able to send to multiple receivers
ref: N25B-441
This commit is contained in:
@@ -130,16 +130,21 @@ class BaseAgent(ABC):
|
||||
|
||||
:param message: The message to send.
|
||||
"""
|
||||
target = AgentDirectory.get(message.to)
|
||||
if target:
|
||||
await target.inbox.put(message)
|
||||
self.logger.debug(f"Sent message {message.body} to {message.to} via regular inbox.")
|
||||
else:
|
||||
# Apparently target agent is on a different process, send via ZMQ
|
||||
topic = f"internal/{message.to}".encode()
|
||||
body = message.model_dump_json().encode()
|
||||
await self._internal_pub_socket.send_multipart([topic, body])
|
||||
self.logger.debug(f"Sent message {message.body} to {message.to} via ZMQ.")
|
||||
to = message.to
|
||||
receivers = [to] if isinstance(to, str) else to
|
||||
|
||||
for receiver in receivers:
|
||||
target = AgentDirectory.get(receiver)
|
||||
|
||||
if target:
|
||||
await target.inbox.put(message)
|
||||
self.logger.debug(f"Sent message {message.body} to {message.to} via regular inbox.")
|
||||
else:
|
||||
# Apparently target agent is on a different process, send via ZMQ
|
||||
topic = f"internal/{message.to}".encode()
|
||||
body = message.model_dump_json().encode()
|
||||
await self._internal_pub_socket.send_multipart([topic, body])
|
||||
self.logger.debug(f"Sent message {message.body} to {message.to} via ZMQ.")
|
||||
|
||||
async def _process_inbox(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user