Swarm
Swarm is an experimental, educational Python framework for coordinating and executing multi-agent systems. It solves the problem of building complex agent networks by providing lightweight primitives for agent handoffs and function calling. It is intended for developers curious about multi-agent orchestration, not for production use.
✨ Key features
- Lightweight agent coordination and execution
- Agent handoffs via function returns
- Context variables for shared state
- Function calling with automatic JSON schema
- Streaming responses support
- Stateless between calls, like Chat Completions API
🎯 Use cases
- Build multi-agent customer service bots
- Create triage systems that route to specialized agents
- Implement personal shopping assistants
- Explore multi-agent orchestration patterns for learning
📦 Installation
🧰 Requirements: Requires Python 3.10+ and an OpenAI API key.
pip install git+ssh://git@github.com/openai/swarm.git
or
pip install git+https://github.com/openai/swarm.git
🚀 Usage
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"])
⚠️ Good to know
Swarm is experimental and educational, and has been replaced by the OpenAI Agents SDK for production use; it is stateless between calls and not related to the Assistants API.
❓ FAQ
Is Swarm production-ready?
No, Swarm is experimental and educational. It has been replaced by the OpenAI Agents SDK, which is production-ready and actively maintained.
How does Swarm differ from the Assistants API?
Swarm is entirely powered by the Chat Completions API and is stateless between calls, whereas the Assistants API offers fully-hosted threads and built-in memory management.
Can an agent hand off to another agent?
Yes, an agent can hand off to another agent by returning it from a function. The last handoff function is used if multiple are called.
How can I pass context variables to functions?
Define a function with a context_variables parameter, and it will be populated with the context variables passed to client.run().
📊 Repository
🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.