Create ConversableAgent instances for each specialist, providing name, system_message, and llm_config
Define a context_variables dict with initial shared state (e.g. {'order_status': 'pending'})
Set handoff conditions using OnContextCondition, pointing to a target agent when a context variable matches a value
Register tool functions on agents using register_for_execution() and register_for_llm(); tool functions receive and mutate context_variables to drive handoff routing
Initiate the swarm with initiate_swarm_chat(initial_agent, agents, messages, context_variables=context_variables)
Known gotchas
Context variables are shared across all agents in the swarm — a tool mutation by one agent immediately affects routing logic for all others
OnContextCondition checks variables at handoff time; if a tool does not update the variable before returning, the condition never triggers
AG2 is on a path to v1.0 where autogen.beta becomes the stable API — check docs.ag2.ai for deprecation notices before pinning a version
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp