a_initiate_swarm_chat

a_initiate_swarm_chat(
    initial_agent: SwarmAgent,
    messages: list[dict[str, typing.Any]] | str,
    agents: list['SwarmAgent'],
    user_agent: autogen.UserProxyAgent | None = None,
    max_rounds: int = 20,
    context_variables: dict[str, typing.Any] | None = None,
    after_work: autogen.AfterWorkOption | Callable | None = AFTER_WORK(agent=<AfterWorkOption.TERMINATE: 'TERMINATE'>)
) -> tuple[autogen.ChatResult, dict[str, typing.Any], 'SwarmAgent']

Initialize and run a swarm chat asynchronously

Parameters:
NameDescription
initial_agentThe first receiving agent of the conversation.

Type: SwarmAgent
messagesInitial message(s).

Type: list[dict[str, typing.Any]] | str
agentsList of swarm agents.

Type: list['SwarmAgent']
user_agentOptional user proxy agent for falling back to.

Type: autogen.UserProxyAgent | None

Default: None
max_roundsMaximum number of conversation rounds.

Type: int

Default: 20
context_variablesStarting context variables.

Type: dict[str, typing.Any] | None

Default: None
after_workMethod to handle conversation continuation when an agent doesn’t select the next agent.

If no agent is selected and no tool calls are output, we will use this method to determine the next agent.

Must be a AFTER_WORK instance (which is a dataclass accepting a SwarmAgent, AfterWorkOption, A str (of the AfterWorkOption)) or a callable.

AfterWorkOption: - TERMINATE (Default): Terminate the conversation.

- REVERT_TO_USER : Revert to the user agent if a user agent is provided.

If not provided, terminate the conversation.

- STAY : Stay with the last speaker.

Callable: A custom function that takes the current agent, messages, and groupchat as arguments and returns an AfterWorkOption or a SwarmAgent (by reference or string name).

python def custom_afterwork_func(last_speaker: SwarmAgent, messages: List[Dict[str, Any]], groupchat: GroupChat) -> Union[AfterWorkOption, SwarmAgent, str]:

Type: autogen.AfterWorkOption | Callable | None = AFTER_WORK(agent

Default: <AfterWorkOption.TERMINATE
Returns:
TypeDescription
tuple[autogen.ChatResult, dict[str, typing.Any], 'SwarmAgent']ChatResult: Conversations chat history. Dict[str, Any]: Updated Context variables. SwarmAgent: Last speaker.