OpenAI Swarm
Type: full-code · Vendor: OpenAI · Language: Python · License: MIT · Status: deprecated · Status in practice: deprecated · First released: 2024-10-10 · Successor: OpenAI Agents SDK
Explore an ergonomic, minimal model of multi-agent orchestration where agents are functions, control transfer is just returning another Agent from a tool, and a single client.run() drives the whole loop.
Description. OpenAI Swarm is an MIT-licensed educational framework (not for production) from the OpenAI Solution team. Its API has two primitives: an Agent (name, model, instructions, functions, tool_choice) and a handoff that happens when a function returns another Agent. context_variables flow through every call and can be updated via a Result return. The library is no longer recommended for new code; the README states 'Swarm is now replaced by the OpenAI Agents SDK, which is a production-ready evolution of Swarm. We recommend migrating to the Agents SDK for all production use cases.'
Agent loop shape. Single client.run() loop, analogous to chat.completions.create(). On each turn the current Agent is called, any tool functions execute; if a function returns an Agent, the runner swaps current_agent and continues; if it returns a Result, context_variables update. The loop terminates when the agent produces a plain message with no further handoff or tool call.
Primary use cases
- studying minimal multi-agent orchestration as a teaching reference
- small experimental routines where agents transfer control by returning each other
- porting designs into the OpenAI Agents SDK
Key concepts
- Agent → tool-use (docs) — Bundle of name, model, instructions (string or callable), functions, tool_choice. The unit of behaviour.
- Handoff via function return → handoff (docs) — Returning another Agent from a function transfers control to that Agent for the next turn.
- context_variables (docs) — Dict-shaped state passed into instructions and functions; persists across handoffs and can be updated via a Result return.
- client.run() (docs) — Single-entry runner that drives the loop, analogous to chat.completions.create.
Patterns this full-code implements —
- ★Handoff
Handoff is the framework's defining primitive: an Agent transfers control by being returned from a function call. There is no router, no graph, no scheduler.
- ★★Tool Use
Functions are Python callables on the Agent; type hints and docstrings generate the schema. Functions can also read context_variables and return either a string result or a new Agent (handoff) or a R…
- ★★Supervisor
There is no dedicated supervisor primitive: any Agent can become the supervisor by routing other Agents through its functions. The triage_agent example demonstrates a supervisor by handoff. The patte…
- ★★Structured Output
Swarm has no Pydantic output_type or response_model; the README documents only two primitive abstractions (Agents and handoffs), and structured output is only available through tool/function call sig…
Neighbourhood
Click any neighbour to follow the lineage. Scroll to zoom, drag to pan.