Featured image of post Start a rap battle between agents with AutoGen - AutoGen Studio

Start a rap battle between agents with AutoGen - AutoGen Studio

AutoGen is a powerful framework by Microsoft for building multi-agent scenarios. In this post, we'll start taking a look at it through the lens of AutoGen Studio, a web application that you can use as a playground to test your agentic ideas.

Last year, we dived into the world of multi-agents scenarios and we learned how this approach can help to solve complex problems, by splitting them into smaller tasks that can be solved by different agents. At that time, we chose Semantic Kernel as a framework to build our agents, continuing on the explorations we did on how Semantic Kernel can help to infuse AI into your applications.

However, Semantic Kernel isn’t the only framework created by Microsoft to support AI workloads. A while ago, a Microsoft Research team started to work on AutoGen which, unlike Semantic Kernel (which is a general puprose AI orchestration framework that offers agents support as well), it’s a framework specifically designed for building multi-agent systems. AutoGen recently went through a major refactoring, which led to the stable 0.4 release.

In this series of posts, we’ll explore AutoGen and its capabilities with a scenario that isn’t very enterprise-friendly, but it shows the potentials of a multi-agent approach in an effective way. We’re going to run… drum roll… a rap battle between agents! 🎤

Our solution will consist of four agents:

  • An MC agent, that will introduce the rap battle.
  • Two rapper agents, who will generate lyrics for the rap battle starting from a given topic.
  • A judge agent, who will evaluate the lyrics and declare a winner.

In this post, we’ll start to experiment with this scenario using AutoGen Studio, a web application that you can use as a playground to test your agent configuration before actually coding it.

Let’s start!

Setting up AutoGen Studio

AutoGen Studio is a web application based on Python, so the easiest way to install it is through PyPi, the Python package manager. However, in my experience, I had a few challenges when I tried to do that using my default Python installation, due to some conflicts with existing dependencies. As such, the best way to avoid them is to create a new Python virtual environment, which is a self-contained directory that contains a Python installation for a particular version of Python, plus several additional packages.

The easiest way to manage virtual environments is to leverage Conda, a package system and environment manager for Python. To install it, you have two options:

  • If you want to install the most comprehensive version, you can get Anaconda from the official website. However, this version comes with a lot of packages and features that you might not need.
  • If you prefer to install a more lightweight version, you can get Miniconda from the official website. This version is a minimal installer for conda and only includes conda, Python, the packages they depend on, and a small number of other useful packages.

Regardless of your choice, at the end of the installation, you will find a couple of new Anaconda-specific terminals in the Start menu and Windows Terminal.

The Anaconda terminals

Run the Anaconda PowerShell Prompt and type the following command:

1
2
conda create -n autogen python=3.10
conda activate autogen

Now you have a dedicated Python environment you can use to isolate all the dependencies required by AutoGen Studio. You can now proceed to the actual installation, by typing the following command:

1
pip install autogenstudio

Once the installation is complete, you can start AutoGen Studio by typing the following command:

1
autogenstudio ui

You will see, at the end of the initialization process, a message with the URL to open, which is http://127.0.0.1:8081. Open it inside your favorite browser to finally get access to AutoGen Studio:

The AutoGen Studio UI

Let’s explore the various building blocks!

Getting started with AutoGen Studio

AutoGen Studio is made by four sections:

  • Team Builder is where you’re going to spend most of time, since it provides the components to create a multi-agent scenario.
  • Playground is where you’re actually going to test your multi-agent scenario, by starting a chat with your agents.
  • Gallery is where you can find a few pre-built scenarios that you can use as a starting point. What’s important for us is that we have a Default Component Gallery, which contains all the main building blocks we’ll need to use to build our scenario.
  • Deploy is where you will find instruction on how you can turn the scenario you build into a real application, by using the AutoGen APIs or Docker.

Let’s take a deeper look at the Default Component Gallery, since it contains the main building blocks that AutoGen offers for building multi-agent scenarios, whether you build them with AutoGen Studio or in code.".

The default component gallery in AutoGen Studio

There are five main building blocks:

  • Agents are the core component of a multi-agent scenario. They are the ones that will actually do the work, by executing tasks and following the set of instructions we have provided. Typically, in a multi-agent architecture, each agent has different skills and capabilities and they are specialized in one task. For example, in our rap battle, every agent will play a different role: one will introduce the battle, two will generate lyrics following a specific rap style, one will judge the lyrics and declare a winner.
  • Models are the AI engines used by agents to perform their tasks. We can use OpenAI, Azure OpenAI or open-source models like llama or DeepSeek R1. Typically, models are associated with an agent, but we’ll see how they can be used to empower a team in some specific scenarios.
  • Tools are custom Python functions that an agent can use to perform a task. They are equivalent to Semantic Kernel plugins and, being built with Python code, you can use them to extend the capabilities of an LLM and interact with APIs, databases, read files, etc.
  • Terminations are the conditions that you can use to define when the multi-agent conversation is completed. The most common type of terminations are based on the number of messages (e.g. terminate the conversation after 10 messages) or a specific keyword mentioned in the conversation (e.g. terminate the conversation when the word “terminate” is mentioned).
  • Teams are the glue that puts everything together. A team orchestrates the work of agents and it’s composed by the agents themselves, optionally a model and the termination conditions.

Now that we have a better understanding of the building blocks we’re going to use, let’s start to build our rap battle!

Creating the multi-agent scenario

The starting point in AutoGen Studio to create our scenario is the Team Builder section. Click on New Team. This will create a new default configuration with:

  • A team object, which is the main orchestrator of the scenario.
  • One default agent, called weather_agent, with a default model (gpt-4o-mini).

AutoGen Studio offers a visual drag & drop interface. For example, if we want to add another agent to our team, we can pick one of the available agents in the Component Library and drag it inside the team.

A new team created in AutoGen Studio

Behind the scenes, the configuration will be stored in JSON format, which we can see by turning off the Visual builder mode option:

The JSON representation o a team

The JSON shows that the team is the main object of the scenario. Inside it, we have a config property which has a sub collection called participants, which stores the configuration of all the agents that participates to the scenario. From the provider property, we can also understand a bit more the approach that this team is going to use. By default, in fact, the provider property will be set to autogen_agentchat.teams.RoundRobinGroupChat, which refers to a round-robin approach, where each agent will take turns to respond to the conversation. We will explore more the JSON as we’re going to build our rap battle.

For the moment, let’s keep the team, but let’s delete the default weather_agent, by clicking on the trash can icon. As you can see from the Component Library on the left, we have different agents available. Let’s pick the AssistantAgent one, which represents a default agent powered by the OpenAI Chat Completion APIs, and drag it innside the Agents section of the team. This will be our MC agent, which is going to introduce the rap battle. Click on the pencil icon to start editing it using the visual interface:

Editing the configuration of an agent

Let’s start to customize the properties in the Component Details section:

  • Label: this is the “verbose” name of the agent. Let’s call it Rap MC Agent.
  • Description: this is the description of the agent. It doesn’t need to follow a specific format, but it should be a short sentence that describes the role of the agent. Let’s set it to An agent that acts as the master of ceremonies in a rap battle.

Now let’s move to the Component details one:

  • Name: this property is more important, because it’s the actual name of the agent. It can be used also within a conversation or in the instructions to refer to it. Let’s set it to rapmc_agent.
  • Description: this is, again, a description of the agent, which is used by the LLM to understand the role of the agent in the conversation. We can safely reuse the one we have used in the Component Details section, which is An agent that acts as a master of ceremony in a rap battle.
  • System Message: this is a key property, since it’s the set of instructions that our agent will follow. Here we must describe, in a detailed way and in natural language, how the agent must behave. Let’s set the one for our MC agent:
1
2
3
4
5
6
7
8
You are a rap MC and your role is to run a rap battle with two contestants. 
The user will provide you with the topic for the battle. 
Your main task is to be the master of ceremony and introduce the rap battle. 
You must share some words of encouragement and describe the topic for the battle that was given by the user. 
YOU MUST USE THE TOPIC GIVEN BY THE USER, you can't make up one on your own. 
You must be very enthusiastic and use a lot of exclamation marks. 
You must also use a lot of slang words and rap terms. 
You must also use emojis.

Let’s take a look now at the final configuration section:

The configuration of the agent

For the moment, let’s keep the option Reflect on tool use off, since our agent won’t actually use any tool, just instructions. However, we must set up the model in order for our agent to work. The agent already comes with a default configuration, called Model Client. Click on the edit icon near it to get access to the configuration to the OpenAIChatCompletionClient object, which wraps the Chat Completion APIs provided by OpenAI. By default, the configuration is set to use the gpt-4o-mini model and the OpenAI API. If you’re comfortable with this setup, the only field you need to modify is the API Key. Paste the API Key provided by OpenAI, which you can obtain from https://platform.openai.com/settings/organization/api-keys after you have logged in with your OpenAI account.

If you want to use Azure OpenAI or an entirely different model, you will need to directly manipulate the JSON file that describes the team, since the UI doesn’t support this scenario as of today. Let’s take a look at how we can switch to Azure OpenAI, for example. After you have saved your changes, switch to JSON mode and, inside the config -> participants property, you will find the configuration of the rapmc_agent.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
    "provider": "autogen_agentchat.agents.AssistantAgent",
    "component_type": "agent",
    "version": 1,
    "component_version": 1,
    "description": "An agent that acts as a master of ceremony in a rap battle",
    "label": "Rap MC Agent",
    "config": {
        "name": "assistant_agent",
        "model_client": {
            "provider": "autogen_ext.models.openai.OpenAIChatCompletionClient",
            "component_type": "model",
            "version": 1,
            "component_version": 1,
            "description": "Chat completion client for OpenAI hosted models.",
            "label": "OpenAIChatCompletionClient",
            "config": {
                "model": "gpt-4o-mini",
                "api_key": "<your-openai-api-key>"
            }
        },
        "tools": [
        {
            "provider": "autogen_core.tools.FunctionTool",
            "component_type": "tool",
            "version": 1,
            "component_version": 1,
            "description": "Create custom tools by wrapping standard Python functions.",
            "label": "FunctionTool",
            "config": {
                "source_code": "def calculator(a: float, b: float, operator: str) -> str:\n    try:\n        if operator == '+':\n            return str(a + b)\n        elif operator == '-':\n            return str(a - b)\n        elif operator == '*':\n            return str(a * b)\n        elif operator == '/':\n            if b == 0:\n                return 'Error: Division by zero'\n            return str(a / b)\n        else:\n            return 'Error: Invalid operator. Please use +, -, *, or /'\n    except Exception as e:\n        return f'Error: {str(e)}'\n",
                "name": "calculator",
                "description": "A simple calculator that performs basic arithmetic operations",
                "global_imports": [],
                "has_cancellation_support": false
            }
        }],
        "handoffs": [],
        "model_context": {
            "provider": "autogen_core.model_context.UnboundedChatCompletionContext",
            "component_type": "chat_completion_context",
            "version": 1,
            "component_version": 1,
            "description": "An unbounded chat completion context that keeps a view of the all the messages.",
            "label": "UnboundedChatCompletionContext",
            "config": {}
        },
        "description": "An agent that acts as a master of ceremony in a rap battle",
        "system_message": "You are a rap MC and your role is run a rap battle with two contestants. The user will provide you the topic for the battle. Your main task is to be the master of ceremony and introduce the rap battle. You must share some words of encouragement and describe the topic for the battle that was given by the user. YOU MUST USE THE TOPIC GIVEN BY THE USER, you can't make up one on your own. \nYou must be very enthusiastic and use a lot of exclamation marks. You must also use a lot of slang words and rap terms. You must also use emojis.",
        "model_client_stream": false,
        "reflect_on_tool_use": false,
        "tool_call_summary_format": "{result}",
        "label": "Rap MC Agent"
    }
}

Let’s focus on the model_client property:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
"model_client": {
    "provider": "autogen_ext.models.openai.OpenAIChatCompletionClient",
    "component_type": "model",
    "version": 1,
    "component_version": 1,
    "description": "Chat completion client for OpenAI hosted models.",
    "label": "OpenAIChatCompletionClient",
    "config": {
        "model": "gpt-4o-mini",
        "api_key": "<your-openai-api-key>"
    }
}

This JSON representation reflects the configuration set in the UI: it specifies the gpt-4o-mini model and includes our API key. If we want to use Azure OpenAI, we must switch to another provider, which is autogen_ext.models.azure.AzureOpenAIChatCompletionClient. The configuration looks a bit different since you need some extra information to connect to Azure OpenAI:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
{
  "provider": "autogen_ext.models.openai.AzureOpenAIChatCompletionClient",
  "component_type": "model",
  "version": 1,
  "component_version": 1,
  "description": "Chat completion client for Azure OpenAI hosted models.",
  "label": "AzureOpenAIChatCompletionClient",
  "config": {
    "model": "gpt-4o-mini",
    "api_key": "sk-...",
    "azure_endpoint": "https://{your-custom-endpoint}.openai.azure.com/",
    "azure_deployment": "{your-azure-deployment}",
    "api_version": "2024-06-01"
  }
}

Compared to OpenAI, we need to add a few extra properties in the config section:

  • azure_endpoint: the endpoint of your Azure OpenAI resource.
  • azure_deployment: the deployment name of your Azure OpenAI resource.
  • api_version: the API version to use.

Since we’re already examining the agent’s JSON configuration, let’s make another change not currently supported by the UI. If you take a look again at the JSON, you will find a property called tools, which stores all the tools that we want the agent to be able to use to perform their tasks:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
"tools": [
    {
        "provider": "autogen_core.tools.FunctionTool",
        "component_type": "tool",
        "version": 1,
        "component_version": 1,
        "description": "Create custom tools by wrapping standard Python functions.",
        "label": "FunctionTool",
        "config": {
            "source_code": "def calculator(a: float, b: float, operator: str) -> str:\n    try:\n        if operator == '+':\n            return str(a + b)\n        elif operator == '-':\n            return str(a - b)\n        elif operator == '*':\n            return str(a * b)\n        elif operator == '/':\n            if b == 0:\n                return 'Error: Division by zero'\n            return str(a / b)\n        else:\n            return 'Error: Invalid operator. Please use +, -, *, or /'\n    except Exception as e:\n        return f'Error: {str(e)}'\n",
            "name": "calculator",
            "description": "A simple calculator that performs basic arithmetic operations",
            "global_imports": [],
            "has_cancellation_support": false
        }
    }
]

By default, AutoGen Studio adds a FunctionTool to our agent called calculator, which is a custom Python function to do simple math operations. Our RAP MC agent won’t need it, so we can safely remove it from the JSON. Pay attention that we can’t remove the entire tools property, otherwise the JSON won’t be valid, but we just need to turn it into an empty array:

1
"tools": []

Creating the other agents

Now that we have seen how to create the first agent, we just need to replicate the same steps, but for the other agents.

Let’s start with the first rapper agent, which will be called Eminem Agent, since we’re going to configure it in a way that it will generate lyrics following the style of Eminem. Drag and drop a new AssistantAgent inside the team and configure it as follows:

  • Label: Eminem Agent
  • Description: An agent that generates rap lyrics in the style of Eminem
  • Name: eminem_agent
  • Description: An agent that generates rap lyrics in the style of Eminem
  • System Message:
1
2
3
4
5
You are a rapper, and you rap in the style of Eminem. 
You are participating in a rap battle. 
You will be given a topic, and you will need to create the lyrics and rap about it. 
Be creative, but remember to stay on topic. 
Do your best, since you're going to compete against another rapper.

Now let’s move to the second agent, which will be called Drake Agent since, in this case, it’s going to generate lyrics following the style of Drake. Drag and drop another AssistantAgent inside the team and configure it as follows:

  • Label: Drake Agent
  • Description: An agent that generates rap lyrics in the style of Drake
  • Name: drake_agent
  • Description: An agent that generates rap lyrics in the style of Drake
  • System Message:
1
2
3
4
5
You are a rapper, and you rap in the style of Drake. 
You are participating in a rap battle. 
You will be given a topic, and you will need to create the lyrics and rap about it. 
Be creative, but remember to stay on topic. 
Do your best, since you're going to compete against another rapper.

Finally, let’s create the judge agent, which will evaluate the lyrics and declare a winner. Drag and drop for the last time an AssistantAgent inside the team and configure it as follows:

  • Label: Judge Agent
  • Description: An agent that evaluates the rap lyrics and declares a winner
  • Name: judge_agent
  • Description: An agent that evaluates the rap lyrics and declares a winner
  • System Message:
1
2
3
4
5
6
7
You are a judge in a rap battle. 
You will be given the lyrics of the rap battle and you must give a score to each contestant. 
You must give a score between 1 and 10 to each contestant. The rapper who gets the highest score wins.
You must ensure that the final score is given after all the other contestants have shared their lyrics. 
In addition to the score, you also need to provide an explanation of why you assigned that score. 
YOUR FINAL RESPONSE MUST BE THE SCORE AND THE WINNER DECLARATION. 
When the plan is complete and the winner has been declared, you can respond with TERMINATE.

As you can see, for the last agent the instructions are a bit more detailed, since we need to manage the signal that the rap battle is over, so the multi-agent conversation must be wrapped up. In this case, we’re asking to the Judge Agent to respond with the word TERMINATE when the rap battle is over and the winner has been declared.

Don’t forget, for every agent you have just created, to make the same changes we applied to the MC agent:

  • Provide the API key for using the OpenAI model (or switch to the JSON editor to change the configuration to use Azure OpenAI).
  • Remove the calculator tool from the configuration.

Now we’re ready to put everything together and set up the team.

Setting up the team

Since we dragged and dropped the agents inside the team in the previous section, most of the configuration is already completed. We just need to set up the termination condition, which is the last step before we can start the rap battle. Since we configured the Judge Agent to respond with the word TERMINATE when the rap battle is over, we can use this keyword as termination condition. Drag the TextMentionTermination condition from the Component Library and drop it inside the team, under the Terminations section. Now click on the pencil icon to edit the team. Since we’re here, let’s give to the team also a more meaningful name, by changing the label property for example to Rap Battle. Then go on and perform the two following actions:

  • Change the Max Turn property to 10 otherwise, after the first agent response, the conversation will terminate.

  • Click on the edit button near Termination Condition in the Configuration section. You should see that the termination condition is already set in the proper way for our scenario: the Text property is set to TERMINATE, which is the keyword we have configured for the Judge Agent to signal that the rap battle is over.

    The termination configuration

Now, we’re ready to start the rap battle! Before doing that, however, as a reference let me share the complete JSON configuration of the team after we have completed all the changes:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
{
  "provider": "autogen_agentchat.teams.RoundRobinGroupChat",
  "component_type": "team",
  "version": 1,
  "component_version": 1,
  "description": "A team of agents that chat with users in a round-robin fashion.",
  "label": "Rap Battle v2",
  "config": {
    "participants": [
      {
        "provider": "autogen_agentchat.agents.AssistantAgent",
        "component_type": "agent",
        "version": 1,
        "component_version": 1,
        "description": "An agent that acts as a master of ceremony in a rap battle",
        "label": "Rap MC Agent",
        "config": {
          "name": "rapmc_agent",
          "model_client": {
            "provider": "autogen_ext.models.openai.OpenAIChatCompletionClient",
            "component_type": "model",
            "version": 1,
            "component_version": 1,
            "description": "Chat completion client for OpenAI hosted models.",
            "label": "OpenAIChatCompletionClient",
            "config": {
              "model": "gpt-4o-mini",
              "api_key": "sk-..."
            }
          },
          "tools": [],
          "handoffs": [],
          "model_context": {
            "provider": "autogen_core.model_context.UnboundedChatCompletionContext",
            "component_type": "chat_completion_context",
            "version": 1,
            "component_version": 1,
            "description": "An unbounded chat completion context that keeps a view of the all the messages.",
            "label": "UnboundedChatCompletionContext",
            "config": {}
          },
          "description": "An agent that acts as a master of ceremony in a rap battle",
          "system_message": "You are a rap MC and your role is to run a rap battle with two contestants. The user will provide you with the topic for the battle. Your main task is to be the master of ceremony and introduce the rap battle. You must share some words of encouragement and describe the topic for the battle that was given by the user. YOU MUST USE THE TOPIC GIVEN BY THE USER, you can't make up one on your own. \nYou must be very enthusiastic and use a lot of exclamation marks. You must also use a lot of slang words and rap terms. You must also use emojis.",
          "model_client_stream": false,
          "reflect_on_tool_use": false,
          "tool_call_summary_format": "{result}",
          "label": "Rap MC Agent",
          "config": {
            "name": "assistant_agent",
            "description": "An agent that acts as a master of ceremony in a rap battle",
            "system_message": "You are a helpful assistant. Solve tasks carefully. When done, say TERMINATE.",
            "reflect_on_tool_use": false,
            "tool_call_summary_format": "{result}"
          }
        }
      },
      {
        "provider": "autogen_agentchat.agents.AssistantAgent",
        "component_type": "agent",
        "version": 1,
        "component_version": 1,
        "description": "An agent that generates rap lyrics in the style of Eminem",
        "label": "Eminem Agent",
        "config": {
          "name": "eminem_agent",
          "model_client": {
            "provider": "autogen_ext.models.openai.OpenAIChatCompletionClient",
            "component_type": "model",
            "version": 1,
            "component_version": 1,
            "description": "Chat completion client for OpenAI hosted models.",
            "label": "OpenAIChatCompletionClient",
            "config": {
              "model": "gpt-4o-mini",
              "api_key": "sk-..."
            }
          },
          "tools": [],
          "handoffs": [],
          "model_context": {
            "provider": "autogen_core.model_context.UnboundedChatCompletionContext",
            "component_type": "chat_completion_context",
            "version": 1,
            "component_version": 1,
            "description": "An unbounded chat completion context that keeps a view of the all the messages.",
            "label": "UnboundedChatCompletionContext",
            "config": {}
          },
          "description": "An agent that generates rap lyrics in the style of Eminem",
          "system_message": "You are a rapper, and you rap in the style of Eminem. You are participating in a rap battle. You will be given a topic, and you will need to create the lyrics and rap about it. Be creative, but remember to stay on topic. Do your best, since you're going to compete against another rapper.",
          "model_client_stream": false,
          "reflect_on_tool_use": false,
          "tool_call_summary_format": "{result}"
        }
      },
      {
        "provider": "autogen_agentchat.agents.AssistantAgent",
        "component_type": "agent",
        "version": 1,
        "component_version": 1,
        "description": "An agent that generates rap lyrics in the style of Drake",
        "label": "Drake Agent",
        "config": {
          "name": "drake_agent",
          "model_client": {
            "provider": "autogen_ext.models.openai.OpenAIChatCompletionClient",
            "component_type": "model",
            "version": 1,
            "component_version": 1,
            "description": "Chat completion client for OpenAI hosted models.",
            "label": "OpenAIChatCompletionClient",
            "config": {
              "model": "gpt-4o-mini",
              "api_key": "sk-..."
            }
          },
          "tools": [],
          "handoffs": [],
          "model_context": {
            "provider": "autogen_core.model_context.UnboundedChatCompletionContext",
            "component_type": "chat_completion_context",
            "version": 1,
            "component_version": 1,
            "description": "An unbounded chat completion context that keeps a view of the all the messages.",
            "label": "UnboundedChatCompletionContext",
            "config": {}
          },
          "description": "An agent that generates rap lyrics in the style of Drake",
          "system_message": "You are a rapper, and you rap in the style of Drake. You are participating in a rap battle. You will be given a topic, and you will need to create the lyrics and rap about it. Be creative, but remember to stay on topic. Do your best, since you're going to compete against another rapper.",
          "model_client_stream": false,
          "reflect_on_tool_use": false,
          "tool_call_summary_format": "{result}"
        }
      },
      {
        "provider": "autogen_agentchat.agents.AssistantAgent",
        "component_type": "agent",
        "version": 1,
        "component_version": 1,
        "description": "An agent that evaluates the rap lyrics and declares a winner",
        "label": "Judge Agent",
        "config": {
          "name": "judge_agent",
          "model_client": {
            "provider": "autogen_ext.models.openai.OpenAIChatCompletionClient",
            "component_type": "model",
            "version": 1,
            "component_version": 1,
            "description": "Chat completion client for OpenAI hosted models.",
            "label": "OpenAIChatCompletionClient",
            "config": {
              "model": "gpt-4o-mini",
              "api_key": "sk-..."
            }
          },
          "tools": [],
          "handoffs": [],
          "model_context": {
            "provider": "autogen_core.model_context.UnboundedChatCompletionContext",
            "component_type": "chat_completion_context",
            "version": 1,
            "component_version": 1,
            "description": "An unbounded chat completion context that keeps a view of the all the messages.",
            "label": "UnboundedChatCompletionContext",
            "config": {}
          },
          "description": "An agent that evaluates the rap lyrics and declares a winner",
          "system_message": "You are a judge in a rap battle. You will be given the lyrics of the rap battle and you must give a score to each contestant. You must give a score between 1 and 10 to each contestant. The rapper who gets the highest score wins. \\\\n You must ensure that the final score is given after all the other contestants have shared their lyrics. On top of the score, you need also to provide an explanation on why you assinged that score. YOUR FINAL RESPONSE MUST BE THE SCORE AND THE WINNER DECLARATION. When the plan is complete and the winner has been declared, you can respond with TERMINATE.",
          "model_client_stream": false,
          "reflect_on_tool_use": false,
          "tool_call_summary_format": "{result}"
        }
      }
    ],
    "termination_condition": {
      "provider": "autogen_agentchat.conditions.TextMentionTermination",
      "component_type": "termination",
      "version": 1,
      "component_version": 1,
      "description": "Terminate the conversation if a specific text is mentioned.",
      "label": "TextMentionTermination",
      "config": {
        "text": "TERMINATE",
        "label": "TextMentionTermination",
        "description": "Terminate the conversation if a specific text is mentioned.",
        "config": {
          "text": "TERMINATE"
        }
      }
    },
    "max_turns": 1,
    "label": "Rap Battle v2",
    "description": "A team of agents that chat with users in a round-robin fashion.",
    "config": {
      "max_turns": 1
    }
  }
}

Test the multi-agent scenario

To test our rap battle, we must head to the Playground section of AutoGen Studio and click on New session. Give it a name you like and, under Team, pick the team we have just created. Click on Create to create the new session.

Create a new Playground session

You will start a chat session, which will give you the chance to send a message to the team and see how it responds. For our rap battle, let’s just provide the topic, by typing for example the following message:

1
The topic of the rap battle is "marshmallow"

After sending the message, you should see the following happening:

  • The Rap MC agent will share an introduction to the rap battle, by describing the topic. You will notice how the agent will follow the style we included in the instructions, like adding emojis and using a rap slang. In my case, for example, the agent created the following introduction:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    🎤🎶 Yo! Yo! Yo! What’s good, rap fam?! Welcome to the hottest rap battle of the century! It’s your boy, the MC with the flyest flow in the game, and I’m here to serve up an epic showdown for y’all! 💥🔥
    
    Tonight, we're diving into a topic that’s sweeter than candy and fluffier than clouds in the sky— "MARSHMALLOW!" That’s right, folks! We’re talkin’ about that gooey goodness that melts in your mouth and sticks in your heart! 🍬❤️
    
    So, whether you’re vibin’ with s’mores around the campfire or just chillin’ with a hot cocoa, these two contestants are ready to spit some fire and mix it up with those marshmallow bars! 🚀🍫
    
    I wanna hear your loudest cheers, your hype, and your energy for our dope contenders! Let’s lift them up and show ‘em some love! 💚💛 You see, rap battles are all about creativity and passion, so let's get ready to witness some epic flows, clever wordplay, and marshmallow magic! 🎤🔥
    
    Remember, fam, it’s all in good fun— no beef, just beats! Now, without further ado, let’s bring these lyrical legends to the stage!! Who’s ready to get this marshmallow madness poppin’?! Let’s go!!! 🎉🎤✌️
    
  • After the MC agent, the Eminem agent will respond with its lyrics, followed by the Drake agent, which which will generate its own version of the lyrics.

  • Finally, the Judge agent will respond with the score and the winner. In my case, for example, it generated the following response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Scores:

Eminem: 9/10
Drake: 8/10
Explanation:

Eminem delivered a powerful performance with clever wordplay and an engaging flow that seamlessly adapted the marshmallow theme into a vivid and memorable rap experience. His verses incorporated a narrative about the essence of marshmallows while cleverly intertwining personal and nostalgic elements, making it relatable and fresh. The repetition of the chorus further emphasized his theme, and the rhythm maintained the audience's excitement. All of this culminated in a strong performance worthy of a high score.

Drake brought a lighter, melodic vibe that was enjoyable but felt slightly less impactful compared to Eminem's approach. His lyrics were catchy and showcased his signature style, yet some of the lines lacked the same punch and depth that made Eminem's verses stand out. While the composition was solid and fit well with the theme, it didn't quite reach the same level of innovation.

In conclusion, Eminem's overall execution and creativity in writing earned him the victory in this rap battle!

Winner: Eminem
Final Score: Eminem 9, Drake 8

TERMINATE

As you can see, the response ends with the TERMINATE word, which will lead to the termination of the conversation.

Once the rap battle is ended, at the top will see the last message posted in the conversation and the reason why the conversation is ended.

The task is completed

Additionally, you can see two features that make AutoGen Studio a very interesting tool to test these multi-agent scenarios ahead of their implementation in code:

  • We can track the number of messages and tokens used to estimate the conversation’s potential cost.

    The number of total tokens used in the conversation

  • We can see a visual representation of the workflow, including the number of tokens used in each step

    The visual workflow of the outcome

From the visual workflow, we can see that in our case our conversation was quite linear: every agent responded one after the other. This is because the type of team we used is the RoundRobinGroupChat one, which does exactly that: invoking one agent after the other, according to the order we have added them into the team. However, AutoGen Studio also supports more complex scenarios where agents can respond in a non-linear fashion. We’ll see more in the next blog post, in which we’ll add an extra feature to our rap battle: the ability to use tools.

Conclusion

In this post, we have seen how to create a multi-agent scenario using AutoGen Studio. We have created a rap battle scenario, in which we had an MC agent, two rapper agents and a judge agent. We have also seen how to configure the team and the termination condition, so that the conversation would end when the judge agent declared the winner. However, this was just the first post of a series. In the next one, we’ll add a new feature to our rap battle: a tool to generate a list of words, that the Rap MC agent will use to encourage the two rappers to use them in their lyrics.

Then, we will see also how to turn the playground test we did into a real application, by leveraging AutoGen as an application framework.

Happy coding!

Built with Hugo
Theme Stack designed by Jimmy