GenAIHub
Back to Technical Section

OpenAI Swarm

Experimental & Lightweight Multi-Agent Orchestration

What is Swarm?

Swarm is an experimental framework from OpenAI that explores ergonomic, lightweight multi-agent orchestration. It is designed to be stateless, highly controllable, and easy to test.

The primary goal of Swarm is to showcase the Handoffs and Routines patterns, allowing developers to build complex workflows by coordinating multiple specialized agents.

Experimental
Lightweight
# Install via pip
pip install git+ssh://git@github.com/openai/swarm.git

Core Abstractions

The Agent

An Agent encapsulates instructions and tools. Unlike the Assistants API, Swarm Agents are stateless and client-side, giving you total control over the context.

  • Custom Instructions
  • Function Call Support

Handoffs

Handoffs allow an agent to "transfer" the conversation to another agent by simply returning the destination Agent object from a function.

  • Dynamic Routing
  • Clean Separation of Concerns

Simple Handoff Example

from swarm import Swarm, Agent

client = Swarm()

agent_b = Agent(
    name="Agent B",
    instructions="Only speak in Portuguese.",
)

def transfer_to_agent_b():
    return agent_b

agent_a = Agent(
    name="Agent A",
    instructions="You are a helpful assistant.",
    functions=[transfer_to_agent_b],
)

response = client.run(
    agent=agent_a,
    messages=[{"role": "user", "content": "Transfira para o Agente B"}],
)

print(response.messages[-1]["content"])

When to Choose Swarm?

Swarm is ideal for prototypes and educational purposes where **full observability** and **low overhead** are more important than production-scale durability. It provides an excellent template for building custom "triage" systems where a root agent routes user intent to specialized sub-agents.

Official Repository

Explore the source code and official examples directly from OpenAI.

View on GitHub

Important Note

Swarm is currently an **experimental educational tool**. For production-ready applications, OpenAI recommends looking into the latest Assistants API features or the new OpenAI Agents SDK, which provide robust state management and scalability.

Explore Multi-Agent Alternatives