# a_initiate_group_chat

## ``autogen.agentchat.a_initiate_group_chat`async`[

```
a_initiate_group_chat(pattern, messages, max_rounds=20, safeguard_policy=None, safeguard_llm_config=None, mask_llm_config=None)
```

Initialize and run a group chat using a pattern for configuration, asynchronously.

| PARAMETER                | DESCRIPTION                                                                                     |
|--------------------------|-------------------------------------------------------------------------------------------------|
| `pattern`                | Pattern object that encapsulates the chat configuration.<br>**TYPE:**`Pattern`                  |
| `messages`               | Initial message(s).<br>**TYPE:**`list[dict[str, Any]] | str`                                |
| `max_rounds`            | Maximum number of conversation rounds.<br>**TYPE:**`int`**DEFAULT:**`20`                       |
| `safeguard_policy`      | Optional safeguard policy dict or path to JSON file.<br>**TYPE:**`dict[str, Any] | str | None`**DEFAULT:**`None` |
| `safeguard_llm_config`  | Optional LLM configuration for safeguard checks.<br>**TYPE:**`LLMConfig | None`**DEFAULT:**`None` |
| `mask_llm_config`       | Optional LLM configuration for masking.<br>**TYPE:**`LLMConfig | None`**DEFAULT:**`None`    |

| RETURNS                   | DESCRIPTION                                                                                     |
|---------------------------|-------------------------------------------------------------------------------------------------|
| `ChatResult`              | Conversations chat history.<br>**TYPE:**`ChatResult`                                          |
| `ContextVariables`        | Updated Context variables.<br>**TYPE:**`ContextVariables`                                     |
| `Agent`                   | "ConversableAgent": Last speaker.                                                              |

Source code in `autogen/agentchat/group/multi_agent_chat.py`

|     |     |
| --- | --- |
| ```<br>@export_module("autogen.agentchat")<br>async def a_initiate_group_chat(<br>    pattern: "Pattern",<br>    messages: list[dict[str, Any]] | str,<br>    max_rounds: int = 20,<br>    safeguard_policy: dict[str, Any] | str | None = None,<br>    safeguard_llm_config: LLMConfig | None = None,<br>    mask_llm_config: LLMConfig | None = None,<br>) -> tuple[ChatResult, ContextVariables, "Agent"]:<br>    """Initialize and run a group chat using a pattern for configuration, asynchronously.<br>    Args:<br>        pattern: Pattern object that encapsulates the chat configuration.<br>        messages: Initial message(s).<br>        max_rounds: Maximum number of conversation rounds.<br>        safeguard_policy: Optional safeguard policy dict or path to JSON file.<br>        safeguard_llm_config: Optional LLM configuration for safeguard checks.<br>        mask_llm_config: Optional LLM configuration for masking.<br>    Returns:<br>        ChatResult:         Conversations chat history.<br>        ContextVariables:   Updated Context variables.<br>        "ConversableAgent":   Last speaker.<br>    """<br>    # Let the pattern prepare the group chat and all its components<br>    # Only passing the necessary parameters that aren't already in the pattern<br>    (<br>        _,  # agents,<br>        _,  # wrapped_agents,<br>        _,  # user_agent,<br>        context_variables,<br>        _,  # initial_agent,<br>        _,  # group_after_work,<br>        _,  # tool_execution,<br>        _,  # groupchat,<br>        manager,<br>        processed_messages,<br>        last_agent,<br>        _,  # group_agent_names,<br>        _,  # temp_user_list,<br>    ) = pattern.prepare_group_chat(<br>        max_rounds=max_rounds,<br>        messages=messages,<br>    )<br>    # Apply safeguards if provided<br>    if safeguard_policy:<br>        from .safeguards import apply_safeguard_policy<br>        apply_safeguard_policy(<br>            groupchat_manager=manager,<br>            policy=safeguard_policy,<br>            safeguard_llm_config=safeguard_llm_config,<br>            mask_llm_config=mask_llm_config,<br>        )<br>    # Start or resume the conversation<br>    if len(processed_messages) > 1:<br>        last_agent, last_message = await manager.a_resume(messages=processed_messages)<br>        clear_history = False<br>    else:<br>        last_message = processed_messages[0]<br>        clear_history = True<br>    if last_agent is None:<br>        raise ValueError("No agent selected to start the conversation")<br>    chat_result = await last_agent.a_initiate_chat(<br>        manager,<br>        message=last_message,  # type: ignore[arg-type]<br>        clear_history=clear_history,<br>        summary_method=pattern.summary_method,<br>    )<br>    # Recalculate cost to include ALL agents in the group chat<br>    # initiate_chat only gathers cost from [sender, recipient],<br>    # but in group chat we need to include all participating agents<br>    all_agents = list(manager.groupchat.agents) + [manager]<br>    chat_result.cost = cast(CostDict, gather_usage_summary(all_agents))<br>    cleanup_temp_user_messages(chat_result)<br>    return chat_result, context_variables, manager.last_speaker<br>``` | ```  |
