Skip to main content
Open In Colab Open on GitHub AG2’s swarm orchestration provides a flexible and powerful method of managing a conversation with multiple agents, tools, and transitions. In this notebook, we look at more advanced features of the swarm orchestration. If you are new to swarm, check out this notebook, where we introduce the core features of swarms including global context variables, hand offs, and initiating a swarm chat. In this notebook we’re going to demonstrate these features AG2’s swarm orchestration:
  • Updating an agent’s state
  • Conditional handoffs
  • Nested chats
Install ag2:
Note: If you have been using autogen or ag2, all you need to do is upgrade it using:
or
as autogen, and ag2 are aliases for the same PyPI package.
For more information, please refer to the installation guide.

Demonstration

We’re creating this customer service workflow for an e-commerce platform. Customers can ask about the status of their orders, but they must be authenticated to do so. Swarm Enhanced Demonstration Key aspects of this swarm are:
  1. System messages are customised, incorporating the context of the workflow
  2. Handoffs are conditional, only being available when they are relevant
  3. A nested chat handles the order retrieval and summarisation

Set your API Endpoint

The LLMConfig.from_json method loads a list of configurations from an environment variable or a json file.

Context

Databases

Agent’s Functions

Agents

Nested Chats

Handoffs (OnCondition, OnContextCondition, and AfterWork)

Let’s go!

Controlling flow

When not logged in

Swarm Enhanced Demonstration

When logged in but no order id

Swarm Enhanced Demonstration

When logged in with order id

Swarm Enhanced Demonstration

Agent state

Agent System Messages with context

Swarm Enhanced Demonstration