Table of Contents

RoundRobinGroupChat is a group chat that invokes agents in a round-robin order. It's useful when you want to call multiple agents in a fixed sequence. For example, asking search agent to retrieve related information followed by a summarization agent to summarize the information. Beside, it also used by SendAsync(IAgent, IAgent, string, IEnumerable<IMessage>?, int, CancellationToken) in two agent chat.

Use RoundRobinGroupChat to implement a search-summarize chat flow

flowchart LR
    A[User] -->|Ask a question| B[Search Agent]
    B -->|Retrieve information| C[Summarization Agent]
    C -->|Summarize result| A[User]
Note

Complete code can be found in Example11_Sequential_GroupChat_Example;

Step 1: Add required using statements

using AutoGen.Core;
using AutoGen.OpenAI;
using AutoGen.OpenAI.Extension;
using AutoGen.SemanticKernel;
using AutoGen.SemanticKernel.Extension;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Plugins.Web;
using Microsoft.SemanticKernel.Plugins.Web.Bing;

Step 2: Create a bingSearch agent using SemanticKernelAgent

var config = LLMConfiguration.GetAzureOpenAIGPT3_5_Turbo();
var apiKey = config.ApiKey;
var kernelBuilder = Kernel.CreateBuilder()
    .AddAzureOpenAIChatCompletion(config.DeploymentName, config.Endpoint, apiKey);
var bingApiKey = Environment.GetEnvironmentVariable("BING_API_KEY") ?? throw new Exception("BING_API_KEY environment variable is not set");
var bingSearch = new BingConnector(bingApiKey);
var webSearchPlugin = new WebSearchEnginePlugin(bingSearch);
kernelBuilder.Plugins.AddFromObject(webSearchPlugin);

var kernel = kernelBuilder.Build();
var kernelAgent = new SemanticKernelAgent(
    kernel: kernel,
    name: "bing-search",
    systemMessage: """
    You search results from Bing and return it as-is.
    You put the original search result between ```bing and ```

    e.g.
    ```bing
    xxx
    ```
    """)
    .RegisterMessageConnector()
    .RegisterPrintMessage(); // pretty print the message

return kernelAgent;

Step 3: Create a summarization agent using SemanticKernelAgent

var gpt4o = LLMConfiguration.GetOpenAIGPT4o_mini();
var openAIClientAgent = new OpenAIChatAgent(
    chatClient: gpt4o,
    name: "summarizer",
    systemMessage: "You summarize search result from bing in a short and concise manner");

return openAIClientAgent
    .RegisterMessageConnector()
    .RegisterPrintMessage(); // pretty print the message

Step 4: Create a RoundRobinGroupChat and add bingSearch and summarization agents to it

var userProxyAgent = new UserProxyAgent(
    name: "user",
    humanInputMode: HumanInputMode.ALWAYS)
    .RegisterPrintMessage();

var bingSearchAgent = await CreateBingSearchAgentAsync();
var summarizerAgent = await CreateSummarizerAgentAsync();

var groupChat = new RoundRobinGroupChat(
    agents: [userProxyAgent, bingSearchAgent, summarizerAgent]);

var groupChatAgent = new GroupChatManager(groupChat);

var history = await userProxyAgent.InitiateChatAsync(
    receiver: groupChatAgent,
    message: "How to deploy an openai resource on azure",
    maxRound: 10);

Output:

Searcher-Summarizer