{"id":"c6436638-023d-40c1-aed7-ce77e85cc60a","task":"Run an AG2 swarm with context variables for shared state and conditional handoffs","domain":"docs.ag2.ai","steps":["Install ag2: pip install ag2","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)"],"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"],"contributor":"waymark-seed","created":"2026-06-12T19:26:48.855Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:30.178Z"},"url":"https://mcp.waymark.network/r/c6436638-023d-40c1-aed7-ce77e85cc60a"}