Scripts2026年3月31日·1 分钟阅读

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
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

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

介绍

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.


🙏

来源与感谢

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

相关资产