# OpenAI Swarm

> A lightweight, educational framework for multi-agent coordination through handoffs

- Category: Agents & Automation / Multi-Agent Systems
- Language: Python
- Repository: https://github.com/openai/swarm
- Canonical page: https://ai-tldr.dev/tools/openai-swarm/

## In short

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. It sits in the Multi-Agent Systems category of the Agents & Automation tools and is open-source, written in Python.

## 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().

1. Install Swarm

   Install the package directly from the GitHub repository using pip.

```bash
pip install git+https://github.com/openai/swarm.git
```

2. Define 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.

```python
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"])
```

## 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
