Skip to content

Commit

Permalink
Change outline
Browse files Browse the repository at this point in the history
  • Loading branch information
gagb committed Dec 9, 2024
1 parent a74670f commit 2bfa773
Showing 1 changed file with 48 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,18 @@
"source": [
"# Teams\n",
"\n",
"In AgentChat, teams orchestrate the collaboration of multiple agents to accomplish tasks. A team consists of one or more agents and interfaces with your application by receiving tasks and returning results. It maintains state and context across multiple tasks, ensuring continuity. Teams use stateful termination conditions to decide when to stop processing the current task.\n",
"In this section you'll learn how to create a _multi-agent team_ (or simply team) using AutoGen. A team is a group of agents that work together to achieve a common goal.\n",
"\n",
"The diagram below shows the relationship between a team and your application.\n",
"We'll first show you hot create and run a team. We'll then explain how to observe the team's behavior, which is crucial for debugging and understanding the team's performance, and common operations to control the team's behavior.\n",
"\n",
"![AgentChat Teams](./agentchat-team.svg)\n",
"\n",
"AgentChat offers several predefined teams that implement various [multi-agent design patterns](../../core-user-guide/design-patterns/index.md) to streamline development. Below is a list of these predefined teams:\n",
"\n",
"- {py:class}`~autogen_agentchat.teams.RoundRobinGroupChat`: Participants share context and take turns responding in a round-robin manner. This team will be covered in this section.\n",
"- {py:class}`~autogen_agentchat.teams.SelectorGroupChat`: Participants share context and use a model-based selector (with custom overrides) to choose the next agent to respond. For more details, see [Selector Group Chat](./selector-group-chat.ipynb).\n",
"- {py:class}`~autogen_agentchat.teams.Swarm`: Participants share context and use {py:class}`~autogen_agentchat.messages.HandoffMessage` to transfer control to the next agent. For more details, see [Swarm](./swarm.ipynb).\n",
"\n",
"At a high-level, a team API consists of the following methods:\n",
"\n",
"- {py:meth}`~autogen_agentchat.base.TaskRunner.run`: Process a task, which can be a {py:class}`str`, {py:class}`~autogen_agentchat.messages.TextMessage`, {py:class}`~autogen_agentchat.messages.MultiModalMessage`, or {py:class}`~autogen_agentchat.messages.HandoffMessage`, and returns {py:class}`~autogen_agentchat.base.TaskResult`. The task can also be `None` to resume processing the previous task if the team has not been reset.\n",
"- {py:meth}`~autogen_agentchat.base.TaskRunner.run_stream`: Similar to {py:meth}`~autogen_agentchat.base.TaskRunner.run`, but it returns an async generator of messages and the final task result.\n",
"- {py:meth}`~autogen_agentchat.base.Team.reset`: To reset the team state if the next task is not related to the previous task. Otherwise, the team can utilize the context from the previous task to process the next one.\n",
"\n",
"In this section, we will be using the\n",
"{py:class}`~autogen_agentchat.teams.RoundRobinGroupChat` team to introduce the AgentChat team API."
"We'll start by focusing on a simple team with consisting of a single agent (the baseline case) and use a round robin strategy to select the agent to act. We'll then show how to create a team with multiple agents and how to implement a more sophisticated strategy to select the agent to act."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Round-Robin Group Chat\n",
"## Creating a Team\n",
"\n",
"{py:class}`~autogen_agentchat.teams.RoundRobinGroupChat` is a simple yet effective team configuration where all agents share the same context and take turns responding in a round-robin fashion. Each agent, during its turn, broadcasts its response to all other agents, ensuring that the entire team maintains a consistent context.\n",
"\n",
Expand Down Expand Up @@ -125,40 +110,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reseting a Team\n",
"\n",
"You can reset the team by calling the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.reset` method. This method will clear the team's state, including all agents."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"await single_agent_team.reset() # Reset the team for the next run."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is usually a good idea to reset the team if the next task is not related to the previous task.\n",
"However, if the next task is related to the previous task, you don't need to reset and you can instead resume. We will cover this in the next section."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Streaming Team Messages\n",
"## Observability\n",
"\n",
"Similar to the agent's {py:meth}`~autogen_agentchat.agents.BaseChatAgent.on_messages_stream` method, you can stream the team's messages by calling the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run_stream` method. This method returns a generator that yields messages produced by the agents in the team as they are generated, with the final item being the task result.\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -245,7 +204,44 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Teams with Multiple Agents\n",
"## Controlling a Team\n",
"\n",
"You can reset the team by calling the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.reset` method. This method will clear the team's state, including all agents."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"await single_agent_team.reset() # Reset the team for the next run."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is usually a good idea to reset the team if the next task is not related to the previous task.\n",
"However, if the next task is related to the previous task, you don't need to reset and you can instead resume. We will cover this in the next section."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"## Team Usage Guide\n",
"\n",
"We will now implement a slightly more complex team with multiple agents and learn how to resume the team after stopping it and even involve the user in the conversation.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Reflection Pattern\n",
"\n",
"We will now create a team with two agents that implement the _reflection_ pattern, a multi-agent design pattern where a critic agent evaluates the responses of a primary agent.\n",
"\n",
Expand Down Expand Up @@ -395,7 +391,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Resuming a Team\n",
"### Resuming a Team\n",
"\n",
"Let's run the team again with a new task while keeping the context about the previous task."
]
Expand Down Expand Up @@ -577,7 +573,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pausing for User Input\n",
"### Pausing for User Input\n",
"\n",
"Sometimes, teams may require additional input from the application (e.g., the user) to continue making meaningful progress on a task. Here are two ways to achieve this:\n",
"\n",
Expand All @@ -591,7 +587,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Maximum Number of Turns\n",
"#### Maximum Number of Turns\n",
"\n",
"This method allows you to pause the team for user input by setting a maximum number of turns. For instance, you can configure the team to stop after the first agent responds by setting `max_turns` to 1. This is particularly useful in scenarios where continuous user engagement is required, such as in a chatbot.\n",
"\n",
Expand All @@ -613,7 +609,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using Handoff to Pause a Team\n",
"#### Using Handoff to Pause a Team\n",
"\n",
"You can use the {py:class}`~autogen_agentchat.conditions.HandoffTermination` termination condition\n",
"to stop the team when an agent sends a {py:class}`~autogen_agentchat.messages.HandoffMessage` message.\n",
Expand Down

0 comments on commit 2bfa773

Please sign in to comment.