> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ag2.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# autogen.agentchat.contrib.swarm_agent.create_swarm_transition

<code class="doc-symbol doc-symbol-heading doc-symbol-function" />

#### create\_swarm\_transition

```python theme={null}
create_swarm_transition(
    initial_agent: ConversableAgent,
    tool_execution: ConversableAgent,
    swarm_agent_names: list[str],
    user_agent: UserProxyAgent | None,
    swarm_after_work: AfterWorkOption | Callable[..., Any] | None
) -> Callable[[ConversableAgent, GroupChat], Agent | Literal['auto'] | None]
```

Creates a transition function for swarm chat with enclosed state for the use\_initial\_agent.<br />

<b>Parameters:</b>

| Name                | Description                                                                                                                               |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `initial_agent`     | The first agent to speak<br /><br />**Type:** [ConversableAgent](/docs/api-reference/autogen/ConversableAgent)                            |
| `tool_execution`    | The tool execution agent<br /><br />**Type:** [ConversableAgent](/docs/api-reference/autogen/ConversableAgent)                            |
| `swarm_agent_names` | List of all agent names<br /><br />**Type:** list\[str]                                                                                   |
| `user_agent`        | Optional user proxy agent<br /><br />**Type:** [UserProxyAgent](/docs/api-reference/autogen/UserProxyAgent) \| None                       |
| `swarm_after_work`  | Swarm-level after work<br /><br />**Type:** [AfterWorkOption](/docs/api-reference/autogen/AfterWorkOption) \| Callable\[..., Any] \| None |

<b>Returns:</b>

| Type                                                                                                                                                                                                       | Description                                                   |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| Callable\[\[[ConversableAgent](/docs/api-reference/autogen/ConversableAgent), [GroupChat](/docs/api-reference/autogen/GroupChat)], [Agent](/docs/api-reference/autogen/Agent) \| Literal\['auto'] \| None] | Callable transition function (for sync and async swarm chats) |

<br />
