Swarm
Swarms provide controllable flows between agents that are determined at the agent-level. You define hand-off, post-tool, and post-work transitions from an agent to another agent (or to end the swarm).
When designing your swarm, think about your agents in a diagram with the lines between agents being your hand-offs. Each line will have a condition statement which an LLM will evaluate. Control stays with an agent while they execute their tools and once they’ve finished with their tools the conditions to transition will be evaluated.
One of the unique aspects of a swarm is a shared context. ConversableAgents have a context dictionary but in a swarm that context is made common across all agents, allowing a state of the workflow to be maintained and viewed by all agents. This context can also be used within the hand off condition statements, providing more control of transitions.
AG2’s swarm has a number of unique capabilities, find out more in our Swarm deep-dive.
Here’s our lesson planner workflow using AG2’s Swarm.
-
Our shared context, available in function calls and on agents.
-
Functions that represent the work the agents carry out, these the update shared context and, optionally, managed transitions.
-
Agents setup with their tools,
functions
, and a system message and LLM configuration. -
The important hand-offs, defining the conditions for which to transfer to other agents and what to do after their work is finished (equivalent to no longer calling tools). Transfer conditions can be turned on/off using the
available
parameter. -
Kick off the swarm with our agents and shared context. Similar to
initiate_chat
,initiate_swarm_chat
returns the chat result (messages and summary) and the final shared context.