Skip to main content

Authors:

Harish Mohan Raj

Software Engineer at AG2.ai

Mark Sze

Software Engineer at AG2.ai

AG2 v0.9 Release: Introducing the New Group Chat

TL;DR

  • AG2 v0.9 unifies the previous Group Chat and Swarm into a single, powerful, new Group Chat
  • This unification provides improved flexibility, control, and better foundations for scalability
  • Features include pre-built orchestration patterns, enhanced workflow control, and robust context variables
  • Includes all capabilities of the previous Group Chat and Swarm
  • Swarm is now deprecated but still available. We recommend migrating to the new Group Chat pattern

We’re excited to announce the release of AG2 v0.9, featuring a significant enhancement to multi-agent orchestration. This release brings together our widely used Group Chat and Swarm pattern into a unified, more powerful Group Chat that combines the best aspects of both approaches.

A New Era for Multi-Agent Orchestration

AG2 has always provided multiple ways to coordinate agents, from simple two-agent conversations to more complex multi-agent orchestration. With v0.9, we’ve completely reimagined agent orchestration by merging these approaches into a single, unified Group Chat architecture designed to be extensible, controllable, and scalable.

Why We Made This Change

Before diving into the details, let’s understand why this unification matters:
  • Simplified API - One coherent way to orchestrate multi-agent workflows
  • Enhanced Flexibility - Structured handoffs from Swarm with more diverse hand off targets
  • Improved State Management - More robust context sharing and state tracking across agents
  • Future-proof Design - A foundation that can grow with evolving multi-agent orchestration needs

Key Features of the New Group Chat

Pre-built Patterns for Different Needs

The new Group Chat implements several orchestration patterns to suit different use cases:
  • AutoPattern: Uses an LLM to intelligently select the next speaker based on conversation context
  • RoundRobinPattern: Creates a sequential rotation where agents speak in a predefined order
  • RandomPattern: Randomly selects the next agent to speak (excluding the current speaker)
  • ManualPattern: Puts humans in control by allowing manual selection of the next speaker
  • DefaultPattern: Provides complete control of transitions

Dynamic Workflow Control with Handoffs

The handoff system has been enhanced to provide powerful control over agent transitions:

Enhanced Transition Targets

The new Group Chat pattern introduces powerful “Transition Targets” - which define where control should go after an agent completes its work. This system goes beyond simply transferring to another agent:
  • AgentTarget/AgentNameTarget: Transfer to a specific agent directly or by name
  • RevertToUserTarget: Return control to the human user
  • TerminateTarget: End the conversation entirely
  • StayTarget: Keep control with the current agent
  • RandomAgentTarget: Randomly select from a list of possible agents
  • AskUserTarget: You decide who the next agent is
  • NestedChatTarget: Transfer to a nested conversation
  • GroupChatTarget: Transfer to a new group chat (nested group chats!)
  • GroupManagerTarget: Transfer to the group chat manager who will select the next speaker
This flexible targeting system enables complex workflows where control might need to move between different levels of conversation or to specialized processes.

Shared Context Management

The new ContextVariables class provides a structured way to share and maintain state across agents. This shared memory enables agents to:
  • Maintain consistent information throughout a conversation
  • Make decisions based on the current state
  • Pass structured data between agents
  • Control workflow based on context values
Here’s how you can create and use context variables:

Getting Started with the New Group Chat

Let’s explore a practical example of how the new Group Chat pattern can transform travel planning workflows. We’ll implement a personalized travel itinerary system where specialized agents collaborate to assist users based on their membership status.

The Use Case

In this scenario, we want to create a travel planning system that:
  • Verifies user membership and collects travel information
  • Routes users to different advisors based on membership status
  • Provides personalized itineraries using customer preferences
  • Facilitates collaboration between advisors and destination specialists
  • Tracks itinerary status from proposal to approval

Implementing the workflow with the new GroupChat

Now, let’s implement this system:

Running This Example

To run this example yourself:
  1. Save the code to a file (e.g., customer_service_demo.py)
  2. Set up your OpenAI API key - This example uses the gpt-4o-mini model from OpenAI: === “macOS / Linux”
    === “Windows”
  3. Install the required packages:
  4. Run the script:
    !!! note This example uses OpenAI’s gpt-4o-mini model. If you want to use a different provider, ensure you:
    • Install the appropriate AG2 extra (e.g., pip install ag2[anthropic] for Claude models)
    • Update the LLMConfig to use your preferred provider and model
    • Set the appropriate environment variables for authentication with your chosen provider
    You can find the supported model provides here

Example Output

When you run the above code, you should see output similar to this:

Migrating from Swarm to the New Group Chat

If you’re currently using Swarm, we strongly recommend migrating to the new Group Chat pattern. While Swarm functionality is still available in v0.9, it’s now deprecated and will be removed in a future release. At a high level, the migration process involves:
  1. Updating imports to use the new group chat modules instead of swarm modules
  2. Converting context variables from dictionary-based to the new ContextVariables class
  3. Replacing SwarmResult with ReplyResult in your agent functions
  4. Updating handoff definitions to use the new agent-based handoff system
  5. Using patterns to configure and initiate group chats
For detailed migration instructions and examples, please refer to our Migration Guide.

Towards Scalable Agent Orchestration

This unified architecture represents the first step toward more scalable agent orchestration by building upon a serializable framework of classes. Additionally, base classes for Targets and Patterns have been designed to allow you to create your own targets and patterns.

Get Started Today!

The new Group Chat pattern is available now in AG2 v0.9 and we encourage all users to explore it and build their own multi-agent applications. To learn more, check out our documentation: We’re excited to see what you build with this powerful new framework!