agentscope.msghub module

MsgHub is designed to share messages among a group of agents.

class agentscope.msghub.MsgHubManager(participants: Sequence[AgentBase], announcement: Sequence[Msg] | Msg | None = None)[source]

Bases: object

MsgHub manager class for sharing dialog among a group of agents.

__init__(participants: Sequence[AgentBase], announcement: Sequence[Msg] | Msg | None = None) None[source]

Initialize a msghub manager from the given arguments.

Parameters:
  • participants (Sequence[AgentBase]) – The Sequence of participants in the msghub.

  • announcement – (Optional[Union[list[Msg], Msg]], defaults to None): The message that will be broadcast to all participants at the first without requiring response.

add(new_participant: Sequence[AgentBase] | AgentBase) None[source]

Add new participant into this hub

delete(participant: Sequence[AgentBase] | AgentBase) None[source]

Delete agents from participant.

broadcast(msg: Msg | Sequence[Msg]) None[source]

Broadcast the message to all participants.

Parameters:

msg (Union[Msg, Sequence[Msg]]) – One or a list of dict messages to broadcast among all participants.

agentscope.msghub.msghub(participants: Sequence[AgentBase], announcement: Sequence[Msg] | Msg | None = None) MsgHubManager[source]

msghub is used to share messages among a group of agents.

Parameters:
  • participants (Sequence[AgentBase]) – A Sequence of participated agents in the msghub.

  • announcement (Optional[Union[list[Msg], Msg]], defaults to None) – The message that will be broadcast to all participants at the very beginning without requiring response.

Example

In the following code, we create a msghub with three agents, and each message output by agent1, agent2, agent3 will be passed to all other agents, that’s what we mean msghub.

with msghub(participant=[agent1, agent2, agent3]):
    agent1()
    agent2()

Actually, it has the same effect as the following code, but much more easy and elegant!

x1 = agent1()
agent2.observe(x1)
agent3.observe(x1)

x2 = agent2()
agent1.observe(x2)
agent3.observe(x2)