Overview
OpenAI Swarm is an experimental, educational Python framework for building systems where several agents work together. Each Agent has its own instructions and a set of functions (tools), and an agent can hand off the conversation to another agent at any point. Swarm is built around two ideas: agents and handoffs.
It is aimed at developers who want to learn how multi-agent orchestration works rather than ship production systems. Swarm runs almost entirely on the client and, like the Chat Completions API it is built on, keeps no state between calls. The OpenAI team now recommends the OpenAI Agents SDK for production use, with Swarm serving as a learning resource.
Within the multi-agent space, Swarm keeps coordination and execution lightweight, controllable, and testable. It suits cases with many independent capabilities and instructions that are hard to fit into a single prompt, letting you split that logic across focused agents that pass work between each other.
What it does
- Two core primitives: Agents (instructions plus functions) and handoffs between them
- A handoff happens when an agent function returns another Agent, redirecting the conversation
- Stateless client.run() loop that handles completions, tool calls, and agent switching in one call
- Context variables passed through run() are available to functions and agent instructions
- Built directly on the Chat Completions API, so no hosted threads or server-side state
- Runnable examples in /examples (basic, triage_agent, weather_agent, airline, support_bot, personal_shopper)
Getting started
Swarm requires Python 3.10+ and installs straight from the GitHub repo. After installing, you create agents and run a conversation with client.run().
Install Swarm
Install the package directly from the GitHub repository using pip.
pip install git+https://github.com/openai/swarm.gitDefine agents and run a handoff
Create two agents and give the first a function that returns the second. When the model calls that function, Swarm hands the conversation off to Agent B.
from swarm import Swarm, Agent
client = Swarm()
def transfer_to_agent_b():
return agent_b
agent_a = Agent(
name="Agent A",
instructions="You are a helpful agent.",
functions=[transfer_to_agent_b],
)
agent_b = Agent(
name="Agent B",
instructions="Only speak in Haikus.",
)
response = client.run(
agent=agent_a,
messages=[{"role": "user", "content": "I want to talk to agent B."}],
)
print(response.messages[-1]["content"])Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Learning how multi-agent orchestration and handoffs work before moving to a production SDK
- Building a triage step that routes a request to the right specialized agent
- Splitting many independent instructions and capabilities across focused agents instead of one large prompt
- Prototyping customer-service flows, such as support or shopping bots, with several cooperating agents
How OpenAI Swarm compares
OpenAI Swarm alongside other open-source multi-agent systems tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| MetaGPT | ★ 68.9k | A multi-agent framework that models a software company, assigning roles like product manager, architect, and engineer to generate code from a single prompt. |
| AutoGen | ★ 59.1k | Microsoft Research's framework for building applications where multiple agents converse with each other and with tools to solve tasks. |
| CrewAI | ★ 54k | A framework for assembling teams ('crews') of role-playing agents that divide tasks and collaborate to complete a goal. |
| OpenAI Agents SDK | ★ 27.3k | OpenAI's lightweight Python SDK for building multi-agent workflows using explicit handoffs, tools, and guardrails. |
| AgentScope | ★ 27k | A framework for building multi-agent applications with message passing, visual debugging tools, and distributed execution. |
| OpenAI Swarm | ★ 21.7k | A lightweight, educational framework for multi-agent coordination through handoffs |
| PentAGI | ★ 17.8k | PentAGI is a self-hosted AI security platform that plans and runs penetration tests autonomously using a team of agents and 20+ built-in pentesting tools. |
| CAMEL | ★ 17.2k | A research-oriented framework for studying and building communicating agents that cooperate through role-playing conversations. |