ScriptsMar 31, 2026·1 min read

OpenAI Swarm — Lightweight Multi-Agent Orchestration

Educational multi-agent framework by OpenAI. Ergonomic agent handoffs, tool calling, and context variables. Minimal abstraction over Chat Completions API. 21K+ stars.

TO
TokRepo精选 · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

pip install git+https://github.com/openai/swarm.git
from swarm import Swarm, Agent

client = Swarm()

def transfer_to_sales():
    return sales_agent

triage = Agent(name="Triage", instructions="Route to sales or support.",
               functions=[transfer_to_sales])
sales_agent = Agent(name="Sales", instructions="Handle sales inquiries.")

response = client.run(agent=triage,
    messages=[{"role": "user", "content": "I want to buy your product"}])
print(response.messages[-1]["content"])

Intro

Swarm is an educational multi-agent orchestration framework by OpenAI. It explores lightweight, ergonomic patterns for agent handoffs, tool calling, and context variables — with minimal abstraction over the Chat Completions API. Designed to teach multi-agent patterns, not as a production framework. 21,000+ GitHub stars, MIT licensed.

Best for: Learning multi-agent patterns, prototyping agent handoff workflows, understanding OpenAI's agent design philosophy Works with: OpenAI API (GPT-4o, GPT-4, GPT-3.5)


Core Concepts

Agents

Agents are instructions + functions. Simple and composable:

agent = Agent(
    name="Support",
    instructions="You handle customer support.",
    functions=[lookup_order, check_status, escalate],
)

Handoffs

Agents transfer control by returning another agent:

def transfer_to_billing():
    return billing_agent  # Control passes to billing

Context Variables

Share state across agents without global variables:

response = client.run(agent=triage,
    messages=[...],
    context_variables={"user_id": "123", "plan": "premium"})

Routines

Multi-step procedures encoded as agent instructions — like a playbook for the agent to follow.


FAQ

Q: What is OpenAI Swarm? A: An educational framework by OpenAI exploring lightweight multi-agent orchestration with handoffs, tool calling, and context variables. 21K+ stars, MIT licensed.

Q: Should I use Swarm in production? A: OpenAI explicitly states Swarm is educational, not a production framework. For production, consider OpenAI Agents SDK, LangGraph, or CrewAI.


🙏

Source & Thanks

Created by OpenAI. Licensed under MIT. openai/swarm — 21,000+ GitHub stars

Related Assets