A minimalist, state-aware multi-agent orchestration framework for Python.
Swarm Kit sits between simple chat scripts and heavyweight agent frameworks. It provides shared state, tool execution, async support, database persistence hooks and a live dashboard. The core engine is short enough to read in one sitting.
The Agent Studio dashboard following a run: handoff → state update → tool call → reply.
from swarm_kit import Agent, Swarm
def lookup_order(order_id: str) -> str:
"""Look up the status of a customer's order."""
return {"ORD-123": "Shipped"}.get(order_id, "Order not found")
support = Agent(name="Support", instructions="Help customers with their orders.", tools=[lookup_order])
result = Swarm(agents=[support]).execute("Support", "Where is ORD-123?")
print(result.final_output) # e.g. "Your order ORD-123 has shipped."
async functions both work.require_approval and decide each call
with an approval_handler (sync or async).execute_async() is safe to call from FastAPI and other asyncio servers.event_handler
callback, a JSONL event log, and the Agent Studio dashboard.pip install swarm-agent-kit
Put your API key in a .env file. It is loaded automatically:
OPENAI_API_KEY="sk-..."
Or run swarm-kit init my-project to generate a starter project.
from swarm_kit import Agent, Swarm
def process_refund(order_number: str) -> str:
"""Process a refund. Call this only once you have the order number."""
return f"Refund issued for {order_number}."
triage = Agent(
name="Triage",
description="Front desk that routes customers.",
instructions="Find out what the user needs. Refunds go to 'Billing'.",
)
billing = Agent(
name="Billing",
description="Handles refunds.",
instructions="Issue refunds with process_refund, then confirm to the user.",
tools=[process_refund],
model="gpt-4o-mini",
)
swarm = Swarm(agents=[triage, billing])
result = swarm.execute("Triage", "I want a refund for INV-992")
print(result.last_agent, result.final_output, result.state)
swarm = Swarm(agents=[researcher, copywriter, editor])
result = swarm.execute_plan("Write a tweet about the Apollo 11 landing")
print(result.plan) # [{'agent_name': 'Researcher', 'task': ...}, ...]
print(result.final_output)
async def load(session_id):
data = await redis.get(session_id)
return (json.loads(data)["history"], json.loads(data)["state"]) if data else ([], {})
async def save(session_id, history, state):
await redis.set(session_id, json.dumps({"history": history, "state": state}))
swarm = Swarm(agents=[support], load_handler=load, save_handler=save, verbose=False, log_file=None)
@app.post("/chat")
async def chat(req: ChatRequest):
result = await swarm.execute_async("Support", req.message, session_id=req.user_id)
return {"reply": result.final_output}
swarm-kit studio # http://127.0.0.1:8000
The Studio is a live, local dashboard that shows each response, handoff, tool call and state change while your swarm runs.
The full guides and API reference are at moseleydev.github.io/swarm-kit:
Runnable examples are in examples/.
Contributions of any size are welcome, from typo fixes to new features, and first-time contributors are encouraged. 🎃 Hacktoberfest participants welcome!
good first issue or
help wanted.
Ideas include streaming, retries, token and cost tracking, persistence adapters, Studio
improvements and new examples.git clone https://github.com/moseleydev/swarm-kit && cd swarm-kit
uv sync --group dev && uv run pytest # no API key needed
Thanks to everyone who has contributed:
Please read our Code of Conduct. To report a vulnerability, see SECURITY.md.
If Swarm Kit is useful to you:
MIT © moseleydev