Swarm
Peer agents pass control via a handoff tool. OpenAI Swarm reference
(late 2024, experimental). Anthropic Agent Teams (Feb 2026) is the
production answer that improved on the original swarm idea by adding
lightweight coordination.
Production warning. The 2026 production literature is unanimous: swarm has goal-drift and deadlock failure modes that hierarchical / graph topologies don’t. Use only for exploratory or research-mode systems where flow can’t be pre-specified. For production, prefer Supervisor (clear authority) or Router (single specialist owns the answer).
prompt ──► agent A
│
│ handoff(B, payload)
▼
agent B
│
│ transfer_to_C(typed_args)
▼
agent C ──► final output
▲
│ cycle detection: A→B→A→B kills the loop
│ max_handoffs caps total depthPattern
- Setup. N peer
Agentinstances; one designated as the entry agent (receives the first user message). - Active turn. The active agent runs to completion with one or more handoff tools injected. The model can call them (or not) freely during the turn.
- Detect handoff. After the agent’s turn ends, Swarm checks whether a handoff tool was called. If yes, switch active agent to the named target.
- Loop or terminate. Continue handoffs until either: (a) an
agent finishes without calling a handoff tool, (b)
max_handoffsreached, or (c) cycle detected.
Two handoff styles
from loomflow import Agent
from loomflow.architecture import Handoff
from loomflow.team import Team
triage = Agent("Triage incoming requests.", model="claude-opus-4-7")
billing = Agent("Handle billing.", model="claude-opus-4-7", tools=[...])
tech = Agent("Handle technical issues.", model="claude-opus-4-7", tools=[...])
# Style 1: a single generic ``handoff(name, payload)`` tool
team = Team.swarm(
agents={"triage": triage, "billing": billing, "tech": tech},
entry_agent="triage",
model="claude-opus-4-7",
)
# Style 2: typed handoffs — wrap each peer in ``Handoff`` so you get
# per-target ``transfer_to_<name>`` tools with structured arguments
team = Team.swarm(
agents={
"triage": triage,
"billing": Handoff(billing, input_type=BillingHandoff),
"tech": Handoff(tech, input_type=TechHandoff),
},
entry_agent="triage",
model="claude-opus-4-7",
)input_type= is a Pydantic model. The handoff tool’s schema is
derived from it, so the model emits structured payloads instead of
free-form strings.
Cycle detection
Swarm tracks the handoff sequence per run. A repeating chain
(A→B→A→B) trips cycle detection and terminates the run with
interrupted=True, interruption_reason="swarm_cycle". Disable
with cycle_detection=False if you genuinely want long handoff
sequences.
When (sparingly) to use Swarm
- Exploratory pipelines where the flow shape will change weekly.
- Research-mode systems where you’re testing what handoff patterns emerge.
For production multi-agent: use Supervisor or Router.