2024-02-27 02:10:00 +08:00
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
2024-03-02 22:27:11 +08:00
"# FSM - User can input speaker transition constraints\n",
2024-02-27 02:10:00 +08:00
"\n",
"AutoGen offers conversable agents powered by LLM, tool, or human, which can be used to perform tasks collectively via automated chat. This framework allows tool use and human participation through multi-agent conversation.\n",
"Please find documentation about this feature [here](https://microsoft.github.io/autogen/docs/Use-Cases/agent_chat).\n",
"\n",
"This notebook is about using graphs to define the transition paths amongst speakers.\n",
"\n",
"Benefits\n",
"- This contribution fills the gap between the current modes of GroupChat Class (auto, manual, round_robin) and an expressive directed graph. See Motivation for more detailed discussion.\n",
"\n",
"\n",
"````{=mdx}\n",
":::info Requirements\n",
"Install `pyautogen`:\n",
"```bash\n",
"pip install pyautogen\n",
"```\n",
"\n",
"For more information, please refer to the [installation guide](/docs/installation/).\n",
":::\n",
"````"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
2024-04-19 00:43:34 +08:00
"outputs": [],
2024-02-27 02:10:00 +08:00
"source": [
"%%capture --no-stderr\n",
"%pip install pyautogen[graph]>=0.2.11"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import random # noqa E402\n",
"\n",
"import matplotlib.pyplot as plt # noqa E402\n",
"import networkx as nx # noqa E402\n",
"\n",
"import autogen # noqa E402\n",
"from autogen.agentchat.conversable_agent import ConversableAgent # noqa E402\n",
"from autogen.agentchat.assistant_agent import AssistantAgent # noqa E402\n",
"from autogen.agentchat.groupchat import GroupChat # noqa E402\n",
"from autogen.graph_utils import visualize_speaker_transitions_dict # noqa E402"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-04-19 00:43:34 +08:00
"0.2.25\n"
2024-02-27 02:10:00 +08:00
]
}
],
"source": [
"print(autogen.__version__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Motivation\n",
"\n",
"\n",
2024-04-09 23:07:44 +08:00
"The current GroupChat class allows transitioning to any agent (with or without the decision of the LLM), some use cases might demand for more control over transition. A graph is a possible way to control the transition paths, where each node represents an agent and each directed edge represents possible transition paths. Let's illustrate the current transition paths for a GroupChat with five agents."
2024-02-27 02:10:00 +08:00
]
},
{
"cell_type": "code",
2024-04-19 00:43:34 +08:00
"execution_count": 5,
2024-02-27 02:10:00 +08:00
"metadata": {},
"outputs": [],
"source": [
"config_list_gpt4 = {\n",
" \"timeout\": 600,\n",
" \"cache_seed\": 44, # change the seed for different trials\n",
" \"config_list\": autogen.config_list_from_json(\n",
" \"OAI_CONFIG_LIST\",\n",
2024-04-19 00:43:34 +08:00
" filter_dict={\"tags\": [\"gpt-4\", \"gpt-4-32k\"]}, # comment out to get all\n",
2024-02-27 02:10:00 +08:00
" ),\n",
" \"temperature\": 0,\n",
"}"
]
},
{
"cell_type": "code",
2024-04-19 00:43:34 +08:00
"execution_count": 6,
2024-02-27 02:10:00 +08:00
"metadata": {},
"outputs": [
{
"data": {
2024-04-19 00:43:34 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAApQAAAHzCAYAAACe1o1DAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAACxS0lEQVR4nOzdd1yV5f/H8dc57CGgICAq4sAFuLe498i9U9Osb46ybPgty9KWo9LKrd8sM01z5N4bFfcAERUFQUAk2cjmnN8f/jiJ4OTAfYDP8/HgER7uc9+fYwjvc1339blUWq1WixBCCCGEEC9JrXQBQgghhBCieJNAKYQQQgghCkQCpRBCCCGEKBAJlEIIIYQQokAkUAohhBBCiAKRQCmEEEIIIQpEAqUQQgghhCgQCZRCCCGEEKJAJFAKIYQQQogCkUAphBBCCCEKRAKlEEIIIYQoEAmUQgghhBCiQCRQCiGEEEKIApFAKYQQ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fXX9fi3I4QQpZMESiHEC3l0FHLQoEG5/vvo18+fP8+dO3cAcHZ2Zs2aNfTs2ZOffvqJFi1a5DlvWshFNCkJAJi7NcCssgcqY1MsajTDyNbp4THBF8j+/2MeZeHegrLtx2Dp3hzbloN1j2fG3UULlHOrg7v7v30pXV1d8fb2xtvbG1fX/JugCyGEeH4SKIUQzy0pKUm3SrpcuXJ07NgRgAEDBmBkZATA+vXr0Wq1BAcH657XqFEjTExMdH9u2bJlnnNnxkboPk8LPs+9Nf/VfWQn3Pv/r2jJjAn
2024-02-27 02:10:00 +08:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"agents = [ConversableAgent(name=f\"Agent{i}\", llm_config=False) for i in range(5)]\n",
"allowed_speaker_transitions_dict = {agent: [other_agent for other_agent in agents] for agent in agents}\n",
"\n",
"visualize_speaker_transitions_dict(allowed_speaker_transitions_dict, agents)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Possibly interesting transition paths\n",
"1. Hub and Spoke\n",
"2. Sequential Team Operations\n",
"3. Think aloud and debate"
]
},
{
"cell_type": "code",
2024-04-19 00:43:34 +08:00
"execution_count": 7,
2024-02-27 02:10:00 +08:00
"metadata": {},
"outputs": [
{
"data": {
2024-04-19 00:43:34 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAApQAAAHzCAYAAACe1o1DAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAABmHUlEQVR4nO3deVhVdeLH8TcXRHYNAcUFFfet1NyzRcUlR80Ux9zTpsmsMUubFFNBDW1atF9NM7abqWhmalqpmRaZOW4omvsCuLDLIshyl98f1k3SSgM5F/i8nseny7nnnPuBJ7if+/2exclms9kQEREREfmTTEYHEBEREZGyTYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKRYVSRERERIpFhVJEREREikWFUkRERESKxcXoACIiImVJTr6ZM2k5FJituLqYqFfNE8/KejuVik2/ASIiIn/geFI2S3fGs/VoMvHpudiues4JCPL1oFuTAEZ0DKJRdW+jYooYxslms9n+eDUREZGKJyE9l7BPY4k+kYqzyQmL9bffMn9+/u6GfkQ+2Io6vh6lmFTEWCqUIiIi1xG1K55Z6w5http+t0j+mrPJCReTExEDWvBQ+6BbmFDEcahQioiI/MobW4/z8qZjxd7PlF6NebJboxJIJOLYdJa3iIjIVaJ2xZdImQR4edMxVuyKL5F9iTgyFUoRESnzxo8fj5OTk/3f/Pnz/9R+EtJzmbXuUIlmm7nuEAnpuUWWxcTEEB4eTnh4ONu2bfvd7QsLC7njjjuKfH95eXklmlGkuFQoRUSkTCssLGTVqlVFlkVFRf2pfYV9Gov5Jo6XvBFmq42wT2OLLIuJiSEiIoKIiIg/LJT/+te/OHDgQIlmEilpKpQiIlKmbd68mbS0tCLL9u/fz5EjR25qP8eTsok+kXpTJ+DcCIvVRvSJVE4kZ9/0tkePHmXOnDm4ubmVaCaRkqZCKSIiZdrVo5EPPfTQdZf/bNWqVbRs2RI3NzdatmzJypUrCQ8Px8nJicY1fMg9+FWR9QuST5Oy9l+cfX0Ucf8ayNk3RpP2+f9hzkotsl5G9FLi5vcjbn4/Lh3YTNautZz776PEvTSQ8+8+SUH8AT764cqxlPXq1WPs2LH2bSMiIuxT2eHh4fblNpuNRx99lPz8fGbOnFmsn5HIraZCKSIiZVZeXh5r1qwB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rImLi8ZdRG6ECqWIiFR42dnZbNmyBTc3N4KCrpxM06RJE4NTiZQd+uglIiIVXs+ePSksLGTNmjXce++9REZGcueddxodS6TM0Ek5IiJSoS1YsIBnnnmGBx54gDVr1hgdR6RMUqEUEZEK6/z58wQFBeHl5UVqaqqOmRT5k3QMpYiIVFg9evTAYrGwbt06lUmRYlChFBGRCmn27NkcOXKEESNGcM899xgdR6RM05S3iIhUOCdPnqRx48bcdtttJCcnYzJpfEWkOPQbJCIiFU5ISAg2m40vv/xSZVKkBOi3SEREKpRnn32WM2fO8Nhjj9GuXTuj44iUC5ryFhGRCuPgwYPcfvvt1KhRg7Nnz2p0UqSE6DdJREQqBKvVSq9evQDYvHm
2024-02-27 02:10:00 +08:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"agents = [ConversableAgent(name=f\"Agent{i}\", llm_config=False) for i in range(5)]\n",
"allowed_speaker_transitions_dict = {\n",
" agents[0]: [agents[1], agents[2], agents[3], agents[4]],\n",
" agents[1]: [agents[0]],\n",
" agents[2]: [agents[0]],\n",
" agents[3]: [agents[0]],\n",
" agents[4]: [agents[0]],\n",
"}\n",
"\n",
"visualize_speaker_transitions_dict(allowed_speaker_transitions_dict, agents)"
]
},
{
"cell_type": "code",
2024-04-19 00:43:34 +08:00
"execution_count": 8,
2024-02-27 02:10:00 +08:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-04-19 00:43:34 +08:00
"<autogen.agentchat.conversable_agent.ConversableAgent object at 0x7f605e116260>\n"
2024-02-27 02:10:00 +08:00
]
},
{
"data": {
2024-04-19 00:43:34 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAApQAAAHzCAYAAACe1o1DAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQG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6f7ZO9E/7B7Pfr5yJGQQpibjFAKIUQJNXr0aFJSUvj888/57LPPsLGxoW7duiZt9uzZw4EDB4zJJGQlovPnz8/RX7169Zg2bVq+kkmAZcuWERERgVqtxsrKyuQ9vr6+xnfP2RnG5FXBpOsM+T4qUm9QSNcZmLwqmDk7w/L1rBDi4WSEUgghSqCwsDBq166Nl5cXV65cAUCn06HRaEw2z/Tp04cVK1ag1WrR6XTGeyqVCoPBQMWKFYmPj8dgMBhHOvMrKSmJFStWcPXqVa5evUpkZCShoaFcunQJg8FAy5YtGTF9Ph9vvlToz51tRm/vHGWOhBAFJwmlEEKUQHXq1OHcuXOcPHmSBg0a3Lfdli1b2LNnDwaDgc8++4ymTZsSEBBAqVKlaNq0KY0bN2b8+PHMnj2b7du3065dO7PGuWfPHoaMHEN42FnTGyo1artSWJepjIN3Rxzr+xtvJZ7cTMq5vWTGRGJIvYOiKGgc3bCtVB/nli9i5V4JG62abRPaUsnt/pt+hBB5JwmlEEKUMD///DMvv/wyffr0Yfny5Xl6RqfTYWVlxdChQ/n9999N7sXExFCmTBnat2/Ptm3bzB5vg+4jCf4n5xT73Vz8h+PcvDcAN//4H2nhJ3Ntp7K2o9xLs7A
2024-02-27 02:10:00 +08:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Sequential Team Operations\n",
"# Create an empty directed graph\n",
"\n",
"speaker_transitions_dict = {}\n",
"teams = [\"A\", \"B\", \"C\"]\n",
"team_size = 5\n",
"\n",
"\n",
"def get_agent_of_name(agents, name) -> ConversableAgent:\n",
" for agent in agents:\n",
" if agent.name == name:\n",
" return agent\n",
"\n",
"\n",
"# Create a list of 15 agents 3 teams x 5 agents\n",
"agents = [ConversableAgent(name=f\"{team}{i}\", llm_config=False) for team in teams for i in range(team_size)]\n",
"\n",
"# Loop through each team and add members and their connections\n",
"for team in teams:\n",
" for i in range(team_size):\n",
" member = f\"{team}{i}\"\n",
" # Connect each member to other members of the same team\n",
" speaker_transitions_dict[get_agent_of_name(agents, member)] = [\n",
" get_agent_of_name(agents, name=f\"{team}{j}\") for j in range(team_size) if j != i\n",
" ]\n",
"\n",
"# Team leaders connection\n",
"print(get_agent_of_name(agents, name=\"B0\"))\n",
"speaker_transitions_dict[get_agent_of_name(agents, \"A0\")].append(get_agent_of_name(agents, name=\"B0\"))\n",
"speaker_transitions_dict[get_agent_of_name(agents, \"B0\")].append(get_agent_of_name(agents, name=\"C0\"))\n",
"\n",
"visualize_speaker_transitions_dict(speaker_transitions_dict, agents)"
]
},
{
"cell_type": "code",
2024-04-19 00:43:34 +08:00
"execution_count": 9,
2024-02-27 02:10:00 +08:00
"metadata": {},
"outputs": [
{
"data": {
2024-04-19 00:43:34 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAApQAAAHzCAYAAACe1o1DAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAABEnklEQVR4nO3deVjVdeL+/xvEEyEiIh5QEVTEFc01l1Q2c8HKJU2nxbFtpmVqatqdqbRpbPI3TXv9mpopJytNc0tURIGDmhkuuKASIoKobCIgILJ+/3Dio6klgrzP8nxcV1dwzuFwy1/3db/OOW+n2traWgEAAABXydnoAAAAALBtFEoAAAA0CIUSAAAADUKhBAAAQINQKAEAANAgFEoAAAA0CIUSAAAADUKhBAAAQINQKAEAANAgFEoAAAA0CIUSAAAADUKhBAAAQINQKAEAANAgFEoAAAA0CIUSAAAADUKhBAAAQINQKAEAANAgFEoAAAA0CIUSAAAADUKhBAAAQINQKAEAANAgFEoAAAA0CIUSAAAADUKhBAAAQINQKAEAANAgFEoAAAA0CIUSAAAADUKhBAAAQINQKAEAANAgFEoAAAA0CIUSAAAADeIQhbK2tlaHDx9WbW2t0VEAAADsjkMUysTERAUGBmrQoEFau3YtxRIAAKAROUShLC4uliQ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dOXKk7j4fH58LnttsNtd9nZ6eXu+/FwAAgLWwmkJ5/go5derUC/5//v07duzQ0aNHJUm+vr764osvFBkZqbfffltDhw696HnL03eppqxIkuTaqZ+u69hbTi4mXd/1RjVrda7klR/eqer/PeZ81wcNVevQWXILGqJWw6bV3V556oRqJXl16qmgoP/7XEp/f3+NGDFCI0aMkL+/v0pLS+vuM5lMFzz3+d+f/zgAAABbYxWF8vTp04qKipIkeXl5KTw8XJI0ZcoUNWt27vKIixcvVm1trQ4fPlz3cwMGDFDz5s3rvj//GPknlQXH6r4uP7xDOV88V/dfdVHO/+6pVeXJrIt+1rVjcN3Xztd71H1dc/ZcAayoqvnFf1eLFi3qvj579uwF91VUVFzycQAAALbGxegAkrRixQqVl5dLkgoKCi4oiT/JyMjQ1q1bL7jNycmp0TLUVpZfdJuzq/t5v+u87v2/43aTyy/38U6dOtV9nZOTc8F92dn/97rNzp071ycqAACAVbGKQvnVV19d0eMWLVqke+65p+77Xbt2qbq6um7F/HnhlKTmXh3qvm4RHCHvW5686DE1leVybu5ar8xOkjq1aaEdzv9XKmtqLlwsg4OD1apVKxUVFSkjI0PHjh1Thw4dVFtbq++//77ucSNHjqzX7wYAALAmhhfKkydPKiYmRpLUsmVLzZs374L7Kyoq9NRTT0mSlixZojfffFMdO3bU0aNHdfz4cc2cOVN33XWXoqOjLyhpbdxNOivJtVN/Obu1Uk1ZkUr3xcr5endd36m/amtrVFWUo7NZB1SZm672D176jTmX49/GTS2uc1Hr1q3rblu3bp1GjRolV1dX9enTR61atdJ9992nN998U7W1tfrNb36jp59+WlFRUUpJSZEkDRo0iI8MAgAANs3wz6H86KOP9NBDD0mSbr/9di1duvSix/Tv37/uajkbNmxQUVGRpk6dqp9H79Onj/bu3Svpws+hPJOWqNxl88690/sSmnmY5ffIfyT9/HMon5B739GSpPKMPcr56tw7ut37ROipV9/WnNt6Kz8/X35+fhe9RjIuLk6hoaG/eKUcT09PJSQkcKUcAABg0wx/U875x9233XbbJR9z66231n29aNEiTZkyRV9//bV69eolk8mknj176ssvv1RERETd48J6+9V9DuX1gYPVbtabatE7TM1aekvOLnK+3kP
2024-02-27 02:10:00 +08:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"agents = [ConversableAgent(name=f\"Agent{i}\", llm_config=False) for i in range(2)]\n",
"allowed_speaker_transitions_dict = {\n",
" agents[0]: [agents[0], agents[1]],\n",
" agents[1]: [agents[0], agents[1]],\n",
"}\n",
"\n",
"visualize_speaker_transitions_dict(allowed_speaker_transitions_dict, agents)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Demonstration"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`GroupChat` now takes in two optional arguments.\n",
"- allowed_or_disallowed_speaker_transitions: The keys are source agents, and the values are agents that the key agent can/can't transit to, depending on speaker_transitions_type. Default is None, which means all agents can transit to all other agents.\n",
"- speaker_transitions_type: whether the speaker_transitions_type is a dictionary containing lists of allowed agents or disallowed agents. \"allowed\" means the `allowed_or_disallowed_speaker_transitions` is a dictionary containing lists of allowed agents."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Team Operations\n"
]
},
{
"cell_type": "code",
2024-04-19 00:43:34 +08:00
"execution_count": 10,
2024-02-27 02:10:00 +08:00
"metadata": {},
"outputs": [
{
"data": {
2024-04-19 00:43:34 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABMQAAAP7CAYAAAC0u1IMAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd1yVZePH8e85ICDDAYjiQFQ09yBHmri3pqI5srIsR8MMzTIzs+xJ0wamttO0NDVzp7lIHGmmOXMPBBeyRJaMw+H3h0/88knFAd7A+bxfL18P5z73ue7vwSeEL9d13aasrKwsAQAAAAA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3L1Kbg27a6s1SyejEuXn5WbIewMAAAAA5C4KMQCFwvydEbIzm3T5j6XZZZjJ0UVlnvpY9m6e2ec5V2uq4k37SGY7meyKqOzQr2Rf7P+fL+pbX+c+HyRrcrykLKVfPCEnd2/N+z1Cb3evdZ/fFQAAAAAgL7CpPoBCYdOxKGVas5RyZGv2sWKNelxXhv3NzqWE7Iq6qYhnhevKMEky2ReRfbFS//+4iJMyrVnadDwq78IDAAAAAO4rCjEABV5SmkURcSmypl+9bt8wx/J3PqMrIz5S6ZdOS5JMDkXlVOHaGBGxKUpOs+ROYAAAAACAoSjEABR44bHJypJkTUu+7ri9m/sdjZN5NUHRS/4jWTMlSSVaDpTZ8drdJbMknYlNvsWrAQAAAAAFBYUYgAIv3WKVJJkdXa47bkmMu+0xLElxujT/dWVEn5EkuTXqqWI
2024-02-27 02:10:00 +08:00
"text/plain": [
"<Figure size 1200x1000 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Create an empty directed graph\n",
"agents = []\n",
"speaker_transitions_dict = {}\n",
"secret_values = {}\n",
"\n",
"# Outer loop for prefixes 'A', 'B', 'C'\n",
"for prefix in [\"A\", \"B\", \"C\"]:\n",
" # Add 3 nodes with each prefix to the graph using a for loop\n",
" for i in range(3):\n",
" node_id = f\"{prefix}{i}\"\n",
" secret_value = random.randint(1, 5) # Generate a random secret value\n",
" secret_values[node_id] = secret_value\n",
"\n",
" # Create an AssistantAgent for each node (assuming AssistantAgent is a defined class)\n",
" agents.append(\n",
" AssistantAgent(\n",
" name=node_id,\n",
" system_message=f\"\"\"Your name is {node_id}.\n",
" Do not respond as the speaker named in the NEXT tag if your name is not in the NEXT tag. Instead, suggest a relevant team leader to handle the mis-tag, with the NEXT: tag.\n",
"\n",
" You have {secret_value} chocolates.\n",
"\n",
" The list of players are [A0, A1, A2, B0, B1, B2, C0, C1, C2].\n",
"\n",
" Your first character of your name is your team, and your second character denotes that you are a team leader if it is 0.\n",
" CONSTRAINTS: Team members can only talk within the team, whilst team leader can talk to team leaders of other teams but not team members of other teams.\n",
"\n",
" You can use NEXT: to suggest the next speaker. You have to respect the CONSTRAINTS, and can only suggest one player from the list of players, i.e., do not suggest A3 because A3 is not from the list of players.\n",
" Team leaders must make sure that they know the sum of the individual chocolate count of all three players in their own team, i.e., A0 is responsible for team A only.\n",
"\n",
" Keep track of the player's tally using a JSON format so that others can check the total tally. Use\n",
" A0:?, A1:?, A2:?,\n",
" B0:?, B1:?, B2:?,\n",
" C0:?, C1:?, C2:?\n",
"\n",
" If you are the team leader, you should aggregate your team's total chocolate count to cooperate.\n",
" Once the team leader know their team's tally, they can suggest another team leader for them to find their team tally, because we need all three team tallys to succeed.\n",
" Use NEXT: to suggest the next speaker, e.g., NEXT: A0.\n",
"\n",
" Once we have the total tally from all nine players, sum up all three teams' tally, then terminate the discussion using TERMINATE.\n",
"\n",
" \"\"\",\n",
" llm_config=config_list_gpt4,\n",
" )\n",
" )\n",
" speaker_transitions_dict[agents[-1]] = []\n",
"\n",
" # Add edges between nodes with the same prefix using a nested for loop\n",
" for source_node in range(3):\n",
" source_id = f\"{prefix}{source_node}\"\n",
" for target_node in range(3):\n",
" target_id = f\"{prefix}{target_node}\"\n",
" if source_node != target_node: # To avoid self-loops\n",
" speaker_transitions_dict[get_agent_of_name(agents, source_id)].append(\n",
" get_agent_of_name(agents, name=target_id)\n",
" )\n",
"\n",
"\n",
"# Adding edges between teams\n",
"speaker_transitions_dict[get_agent_of_name(agents, \"A0\")].append(get_agent_of_name(agents, name=\"B0\"))\n",
"speaker_transitions_dict[get_agent_of_name(agents, \"A0\")].append(get_agent_of_name(agents, name=\"C0\"))\n",
"speaker_transitions_dict[get_agent_of_name(agents, \"B0\")].append(get_agent_of_name(agents, name=\"A0\"))\n",
"speaker_transitions_dict[get_agent_of_name(agents, \"B0\")].append(get_agent_of_name(agents, name=\"C0\"))\n",
"speaker_transitions_dict[get_agent_of_name(agents, \"C0\")].append(get_agent_of_name(agents, name=\"A0\"))\n",
"speaker_transitions_dict[get_agent_of_name(agents, \"C0\")].append(get_agent_of_name(agents, name=\"B0\"))\n",
"\n",
"\n",
"# Visualization only\n",
"graph = nx.DiGraph()\n",
"\n",
"# Add nodes\n",
"graph.add_nodes_from([agent.name for agent in agents])\n",
"\n",
"# Add edges\n",
"for key, value in speaker_transitions_dict.items():\n",
" for agent in value:\n",
" graph.add_edge(key.name, agent.name)\n",
"\n",
"# Visualize\n",
"# Draw the graph with secret values annotated\n",
"plt.figure(figsize=(12, 10))\n",
"pos = nx.spring_layout(graph) # positions for all nodes\n",
"\n",
"# Draw nodes with their colors\n",
"nx.draw(graph, pos, with_labels=True, font_weight=\"bold\")\n",
"\n",
"# Annotate secret values\n",
"for node, (x, y) in pos.items():\n",
" secret_value = secret_values[node]\n",
" plt.text(x, y + 0.1, s=f\"Secret: {secret_value}\", horizontalalignment=\"center\")\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
2024-04-19 00:43:34 +08:00
"execution_count": 11,
2024-02-27 02:10:00 +08:00
"metadata": {},
"outputs": [],
"source": [
"# Termination message detection\n",
"\n",
"\n",
"def is_termination_msg(content) -> bool:\n",
" have_content = content.get(\"content\", None) is not None\n",
" if have_content and \"TERMINATE\" in content[\"content\"]:\n",
" return True\n",
" return False\n",
"\n",
"\n",
"# Terminates the conversation when TERMINATE is detected.\n",
"user_proxy = autogen.UserProxyAgent(\n",
" name=\"User_proxy\",\n",
" system_message=\"Terminator admin.\",\n",
" code_execution_config=False,\n",
" is_termination_msg=is_termination_msg,\n",
" human_input_mode=\"NEVER\",\n",
")\n",
"\n",
"agents.append(user_proxy)"
]
},
{
"cell_type": "code",
2024-04-19 00:43:34 +08:00
"execution_count": 12,
2024-02-27 02:10:00 +08:00
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:root:Warning: There are isolated agent nodes, there are not incoming nor outgoing edges. Isolated agents: ['User_proxy']\n",
"WARNING:root:Warning: The set of agents in allowed_speaker_transitions do not match agents. Offending agents: ['User_proxy']\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mA0\u001b[0m (to chat_manager):\n",
"\n",
"\n",
" There are 9 players in this game, split equally into Teams A, B, C. Therefore each team has 3 players, including the team leader.\n",
" The task is to find out the sum of chocolate count from all nine players. I will now start with my team.\n",
" NEXT: A1\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mA1\u001b[0m (to chat_manager):\n",
"\n",
2024-04-19 00:43:34 +08:00
"As the team leader of Team A, it's my responsibility to gather the chocolate count from my team members. I have 1 chocolate. \n",
"\n",
"A0:?, A1:1, A2:?,\n",
"\n",
"B0:?, B1:?, B2:?,\n",
2024-02-27 02:10:00 +08:00
"\n",
"C0:?, C1:?, C2:?\n",
"\n",
"NEXT: A2\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mA2\u001b[0m (to chat_manager):\n",
"\n",
2024-04-19 00:43:34 +08:00
"I have 5 chocolates.\n",
"\n",
"A0:?, A1:1, A2:5,\n",
"\n",
"B0:?, B1:?, B2:?,\n",
2024-02-27 02:10:00 +08:00
"\n",
"C0:?, C1:?, C2:?\n",
"\n",
"NEXT: A0\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mA0\u001b[0m (to chat_manager):\n",
"\n",
2024-04-19 00:43:34 +08:00
"I have 1 chocolate. Now that I have the counts from A1 and A2, I can calculate our team's total.\n",
"\n",
"A0:1, A1:1, A2:5,\n",
"\n",
"B0:?, B1:?, B2:?,\n",
2024-02-27 02:10:00 +08:00
"\n",
"C0:?, C1:?, C2:?\n",
"\n",
2024-04-19 00:43:34 +08:00
"Team A's total tally is 7 chocolates. It's time to find out the tally from another team. I'll pass this to the next team leader.\n",
"\n",
2024-02-27 02:10:00 +08:00
"NEXT: B0\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mB0\u001b[0m (to chat_manager):\n",
"\n",
2024-04-19 00:43:34 +08:00
"As the team leader of Team B, it's my responsibility to gather the chocolate count from my team members. I have 1 chocolate.\n",
"\n",
"A0:1, A1:1, A2:5,\n",
"\n",
"B0:1, B1:?, B2:?,\n",
2024-02-27 02:10:00 +08:00
"\n",
"C0:?, C1:?, C2:?\n",
"\n",
2024-04-19 00:43:34 +08:00
"Now, I need to find out the chocolate counts from B1 and B2.\n",
"\n",
2024-02-27 02:10:00 +08:00
"NEXT: B1\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mB1\u001b[0m (to chat_manager):\n",
"\n",
2024-04-19 00:43:34 +08:00
"I have 3 chocolates.\n",
"\n",
"A0:1, A1:1, A2:5,\n",
"\n",
"B0:1, B1:3, B2:?,\n",
2024-02-27 02:10:00 +08:00
"\n",
"C0:?, C1:?, C2:?\n",
"\n",
"NEXT: B2\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mB2\u001b[0m (to chat_manager):\n",
"\n",
2024-04-19 00:43:34 +08:00
"I have 4 chocolates. Now that I have the counts from B0 and B1, I can calculate our team's total.\n",
"\n",
"A0:1, A1:1, A2:5,\n",
"\n",
"B0:1, B1:3, B2:4,\n",
2024-02-27 02:10:00 +08:00
"\n",
"C0:?, C1:?, C2:?\n",
"\n",
2024-04-19 00:43:34 +08:00
"Team B's total tally is 8 chocolates. It's time to find out the tally from the last team. I'll pass this to the next team leader.\n",
"\n",
2024-02-27 02:10:00 +08:00
"NEXT: C0\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mB0\u001b[0m (to chat_manager):\n",
"\n",
2024-04-19 00:43:34 +08:00
"I'm sorry for any confusion, but it seems there's been a misunderstanding in the flow of communication. As B0, I should be the one to summarize the tally for Team B and pass the conversation to the next team leader. Let me correct that.\n",
2024-02-27 02:10:00 +08:00
"\n",
2024-04-19 00:43:34 +08:00
"A0:1, A1:1, A2:5,\n",
2024-02-27 02:10:00 +08:00
"\n",
2024-04-19 00:43:34 +08:00
"B0:1, B1:3, B2:4,\n",
"\n",
"C0:?, C1:?, C2:?\n",
"\n",
"With the counts from B1 and B2, Team B's total tally is indeed 8 chocolates. Now, it's time to find out the tally from Team C. I'll pass this to the next team leader.\n",
"\n",
"NEXT: C0\n",
2024-02-27 02:10:00 +08:00
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mC0\u001b[0m (to chat_manager):\n",
"\n",
2024-04-19 00:43:34 +08:00
"As the team leader of Team C, it's my responsibility to gather the chocolate count from my team members. I have 3 chocolates.\n",
2024-02-27 02:10:00 +08:00
"\n",
2024-04-19 00:43:34 +08:00
"A0:1, A1:1, A2:5,\n",
"\n",
"B0:1, B1:3, B2:4,\n",
"\n",
"C0:3, C1:?, C2:?\n",
"\n",
"Now, I need to find out the chocolate counts from C1 and C2.\n",
"\n",
"NEXT: C1\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mC1\u001b[0m (to chat_manager):\n",
"\n",
"I have 3 chocolates.\n",
"\n",
"A0:1, A1:1, A2:5,\n",
"\n",
"B0:1, B1:3, B2:4,\n",
"\n",
"C0:3, C1:3, C2:?\n",
2024-02-27 02:10:00 +08:00
"\n",
"NEXT: C2\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[33mC2\u001b[0m (to chat_manager):\n",
"\n",
2024-04-19 00:43:34 +08:00
"I have 2 chocolates. Now that I have the counts from C0 and C1, I can calculate our team's total.\n",
"\n",
"A0:1, A1:1, A2:5,\n",
"\n",
"B0:1, B1:3, B2:4,\n",
"\n",
"C0:3, C1:3, C2:2\n",
2024-02-27 02:10:00 +08:00
"\n",
2024-04-19 00:43:34 +08:00
"Team C's total tally is 8 chocolates. Now that we have the tallies from all teams, we can sum them up.\n",
2024-02-27 02:10:00 +08:00
"\n",
2024-04-19 00:43:34 +08:00
"Team A's total is 7 chocolates, Team B's total is 8 chocolates, and Team C's total is 8 chocolates. The grand total is 23 chocolates.\n",
2024-02-27 02:10:00 +08:00
"\n",
2024-04-19 00:43:34 +08:00
"TERMINATE\n",
2024-02-27 02:10:00 +08:00
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"data": {
"text/plain": [
2024-04-19 00:43:34 +08:00
"ChatResult(chat_id=None, chat_history=[{'content': '\\n There are 9 players in this game, split equally into Teams A, B, C. Therefore each team has 3 players, including the team leader.\\n The task is to find out the sum of chocolate count from all nine players. I will now start with my team.\\n NEXT: A1', 'role': 'assistant'}, {'content': \"As the team leader of Team A, it's my responsibility to gather the chocolate count from my team members. I have 1 chocolate. \\n\\nA0:?, A1:1, A2:?,\\n\\nB0:?, B1:?, B2:?,\\n\\nC0:?, C1:?, C2:?\\n\\nNEXT: A2\", 'name': 'A1', 'role': 'user'}, {'content': 'I have 5 chocolates.\\n\\nA0:?, A1:1, A2:5,\\n\\nB0:?, B1:?, B2:?,\\n\\nC0:?, C1:?, C2:?\\n\\nNEXT: A0', 'name': 'A2', 'role': 'user'}, {'content': \"I have 1 chocolate. Now that I have the counts from A1 and A2, I can calculate our team's total.\\n\\nA0:1, A1:1, A2:5,\\n\\nB0:?, B1:?, B2:?,\\n\\nC0:?, C1:?, C2:?\\n\\nTeam A's total tally is 7 chocolates. It's time to find out the tally from another team. I'll pass this to the next team leader.\\n\\nNEXT: B0\", 'role': 'assistant'}, {'content': \"As the team leader of Team B, it's my responsibility to gather the chocolate count from my team members. I have 1 chocolate.\\n\\nA0:1, A1:1, A2:5,\\n\\nB0:1, B1:?, B2:?,\\n\\nC0:?, C1:?, C2:?\\n\\nNow, I need to find out the chocolate counts from B1 and B2.\\n\\nNEXT: B1\", 'name': 'B0', 'role': 'user'}, {'content': 'I have 3 chocolates.\\n\\nA0:1, A1:1, A2:5,\\n\\nB0:1, B1:3, B2:?,\\n\\nC0:?, C1:?, C2:?\\n\\nNEXT: B2', 'name': 'B1', 'role': 'user'}, {'content': \"I have 4 chocolates. Now that I have the counts from B0 and B1, I can calculate our team's total.\\n\\nA0:1, A1:1, A2:5,\\n\\nB0:1, B1:3, B2:4,\\n\\nC0:?, C1:?, C2:?\\n\\nTeam B's total tally is 8 chocolates. It's time to find out the tally from the last team. I'll pass this to the next team leader.\\n\\nNEXT: C0\", 'name': 'B2', 'role': 'user'}, {'content': \"I'm sorry for any confusion, but it seems there's been a misunderstanding in the flow of communication. As B0, I should be the one to summarize the tally for Team B and pass the conversation to the next team leader. Let me correct that.\\n\\nA0:1, A1:1, A2:5,\\n\\nB0:1, B1:3, B2:4,\\n\\nC0:?, C1:?, C2:?\\n\\nWith the counts from B1 and B2, Team B's total tally is indeed 8 chocolates. Now, it's time to find out the tally from Team C. I'll pass this to the next team leader.\\n\\nNEXT: C0\", 'name': 'B0', 'role': 'user'}, {'content': \"As the team leader of Team C, it's my responsibility to gather the chocolate count from my team members. I have 3 chocolates.\\n\\nA0:1, A1:1, A2:5,\\n\\nB0:1, B1:3, B2:4,\\n\\nC0:3, C1:?, C2:?\\n\\nNow, I need to find out the chocolate counts from C1 and C2.\\n\\nNEXT: C1\", 'name': 'C0', 'role': 'user'}, {'content': 'I have 3 chocolates.\\n\\nA0:1, A1:1, A2:5,\\n\\nB0:1, B1:3, B2:4,\\n\\nC0:3, C1:3, C2:?\\n\\nNEXT: C2', 'name': 'C1', 'role': 'user'}, {'content': \"I have 2 chocolates. Now that I have the counts from C0 and C1, I can calculate our team's total.\\n\\nA0:1, A1:1, A2:5,\\n\\nB0:1, B1:3, B2:4,\\n\\nC0:3, C1:3, C2:2\\n\\nTeam C's total tally is 8 chocolates. Now that we have the tallies from all teams, we can sum them up.\\n\\nTeam A's total is 7 chocolates, Team B's total is 8 chocolates, and Team C's total is 8 chocolates. The grand total is 23 chocolates.\\n\\nTERMINATE\", 'name': 'C2', 'role': 'user'}], summary=\"I have 2 chocolates. Now that I have the counts from C0 and C1, I can calculate our team's total.\\n\\nA0:1, A1:1, A2:5,\\n\\nB0:1, B1:3, B2:4,\\n\\nC0:3, C1:3, C2:2\\n\\nTeam C's total tally is 8 chocolates. Now that we have the tallies from all teams, we can sum them up.\\n\\nTeam A's total is 7 chocolates, Team B's total is 8 chocolates, and Team C's total is 8 chocolates. The grand total is 23 chocolates.\\n\\n\", cost={'usage_including_cached_inference': {'total_cost': 0.5525399999999999, 'gpt-4': {'cost': 0.5525399999999999, 'prompt_tokens': 18174, 'completion_tokens': 122, 'total_tokens'
2024-02-27 02:10:00 +08:00
]
},
2024-04-19 00:43:34 +08:00
"execution_count": 12,
2024-02-27 02:10:00 +08:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"group_chat = GroupChat(\n",
" agents=agents,\n",
" messages=[],\n",
" max_round=20,\n",
" allowed_or_disallowed_speaker_transitions=speaker_transitions_dict,\n",
" speaker_transitions_type=\"allowed\",\n",
")\n",
"\n",
"\n",
"# Create the manager\n",
"manager = autogen.GroupChatManager(\n",
" groupchat=group_chat,\n",
" llm_config=config_list_gpt4,\n",
" code_execution_config=False,\n",
" is_termination_msg=is_termination_msg,\n",
")\n",
"\n",
"\n",
"# Initiates the chat with Alice\n",
"agents[0].initiate_chat(\n",
" manager,\n",
" message=\"\"\"\n",
" There are 9 players in this game, split equally into Teams A, B, C. Therefore each team has 3 players, including the team leader.\n",
" The task is to find out the sum of chocolate count from all nine players. I will now start with my team.\n",
" NEXT: A1\"\"\",\n",
")"
]
}
],
"metadata": {
2024-03-02 22:27:11 +08:00
"front_matter": {
"description": "Explore the demonstration of the Finite State Machine implementation, which allows the user to input speaker transition constraints.",
"tags": [
"orchestration"
]
},
2024-02-27 02:10:00 +08:00
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2024-04-19 00:43:34 +08:00
"version": "3.10.13"
2024-02-27 02:10:00 +08:00
}
},
"nbformat": 4,
"nbformat_minor": 4
}