Peer agents that hand work off to each other — no central coordinator.
mode: swarminorchestrations:— agents decide on their own when to pass the batonagents:list — all participating peersentry_name:— which agent receives the initial taskmax_handoffs:— safety cap on total agent-to-agent transfershandoff_to_agent— a tool strands injects into every swarm agent automatically
Unlike delegation (one boss calls sub-agents), a swarm has no fixed director. Each agent decides autonomously when to hand off to a peer:
drafter ──handoff──▶ reviewer ──handoff──▶ drafter (if revisions needed)
└──handoff──▶ tech_lead (when approved)
strands injects a handoff_to_agent(agent_name, context) tool into every swarm agent.
When an agent calls it, execution transfers to the named peer with full context.
orchestrations:
review_team:
mode: swarm
agents: [drafter, reviewer, tech_lead]
entry_name: drafter
max_handoffs: 10Swarm vs Delegate. Use swarm when agents need to collaborate back-and-forth (e.g. drafting + reviewing cycles). Use delegate when there's a clear hierarchy and fixed flow.
max_handoffs prevents infinite loops. If agents keep handing off without
converging, the swarm stops after max_handoffs transfers.
Swarm agents can't have a session manager. If you have a global session_manager:,
any agent used in a swarm must opt out with session_manager: ~. This is a strands
limitation — may be lifted in the future.
- AWS credentials configured (
aws configureor environment variables) - Dependencies installed:
uv sync
uv run python examples/08_swarm/main.pyWrite and review a Python function that validates an email address.Create and review a function that merges two sorted lists.Write a utility that parses a simple key=value config file.
Strands agents log actions to the console through their default callback_handler.
If you want cleaner example output, set the handler to null in agent_kwargs for any agent:
agents:
my_agent:
agent_kwargs:
callback_handler: null # or ~