{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Transform Messages for Non-OpenAI Models\n",
    "\n",
    "There are a large variety of models available beyond OpenAI's and they all have different capabilities. Smaller context windows and different API's can require tweaks to your workflow in order to work with them.\n",
    "\n",
    "If you're new to Transform Messages, see the [introduction to Transform Messages](/docs/topics/handling_long_contexts/intro_to_transform_messages).\n",
    "\n",
    "## Reducing context sizes\n",
    "\n",
    "Although context windows are increasing, there are still a large number of models that have context windows (e.g. 2K, 4K, or 8K tokens) which may be overwhelmed by your workflow's messages.\n",
    "\n",
    "To handle longer contexts using transforms, essentially reducing them effectively for smaller context windows, please see the page on [compressing text](/docs/topics/handling_long_contexts/compressing_text_w_llmligua).\n",
    "\n",
    "## Incorporating an agent's name\n",
    "\n",
    "Interestingly, the agent's name, such as Jack in the below example, is not included in messages when using non-OpenAI models. This means that there is no way of the name being known by the model during inference, unless we include it in the body of the message text.\n",
    "\n",
    "```python\n",
    "comedian = ConversableAgent(\n",
    "    name=\"Jack\", # Not included in messages for non-OpenAI inference\n",
    "    llm_config=phi2,\n",
    "    system_message=\"Your name is Jack and you are a comedian.\",\n",
    ")\n",
    "```\n",
    "\n",
    "When using OpenAI models, the name field is included and examples in the AutoGen documentation may rely on this fact. Therefore, it may not be an issue in your existing workflows, however it's important to be aware of and be able to cater for it.\n",
    "\n",
    "In the simple two-agent chat example, below, we will use a `TextMessageContentName` transform, available from the Transforms module, to add in the name of the agents to the messages.\n",
    "\n",
    "As we won't be using OpenAI, we will use the Anthropic client to demonstrate.\n",
    "\n",
    "We'll start by importing our modules and setting our config."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "from autogen import ConversableAgent\n",
    "\n",
    "config_list_claude = [\n",
    "    {\n",
    "        \"model\": \"claude-3-5-sonnet-20240620\",\n",
    "        \"api_key\": os.getenv(\"ANTHROPIC_API_KEY\"),\n",
    "        \"api_type\": \"anthropic\",\n",
    "        \"cache_seed\": None,  # Ensure we're not caching any results\n",
    "    }\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we add two agents, both comedians who will make up jokes about the other using their name."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "cathy = ConversableAgent(\n",
    "    \"Cathy\",\n",
    "    system_message=\"Your name is Cathy and you are a part of a duo of comedians.\",\n",
    "    llm_config={\"config_list\": config_list_claude},\n",
    "    human_input_mode=\"NEVER\",\n",
    ")\n",
    "\n",
    "joe = ConversableAgent(\n",
    "    \"Joe\",\n",
    "    system_message=\"Your name is Joe and you are a part of a duo of comedians.\",\n",
    "    llm_config={\"config_list\": config_list_claude},\n",
    "    human_input_mode=\"NEVER\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's start the chat without using the transform and see how it performs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[33mJoe\u001b[0m (to Cathy):\n",
      "\n",
      "People say I have a funny name, tell me a joke about it.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33mCathy\u001b[0m (to Joe):\n",
      "\n",
      "As Cathy, part of a comedy duo, I'd need to know your actual name to craft a personalized joke about it. Without that information, I can't create a specific joke tailored to your name. However, I can offer a more general joke about names if you'd like. Let me know if you want to share your name or if you'd prefer a different kind of joke!\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33mJoe\u001b[0m (to Cathy):\n",
      "\n",
      "I apologize for the confusion. You're right that as Cathy, you wouldn't know my name or background. I made a mistake in my previous response by assuming a context that wasn't provided. Thank you for the professional way you handled that.\n",
      "\n",
      "As Joe, the other half of your comedy duo, I'll play along with your prompt:\n",
      "\n",
      "\"Well, Cathy, you know what they say - people in glass houses shouldn't throw stones. But with a name like yours, maybe you should consider moving into a stone house! At least then when people say 'Cathy who?' you can say 'Cathy Stone, of course!'\"\n",
      "\n",
      "How's that for a quick improvised joke about your name, partner?\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33mCathy\u001b[0m (to Joe):\n",
      "\n",
      "Oh Joe, you crack me up! That's why we're such a great duo. I love how you turned that around on me. Let me give it a shot:\n",
      "\n",
      "\"Well, Joe, speaking of stones, I guess with a partner like you, I'm stuck between a rock and a hard place. But hey, at least with you around, I'll never be accused of being the average Joe in this act!\"\n",
      "\n",
      "How's that for a comeback, partner? I think we're really on a roll here. Should we take this act on the road?\n",
      "\n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "result = joe.initiate_chat(cathy, message=\"People say I have a funny name, tell me a joke about it.\", max_turns=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As we can see from the chat, Cathy doesn't know Joe's name at the start.\n",
    "\n",
    "Now, we'll create a transform that injects the names into the messages and apply that transform to both agents."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import our transforms\n",
    "from autogen.agentchat.contrib.capabilities import transform_messages\n",
    "from autogen.agentchat.contrib.capabilities.transforms import TextMessageContentName\n",
    "\n",
    "# Create a name transform\n",
    "# This will inject the agent's name for a message into the start of the message content.\n",
    "# E.g. \"'Jack' said\\n...\"\n",
    "name_transform = TextMessageContentName(position=\"start\", format_string=\"'{name}' said:\\n\")\n",
    "\n",
    "# Create the TransformMessages that will be applied.\n",
    "# In this case we are only putting in one transform but you could\n",
    "# stack the transforms if you also wanted to do others, like\n",
    "# compress the text. Transforms are performed sequentially.\n",
    "context_handling = transform_messages.TransformMessages(transforms=[name_transform])\n",
    "\n",
    "# Add it to both agents so when they run inference it will apply to the messages\n",
    "context_handling.add_to_agent(cathy)\n",
    "context_handling.add_to_agent(joe)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's try that chat again now that we're injecting the names."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[33mJoe\u001b[0m (to Cathy):\n",
      "\n",
      "People say I have a funny name, tell me a joke about it.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33m1 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mCathy\u001b[0m (to Joe):\n",
      "\n",
      "Hey there Joe! I'm Cathy, one half of a comedy duo. You know, having a short name like Joe can be pretty fun to play with. Here's a little joke for you:\n",
      "\n",
      "Why did Joe's friends call him \"Volcano\"?\n",
      "Because he was always erupting with short outbursts!\n",
      "\n",
      "Ba dumb tss! Okay, maybe not my best work, but I promise our duo's material is much funnier on stage. Names can be great comedy fodder - short ones, long ones, unusual ones. The key is finding the right angle. Got any funny stories about your name you'd like to share? Those personal anecdotes often make for the best laughs!\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33m2 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mJoe\u001b[0m (to Cathy):\n",
      "\n",
      "Thanks for the setup, Cathy! I like your joke - short and sweet, just like my name. Speaking of my name, here's a little quip I've used before:\n",
      "\n",
      "You know, I've always felt my parents really phoned it in when naming me. They must've been like, \"We need to name this kid... eh, Joe. Done. What's for dinner?\"\n",
      "\n",
      "But hey, at least it's easy to spell. Although sometimes I wonder if I should jazz it up a bit. Maybe go by \"Jo-seph\" or \"Joe-tastic.\" What do you think, Cathy? Any suggestions for spicing up a plain old \"Joe\"?\n",
      "\n",
      "And you're right, personal stories about names can be comedy gold. I once had a telemarketer absolutely butcher my name. They called and asked for \"Joo.\" I told them there's no Joo here, just a Joe. They apologized and asked for \"Hoe\" instead. At that point, I just had to laugh and hang up!\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33m3 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mCathy\u001b[0m (to Joe):\n",
      "\n",
      "'Cathy' said:\n",
      "Oh Joe, you're a natural! I'm loving your material. That telemarketer story had me in stitches - from Joe to Joo to Hoe, what a wild ride! \n",
      "\n",
      "As for jazzing up your name, I've got a few suggestions that might tickle your funny bone:\n",
      "\n",
      "1. \"Joe-normous\" - for when you're feeling larger than life.\n",
      "2. \"Joevius Maximus\" - if you're going for that Roman emperor vibe.\n",
      "3. \"Joe-pacabra\" - half man, half mysterious creature.\n",
      "4. \"Joehemoth\" - for those days when you feel particularly beastly.\n",
      "5. \"Average Joe-seidon\" - god of the sea... and mediocrity.\n",
      "\n",
      "But honestly, Joe, I think you're selling yourself short (pun intended for your short name). Your delivery is spot-on, and you've got a great sense of timing. Have you ever considered doing stand-up? With material like that, you could be the next big thing in comedy. \n",
      "\n",
      "Just imagine the headline: \"Plain Old Joe Takes Comedy World by Storm!\" Now that's a name that would turn heads, don't you think?\n",
      "\n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "result = joe.initiate_chat(cathy, message=\"People say I have a funny name, tell me a joke about it.\", max_turns=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can see from this conversation that Cathy uses Joe's name in her first response message, showing that incorporating the name using a transform has enabled the Cathy agent to *recognise* Joe.\n",
    "\n",
    "Where the transform used above becomes essential is in a Group Chat using the `auto` selection mode (default), when the Group Chat Manager is selecting an agent based on their `name`.\n",
    "\n",
    "## Transforms in group chats\n",
    "\n",
    "As noted above, it is important when using non-OpenAI models to inject the agent's name into the messages when you are using `auto` agent selection mode. By doing so, you are giving the model the best chance at understanding which agent belongs to each message.\n",
    "\n",
    "Additionally, group chats can involve a large number of messages and, therefore, tokens. So, to assist with keeping the context used within your model's context window you can use a compression transform.\n",
    "\n",
    "Below is a group chat example that incorporates these two transforms and relies on the LLM using agent names to determine and select the next agent.\n",
    "\n",
    "We'll use Anthropic's Claude 3.5 Sonnet config from the previous example as the LLM for all agents and the group chat manager (which selects the next agent to speak).\n",
    "\n",
    "The scenario in the example is the production of two kid-friendly long-form articles on cloud formations.\n",
    "\n",
    "Let's start by creating our three team members:\n",
    "\n",
    "- **Subject_Expert** will select a cloud formation and provide some bullet points about it.\n",
    "- **Writer** will write long-form content, about 2,000 words, for the selected cloud formation based on the bullet points.\n",
    "- **Scheduler** is responsible for delivering the task to the group chat manager, determining if we need to continue writing more articles, and to terminate the group chat by saying 'TERMINATE'."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "sme_agent = ConversableAgent(\n",
    "    \"Subject_Expert\",\n",
    "    system_message=\"You're a subject matter expert on cloud formations and work in a team with a scheduler and a writer. Every time you're asked to speak it's for a new article. You must prepare for a new article by selecting a the cloud formation, providing a summary of that formation and the impact on weather, in bullet points. Make it kid friendly. Aim for a dozen bullet points. Your task is only to provide topics and bullet points on new articles, don't review any previously written articles.\",\n",
    "    description=\"An expert on cloud formations, great at developing ideas to write about.\",\n",
    "    llm_config={\"config_list\": config_list_claude},\n",
    "    human_input_mode=\"NEVER\",\n",
    ")\n",
    "\n",
    "scheduler = ConversableAgent(\n",
    "    \"Scheduler\",\n",
    "    system_message=\"You're a marketing expert, managing the production of a specific number of articles. Count the number of articles written and once they have been written say the word 'TERMINATE'.\",\n",
    "    description=\"A marketing expert that's excellent at managing the production of articles.\",\n",
    "    llm_config={\"config_list\": config_list_claude},\n",
    "    human_input_mode=\"NEVER\",\n",
    ")\n",
    "\n",
    "writer = ConversableAgent(\n",
    "    \"Writer\",\n",
    "    system_message=\"You're a writer of online news articles on scientific topics, written for an audience of primary school students. Aim for 2,000 words for each article.\",\n",
    "    description=\"An excellent writer, takes given topics and writes long-form articles.\",\n",
    "    llm_config={\"config_list\": config_list_claude},\n",
    "    human_input_mode=\"NEVER\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we create our two transforms, one for injecting the `name` and the other to compress the messages if the estimated token count for all messages combined is greater than 1,000 tokens.\n",
    "\n",
    "As these transforms will be applied to the nested chat in a group chat where the next speaker is selected, we add a filter to the transforms to not apply to `system` messages and to messages from the `checking_agent` who is the agent within the nested chat for selecting the next speaker.\n",
    "\n",
    "These exclusions are used to minimise any loss of instruction in those messages as they are critical for speaker selection."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from autogen.agentchat.contrib.capabilities.text_compressors import LLMLingua\n",
    "from autogen.agentchat.contrib.capabilities.transforms import TextMessageCompressor, TextMessageContentName\n",
    "\n",
    "# Create transform to inject name\n",
    "# This will inject the agent's name for a message into the start of the message content.\n",
    "# E.g. \"'Subject_Expert' said\\n...\"\n",
    "name_transform = TextMessageContentName(\n",
    "    position=\"start\",\n",
    "    format_string=\"'{name}' said:\\n\",\n",
    "    filter_dict={\n",
    "        \"role\": [\"system\"],\n",
    "        \"name\": [\"checking_agent\"],\n",
    "    },  # don't add the name for the select speaker-specific nested-chat agents\n",
    ")\n",
    "\n",
    "# Create transform to compress messages\n",
    "# If you don't have LLMLingua installed: pip install LLMLingua\n",
    "llm_lingua = LLMLingua()\n",
    "compress_transform = TextMessageCompressor(\n",
    "    text_compressor=llm_lingua,\n",
    "    min_tokens=1000,  # Don't compress if total tokens in list of messages is <= 1000\n",
    "    filter_dict={\n",
    "        \"role\": [\"system\"],\n",
    "        \"name\": [\"checking_agent\"],\n",
    "    },  # don't compress messages specifically for the select speaker prompts\n",
    ")\n",
    "\n",
    "# Create the TransformMessages that will be applied\n",
    "# In this case we are only putting in one transform but you could\n",
    "# stack the transforms if you also wanted to do others, like\n",
    "# compressing the text. Transforms are performed sequentially.\n",
    "select_speaker_transforms = transform_messages.TransformMessages(\n",
    "    transforms=[\n",
    "        compress_transform,\n",
    "        name_transform,\n",
    "    ]\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With transforms created, we can apply them to the group chat's select speaker nested chat.\n",
    "\n",
    "In addition to the application of the transforms to the group chat's `select_speaker_transform_messages` parameter, we are providing explicit instructions on the order of agents within the `select_speaker_message_template`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from autogen import GroupChat, GroupChatManager\n",
    "\n",
    "group_chat = GroupChat(\n",
    "    agents=[sme_agent, scheduler, writer],\n",
    "    messages=[],\n",
    "    max_round=10,\n",
    "    select_speaker_message_template=\"\"\"You manage a team that produces and releases articles.\n",
    "        The roles available in the team are:\n",
    "        {roles}\n",
    "        Take the task given and coordinate the production of one or more articles.\n",
    "        The order for each article should be the Subject_Expert first, then the Writer to write an article, then the Scheduler to review and determine if more are required.\n",
    "        Finally, you can output the word 'TERMINATE' to signify the end of the task.\"\"\",\n",
    "    select_speaker_prompt_template=\"Read the above conversation, select the next person from {agentlist} and only return the role.\",\n",
    "    # Transforms applied to the group chat speaker selection when in 'auto' mode\n",
    "    select_speaker_transform_messages=select_speaker_transforms,\n",
    "    select_speaker_auto_verbose=True,  # See the selection process\n",
    ")\n",
    "\n",
    "manager = GroupChatManager(\n",
    "    groupchat=group_chat,\n",
    "    llm_config={\"config_list\": config_list_claude},\n",
    "    is_termination_msg=lambda x: \"TERMINATE\" in x.get(\"content\", \"\"),\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will also apply the transforms to each of the agents so that when they are getting the messages to respond to they are compressed and have the names of the agents injected."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# We add the transforms to the team of agents so they understand who has said what and the messages are compressed to save tokens\n",
    "select_speaker_transforms.add_to_agent(sme_agent)\n",
    "select_speaker_transforms.add_to_agent(scheduler)\n",
    "select_speaker_transforms.add_to_agent(writer)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Start the chat and show the cost at the end.\n",
    "\n",
    "Note: `select_speaker_auto_verbose` was set to True on the group chat so you can see the speaker selection process in between each message."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[33mScheduler\u001b[0m (to chat_manager):\n",
      "\n",
      "We need a couple of articles on different cloud formations, let's get some help on creating them!\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33mchecking_agent\u001b[0m (to speaker_selection_agent):\n",
      "\n",
      "Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33m1 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mspeaker_selection_agent\u001b[0m (to checking_agent):\n",
      "\n",
      "Subject_Expert\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[32m>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Subject_Expert\u001b[0m\n",
      "\u001b[32m\n",
      "Next speaker: Subject_Expert\n",
      "\u001b[0m\n",
      "\u001b[33m1 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mSubject_Expert\u001b[0m (to chat_manager):\n",
      "\n",
      "Certainly! I'd be happy to provide topics and bullet points for an article on a specific cloud formation. Let's start with one of the most recognizable cloud types: Cumulus clouds.\n",
      "\n",
      "Cloud Formation: Cumulus Clouds\n",
      "\n",
      "Summary:\n",
      "Cumulus clouds are puffy, white clouds that look like floating cotton balls in the sky. They're often associated with fair weather and are a common sight on sunny days.\n",
      "\n",
      "Bullet points for a kid-friendly article:\n",
      "\n",
      "• Cumulus clouds are nicknamed \"fair weather clouds\"\n",
      "• They look like fluffy white cotton balls or popcorn in the sky\n",
      "• Cumulus clouds usually have flat bottoms and rounded tops\n",
      "• They form when warm air rises from the ground and cools as it goes up\n",
      "• These clouds are made of tiny water droplets\n",
      "• Cumulus clouds typically appear on sunny, pleasant days\n",
      "• They often form in the late morning and disappear by evening\n",
      "• Sometimes cumulus clouds can grow into big thunderstorms\n",
      "• Pilots of small planes often avoid flying through cumulus clouds because they can be bumpy\n",
      "• Cumulus clouds can cast fun shadows on the ground\n",
      "• They're great for cloud-watching and imagining shapes (like animals or objects)\n",
      "• Artists often include cumulus clouds in their paintings of sunny landscapes\n",
      "\n",
      "This information should provide a good starting point for an engaging, kid-friendly article about cumulus clouds. Let me know if you'd like bullet points on another cloud formation for the second article!\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33mchecking_agent\u001b[0m (to speaker_selection_agent):\n",
      "\n",
      "Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33m2 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mspeaker_selection_agent\u001b[0m (to checking_agent):\n",
      "\n",
      "Writer\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[32m>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Writer\u001b[0m\n",
      "\u001b[32m\n",
      "Next speaker: Writer\n",
      "\u001b[0m\n",
      "\u001b[33m2 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mWriter\u001b[0m (to chat_manager):\n",
      "\n",
      "Thank you for the excellent outline on cumulus clouds. I'll use this information to create a 2000-word article for primary school students on cumulus clouds. Here's the article:\n",
      "\n",
      "Fluffy Friends in the Sky: All About Cumulus Clouds\n",
      "\n",
      "Have you ever looked up at the sky on a beautiful sunny day and seen big, puffy white clouds that look like giant cotton balls floating high above? Those clouds have a special name – they're called cumulus clouds! In this article, we're going to learn all about these fascinating clouds that paint our skies with their fluffy shapes. So, grab your imagination, and let's go on a cloud adventure!\n",
      "\n",
      "What Are Cumulus Clouds?\n",
      "\n",
      "Cumulus clouds are one of the most common and easily recognizable types of clouds in our sky. Their name comes from the Latin word \"cumulus,\" which means \"heap\" or \"pile.\" This makes sense because these clouds look like big heaps of cotton or fluffy piles of popcorn floating in the air.\n",
      "\n",
      "These clouds are famous for their distinct shape. They have flat bottoms and rounded, puffy tops that often look like they're bubbling up into the sky. Cumulus clouds are usually bright white, especially on the parts that face the sun. Sometimes, the bottom parts of the clouds can look a bit grey, especially if they're very big.\n",
      "\n",
      "Cumulus clouds are so well-known and loved that they've earned a special nickname. People often call them \"fair weather clouds\" because they're usually seen on nice, sunny days when the weather is pleasant. When you see cumulus clouds in the sky, it usually means it's a great day to play outside!\n",
      "\n",
      "How Do Cumulus Clouds Form?\n",
      "\n",
      "Now that we know what cumulus clouds look like, let's explore how these fluffy sky friends come to be. The process of cumulus cloud formation is quite interesting and involves some cool science!\n",
      "\n",
      "It all starts with the sun warming up the ground. As the ground gets warm, it heats the air right above it. This warm air starts to rise because hot air is lighter than cold air. As the warm air goes up, it begins to cool down. This is because the higher you go in the atmosphere, the colder it gets.\n",
      "\n",
      "When the rising warm air cools down enough, something magical happens. The water vapor (tiny bits of water that float in the air) in this cooling air starts to condense. Condensation is when water vapor turns back into liquid water. This creates tiny water droplets that clump together to form the cloud.\n",
      "\n",
      "The process doesn't stop there! As long as there's warm air rising from below, the cloud keeps growing bigger and puffier. That's why cumulus clouds often look like they're bubbling or boiling at the top. They're constantly growing and changing shape as more warm air rises and more water droplets form.\n",
      "\n",
      "Interestingly, even though cumulus clouds look super fluffy and solid, they're actually made up of millions of tiny water droplets floating in the air. If you could touch a cumulus cloud (which, unfortunately, you can't), it would feel more like fog than a fluffy pillow!\n",
      "\n",
      "When Can We See Cumulus Clouds?\n",
      "\n",
      "One of the cool things about cumulus clouds is that they follow a bit of a daily schedule. They're like nature's clock in the sky!\n",
      "\n",
      "Cumulus clouds typically start to form in the late morning. This is when the sun has had enough time to warm up the ground and get those pockets of warm air rising. As the day goes on and gets warmer, you might see more and more cumulus clouds popping up in the sky.\n",
      "\n",
      "These clouds usually reach their peak in the afternoon when the day is at its warmest. This is the best time for cloud watching! You might see lots of different shapes and sizes of cumulus clouds dotting the blue sky.\n",
      "\n",
      "As evening approaches and the air starts to cool down, cumulus clouds often begin to disappear. Without the warm rising air to keep them growing, these clouds tend to evaporate and fade away. By nighttime, the sky is often clear again, ready for stars to twinkle.\n",
      "\n",
      "Remember, though, that weather can be unpredictable. Sometimes cumulus clouds stick around longer, and sometimes they might not form at all. It all depends on the conditions in the atmosphere that day.\n",
      "\n",
      "Cumulus Clouds and Weather\n",
      "\n",
      "While cumulus clouds are often called \"fair weather clouds,\" they can actually tell us a lot about what's happening in the atmosphere and what kind of weather we might expect.\n",
      "\n",
      "On most days, seeing cumulus clouds means the weather is likely to stay nice. These small to medium-sized puffy clouds usually indicate stable air and good weather conditions. They're the kind of clouds you want to see on a picnic day or when you're heading to the beach!\n",
      "\n",
      "However, cumulus clouds can sometimes grow into much larger clouds called cumulonimbus clouds. These are the big, tall clouds that can bring thunderstorms. If you see cumulus clouds starting to grow very tall and dark at the bottom, it might be a sign that a storm is brewing.\n",
      "\n",
      "Pilots of small airplanes often try to avoid flying through cumulus clouds. Even though these clouds look soft and fluffy from the ground, they can create bumpy air currents that can make for an uncomfortable flight. Big cumulus clouds can also have strong up and down air movements inside them, which can be challenging for small aircraft to navigate.\n",
      "\n",
      "Fun with Cumulus Clouds\n",
      "\n",
      "Cumulus clouds aren't just interesting to learn about – they're also great for having fun! Here are some enjoyable activities you can do with cumulus clouds:\n",
      "\n",
      "1. Cloud Watching: On a day with lots of cumulus clouds, lie down on the grass and look up at the sky. Let your imagination run wild! What shapes can you see in the clouds? Maybe you'll spot a rabbit, a dragon, or even a sailing ship! Cloud watching is a great way to relax and be creative.\n",
      "\n",
      "2. Cloud Shadows: On sunny days with scattered cumulus clouds, watch how the clouds cast shadows on the ground. These shadows move as the clouds drift across the sky, creating a constantly changing pattern on the earth below.\n",
      "\n",
      "3. Cloud Photography: If you have a camera or a smartphone, try taking pictures of cumulus clouds. You might capture some really interesting shapes or beautiful scenes of clouds against a blue sky.\n",
      "\n",
      "4. Cloud Diary: Keep a cloud diary for a week or a month. Each day, look out the window and draw or describe the clouds you see. Over time, you'll start to notice patterns in how the clouds change with the weather.\n",
      "\n",
      "5. Cloud in a Jar Experiment: With an adult's help, you can even make your own cumulus cloud in a jar! This fun science experiment helps you understand how these clouds form.\n",
      "\n",
      "Cumulus Clouds in Art and Culture\n",
      "\n",
      "Cumulus clouds are so beautiful and recognizable that they've become a popular subject in art and culture.\n",
      "\n",
      "Many famous painters have included cumulus clouds in their landscapes. Artists like Vincent van Gogh and Claude Monet often painted scenes with big, puffy clouds floating over fields or water. These clouds add depth and movement to paintings, making the scenes feel alive and dynamic.\n",
      "\n",
      "In children's books and cartoons, cumulus clouds are often drawn as simple white puffs. They're used to show that it's a nice day in the story. Sometimes, characters in cartoons even sit or sleep on these fluffy clouds (even though in real life, you'd fall right through a cloud!).\n",
      "\n",
      "Cumulus clouds have also inspired many writers and poets. Their ever-changing shapes and the way they float peacefully across the sky have been described in countless poems and stories.\n",
      "\n",
      "In some cultures, cumulus clouds have even played a role in weather folklore. For example, there's an old saying: \"If clouds are puffy like cotton on high, then dry weather's coming by and by.\" This shows how people have long used cumulus clouds as a way to predict the weather.\n",
      "\n",
      "The Science Behind Cumulus Clouds\n",
      "\n",
      "While cumulus clouds might look simple, there's actually a lot of complex science happening inside them. Here are some fascinating scientific facts about cumulus clouds:\n",
      "\n",
      "1. Temperature: The temperature inside a cumulus cloud is usually below freezing, even on a warm day! This is because the cloud is high up in the atmosphere where it's much colder.\n",
      "\n",
      "2. Weight: Even though cumulus clouds look light and fluffy, they're actually quite heavy. An average cumulus cloud can weigh as much as 100 elephants! But don't worry – they stay up in the sky because the tiny water droplets are spread out over a large area.\n",
      "\n",
      "3. Movement: Cumulus clouds move with the wind. The speed at which they move can tell us how fast the wind is blowing high up in the atmosphere.\n",
      "\n",
      "4. Life Span: Most cumulus clouds only last for about 15 to 20 minutes before they evaporate. However, in the right conditions, they can last for hours, constantly reforming as they move across the sky.\n",
      "\n",
      "5. Size: While most cumulus clouds are fairly small, some can grow to be enormous. The biggest cumulus clouds can be as tall as a 10-story building!\n",
      "\n",
      "Conclusion\n",
      "\n",
      "Cumulus clouds are truly amazing parts of our sky. From their fluffy, cotton-like appearance to the complex science behind their formation, these clouds have so much to teach us about weather and the atmosphere.\n",
      "\n",
      "Next time you're outside on a nice day, take a moment to look up at the sky. If you see those familiar puffy white clouds, you'll know you're looking at cumulus clouds. Remember how they form, think about the tiny water droplets that make them up, and let your imagination run wild with the shapes you see.\n",
      "\n",
      "Cumulus clouds are more than just beautiful sights in the sky. They're a reminder of the constant changes happening in our atmosphere, the amazing processes of nature, and the wonder of the world around us. So keep your eyes on the skies, and enjoy the fluffy, fascinating world of cumulus clouds!\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33mchecking_agent\u001b[0m (to speaker_selection_agent):\n",
      "\n",
      "Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.\n",
      "\n",
      "--------------------------------------------------------------------------------\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Token indices sequence length is longer than the specified maximum sequence length for this model (2324 > 512). Running this sequence through the model will result in indexing errors\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[33m1282 tokens saved with text compression.\u001b[0m\n",
      "\u001b[33m3 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mspeaker_selection_agent\u001b[0m (to checking_agent):\n",
      "\n",
      "Scheduler\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[32m>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Scheduler\u001b[0m\n",
      "\u001b[32m\n",
      "Next speaker: Scheduler\n",
      "\u001b[0m\n",
      "\u001b[33m1282 tokens saved with text compression.\u001b[0m\n",
      "\u001b[33m3 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mScheduler\u001b[0m (to chat_manager):\n",
      "\n",
      "Thank you for providing that detailed article on cumulus clouds. It's a well-written piece that covers the topic thoroughly for primary school students. Since we now have one complete article, I'll count that as the first one written.\n",
      "\n",
      "Articles written: 1\n",
      "\n",
      "Please continue with the next article or task.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33mchecking_agent\u001b[0m (to speaker_selection_agent):\n",
      "\n",
      "Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33m1311 tokens saved with text compression.\u001b[0m\n",
      "\u001b[33m4 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mspeaker_selection_agent\u001b[0m (to checking_agent):\n",
      "\n",
      "Subject_Expert\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[32m>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Subject_Expert\u001b[0m\n",
      "\u001b[32m\n",
      "Next speaker: Subject_Expert\n",
      "\u001b[0m\n",
      "\u001b[33m1311 tokens saved with text compression.\u001b[0m\n",
      "\u001b[33m4 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mSubject_Expert\u001b[0m (to chat_manager):\n",
      "\n",
      "'Subject_Expert' said:\n",
      "Excellent, I'm glad the article on cumulus clouds was well-received. For our next article, let's focus on stratus clouds. Here's an outline with kid-friendly bullet points on stratus clouds:\n",
      "\n",
      "Cloud Formation: Stratus Clouds\n",
      "\n",
      "• Stratus clouds are low-lying, gray clouds that often cover the entire sky\n",
      "• They look like a big, gray blanket stretched across the sky\n",
      "• The word \"stratus\" comes from the Latin word for \"layer\" or \"spread out\"\n",
      "• These clouds usually form less than 6,000 feet (1,800 meters) above the ground\n",
      "• Stratus clouds often bring light rain or drizzle, but not heavy downpours\n",
      "• Sometimes, stratus clouds can touch the ground - we call this fog!\n",
      "• They form when a large area of warm air rises slowly and cools down\n",
      "• Stratus clouds can make the day look gloomy and overcast\n",
      "• They don't have distinct shapes like cumulus clouds do\n",
      "• These clouds can stick around for hours or even days\n",
      "• Stratus clouds are common in cool, damp climates\n",
      "• They often form in the morning and can clear up by afternoon\n",
      "• Pilots need to be careful when flying through stratus clouds because they can reduce visibility\n",
      "\n",
      "This outline provides a good starting point for an engaging article about stratus clouds, suitable for primary school students. It covers the basic characteristics, formation, and impact of stratus clouds on weather and daily life.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33mchecking_agent\u001b[0m (to speaker_selection_agent):\n",
      "\n",
      "Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33m1475 tokens saved with text compression.\u001b[0m\n",
      "\u001b[33m5 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mspeaker_selection_agent\u001b[0m (to checking_agent):\n",
      "\n",
      "Writer\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[32m>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Writer\u001b[0m\n",
      "\u001b[32m\n",
      "Next speaker: Writer\n",
      "\u001b[0m\n",
      "\u001b[33m1475 tokens saved with text compression.\u001b[0m\n",
      "\u001b[33m5 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mWriter\u001b[0m (to chat_manager):\n",
      "\n",
      "'Writer' said:\n",
      "Thank you for the excellent outline on stratus clouds. I'll use this information to create a 2000-word article for primary school students about stratus clouds. Here's the article:\n",
      "\n",
      "The Gray Blanket in the Sky: All About Stratus Clouds\n",
      "\n",
      "Have you ever woken up to a gloomy day where the whole sky looks like one big gray blanket? Those aren't just any clouds you're seeing – they're called stratus clouds! Let's embark on a cloudy adventure to learn all about these fascinating sky coverings that can make the world look a bit dreary but play an important role in our weather.\n",
      "\n",
      "What are Stratus Clouds?\n",
      "\n",
      "Stratus clouds are low-lying, gray clouds that often cover the entire sky. Their name comes from the Latin word \"stratus,\" which means \"layer\" or \"spread out.\" That's exactly what these clouds do – they spread out across the sky like a huge, fluffy gray blanket!\n",
      "\n",
      "Unlike their puffy cousins, the cumulus clouds, stratus clouds don't have distinct shapes. You won't see any fun animals or objects in stratus clouds. Instead, they create a uniform, featureless layer that can stretch as far as the eye can see.\n",
      "\n",
      "Stratus clouds are low clouds, which means they form pretty close to the ground. In fact, they usually hang out less than 6,000 feet (or about 1,800 meters) above the Earth's surface. Sometimes, they can be so low that they touch the ground – when this happens, we call it fog!\n",
      "\n",
      "How Do Stratus Clouds Form?\n",
      "\n",
      "The formation of stratus clouds is an interesting process that involves some cool science. Here's how it happens:\n",
      "\n",
      "1. Warm Air Rises: Just like with other cloud types, it all starts with warm air rising from the Earth's surface.\n",
      "\n",
      "2. Cooling Process: As this warm air rises, it starts to cool down. Remember, the higher you go in the atmosphere, the colder it gets!\n",
      "\n",
      "3. Water Vapor Condenses: The cooling air can't hold as much water vapor (invisible water in the air) as warm air can. So, as the air cools, the water vapor starts to condense, turning into tiny water droplets.\n",
      "\n",
      "4. Cloud Formation: These tiny water droplets clump together to form the cloud. In the case of stratus clouds, this happens in a wide, flat layer.\n",
      "\n",
      "5. Stable Atmosphere: Stratus clouds often form when the atmosphere is stable, meaning there's not much mixing between different layers of air. This allows the cloud to spread out in a smooth, even layer.\n",
      "\n",
      "Stratus clouds can form in a couple of different ways:\n",
      "\n",
      "• When a layer of warm air moves over a cooler surface (like when warm air moves over a cool ocean).\n",
      "• When snow or rain evaporates as it falls through dry air near the ground, cooling and moistening that air until it becomes saturated and forms a cloud.\n",
      "\n",
      "Weather Associated with Stratus Clouds\n",
      "\n",
      "When you see stratus clouds, it's a good idea to grab a jacket or an umbrella! These clouds often bring gloomy, overcast weather. Here's what you can expect when stratus clouds are in the sky:\n",
      "\n",
      "1. Light Rain or Drizzle: Stratus clouds can produce light rain or drizzle. This isn't the heavy downpour you might see with thunderstorms, but more of a constant, gentle sprinkle.\n",
      "\n",
      "2. Fog: Remember how we said stratus clouds can touch the ground? When they do, we call it fog. So if you've ever walked through a foggy morning, you've actually been inside a stratus cloud!\n",
      "\n",
      "3. Cool Temperatures: Because stratus clouds block out the sun, days with these clouds tend to be cooler than clear, sunny days.\n",
      "\n",
      "4. Low Visibility: The thick layer of stratus clouds can make it hard to see very far, especially if they're low to the ground or if it's foggy.\n",
      "\n",
      "5. Long-lasting: Unlike some other cloud types that come and go quickly, stratus clouds can stick around for hours or even days, especially in cool, damp climates.\n",
      "\n",
      "Stratus Clouds Around the World\n",
      "\n",
      "Stratus clouds are common in many parts of the world, but they're especially frequent in certain areas:\n",
      "\n",
      "• Coastal Regions: Places near the ocean often see a lot of stratus clouds, especially in the morning. The cool water can cause warm air to cool and form these layered clouds.\n",
      "\n",
      "• Cool, Damp Climates: Areas with cool, moist weather (like the Pacific Northwest in the United States or parts of the United Kingdom) frequently have stratus cloud cover.\n",
      "\n",
      "• Arctic and Antarctic Regions: The cold polar regions often have stratus clouds, contributing to their characteristically gray skies.\n",
      "\n",
      "Stratus Clouds and Daily Life\n",
      "\n",
      "Stratus clouds might not be as fun to look at as puffy cumulus clouds, but they still have a big impact on our daily lives:\n",
      "\n",
      "1. Agriculture: Farmers pay attention to stratus clouds because they can bring needed moisture for crops, but too many cloudy days can reduce sunlight for plant growth.\n",
      "\n",
      "2. Solar Power: Stratus clouds can reduce the effectiveness of solar panels by blocking out sunlight.\n",
      "\n",
      "3. Aviation: Pilots need to be very careful when flying through stratus clouds because they can greatly reduce visibility.\n",
      "\n",
      "4. Mood: Some people find that long periods of stratus cloud cover can affect their mood, making them feel a bit gloomy. That's why sunny days feel so good after a long stretch of cloudy weather!\n",
      "\n",
      "5. Photography: While stratus clouds might not make for the most exciting cloud photos, they can create a soft, even light that photographers sometimes prefer for certain types of pictures.\n",
      "\n",
      "Fun Facts About Stratus Clouds\n",
      "\n",
      "Let's explore some interesting tidbits about these gray sky blankets:\n",
      "\n",
      "1. Cloud Seeding: Sometimes, scientists try to make it rain by \"seeding\" stratus clouds. They drop tiny particles into the clouds to help water droplets form and fall as rain.\n",
      "\n",
      "2. Natural Air Conditioning: Stratus clouds act like nature's air conditioning, keeping the Earth cool by reflecting sunlight back into space.\n",
      "\n",
      "3. Cloud Forests: In some mountainous tropical areas, stratus clouds constantly cover the forest, creating a unique ecosystem called a \"cloud forest.\"\n",
      "\n",
      "4. Noctilucent Clouds: The highest clouds in Earth's atmosphere, called noctilucent clouds, are a special type of stratus cloud that forms in the mesosphere, about 50 miles (80 km) above the Earth's surface!\n",
      "\n",
      "5. Cloud Naming: Stratus clouds are part of the ten basic cloud types identified by Luke Howard in 1803. He's known as the \"father of meteorology\" for his work in classifying clouds.\n",
      "\n",
      "Stratus Cloud Variations\n",
      "\n",
      "While stratus clouds are generally uniform layers, there are a few variations:\n",
      "\n",
      "1. Stratus Nebulosus: This is the classic, featureless gray layer we typically think of as stratus clouds.\n",
      "\n",
      "2. Stratus Fractus: These are ragged, broken pieces of stratus clouds, often seen during or after rain.\n",
      "\n",
      "3. Altostratus: These are similar to stratus but form at higher altitudes, creating a thinner, more translucent layer.\n",
      "\n",
      "4. Nimbostratus: These are thick, dark stratus clouds that produce steady rain or snow.\n",
      "\n",
      "Activities to Learn About Stratus Clouds\n",
      "\n",
      "Even though stratus clouds aren't as visually exciting as some other cloud types, there are still fun ways to learn about them:\n",
      "\n",
      "1. Cloud Diary: Keep a cloud diary for a week or a month. Draw or describe the clouds you see each day, noting when you observe stratus clouds.\n",
      "\n",
      "2. Make a Cloud in a Jar: With an adult's help, you can create a miniature stratus cloud in a jar using hot water, hairspray, and ice.\n",
      "\n",
      "3. Fog Observation: On a foggy day, go outside (with an adult) and observe how it feels to be inside a stratus cloud that's touching the ground.\n",
      "\n",
      "4. Weather Station: Set up a simple weather station at home or school. Track temperature, humidity, and cloud cover, noting how these change when stratus clouds are present.\n",
      "\n",
      "5. Cloud Art: Create art inspired by stratus clouds. You could use gray paint or pencils to create the effect of a cloudy sky, or try making a collage using different shades of gray paper.\n",
      "\n",
      "Conclusion\n",
      "\n",
      "Stratus clouds might not be the most exciting clouds in the sky, but they're an important part of our weather and have a big impact on our daily lives. From creating gloomy, drizzly days to helping cool our planet, these low-lying gray blankets play a crucial role in Earth's atmosphere.\n",
      "\n",
      "Next time you wake up to a gray, overcast day, remember that you're looking at stratus clouds. Think about how they formed, what kind of weather they might bring, and how they're affecting the world around you. Even on a cloudy day, there's always something interesting to learn about the sky above us!\n",
      "\n",
      "So keep your eyes on the skies, young meteorologists, and enjoy exploring the fascinating world of stratus clouds!\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33mchecking_agent\u001b[0m (to speaker_selection_agent):\n",
      "\n",
      "Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33m2485 tokens saved with text compression.\u001b[0m\n",
      "\u001b[33m6 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mspeaker_selection_agent\u001b[0m (to checking_agent):\n",
      "\n",
      "Please continue.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[31m>>>>>>>> Select speaker attempt #1 failed as it did not include any agent names.\u001b[0m\n",
      "\u001b[33mchecking_agent\u001b[0m (to speaker_selection_agent):\n",
      "\n",
      "You didn't choose a speaker. As a reminder, to determine the speaker use these prioritised rules:\n",
      "    1. If the context refers to themselves as a speaker e.g. \"As the...\" , choose that speaker's name\n",
      "    2. If it refers to the \"next\" speaker name, choose that name\n",
      "    3. Otherwise, choose the first provided speaker's name in the context\n",
      "    The names are case-sensitive and should not be abbreviated or changed.\n",
      "    The only names that are accepted are ['Subject_Expert', 'Scheduler', 'Writer'].\n",
      "    Respond with ONLY the name of the speaker and DO NOT provide a reason.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[33m2487 tokens saved with text compression.\u001b[0m\n",
      "\u001b[33m7 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mspeaker_selection_agent\u001b[0m (to checking_agent):\n",
      "\n",
      "Scheduler\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\u001b[32m>>>>>>>> Select speaker attempt 2 of 3 successfully selected: Scheduler\u001b[0m\n",
      "\u001b[32m\n",
      "Next speaker: Scheduler\n",
      "\u001b[0m\n",
      "\u001b[33m2485 tokens saved with text compression.\u001b[0m\n",
      "\u001b[33m6 message(s) changed to incorporate name.\u001b[0m\n",
      "\u001b[33mScheduler\u001b[0m (to chat_manager):\n",
      "\n",
      "'Scheduler' said:\n",
      "Excellent work! You've now completed two well-written articles: one on cumulus clouds and another on stratus clouds. Both are informative and engaging for primary school students.\n",
      "\n",
      "Articles written: 2\n",
      "\n",
      "Since we've reached our target number of articles, I'll now say: TERMINATE\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "The cost of the chat was:\n",
      "{'usage_including_cached_inference': {'total_cost': 0.013266, 'claude-3-5-sonnet-20240620': {'cost': 0.013266, 'prompt_tokens': 3732, 'completion_tokens': 138, 'total_tokens': 3870}}, 'usage_excluding_cached_inference': {'total_cost': 0.013266, 'claude-3-5-sonnet-20240620': {'cost': 0.013266, 'prompt_tokens': 3732, 'completion_tokens': 138, 'total_tokens': 3870}}}\n"
     ]
    }
   ],
   "source": [
    "chat_result = scheduler.initiate_chat(\n",
    "    recipient=manager,\n",
    "    message=\"We need a couple of articles on different cloud formations, let's get some help on creating them!\",\n",
    ")\n",
    "\n",
    "print(f\"The cost of the chat was:\\n{chat_result.cost}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There's a lot to digest in the above code, let's break it down.\n",
    "\n",
    "1. It successfully did the task, getting two articles written (Yay!)\n",
    "2. The sequence of agents was selected successfully: Scheduler to Subject_Expert to Writer then back to Scheduler to Subject_Expert to Writer to Scheduler who then terminates\n",
    "3. Transform messages show the number of messages incorporating the name and the tokens saved during the process\n",
    "4. We occasionally see the next agent name \"Please continue.\" being proposed by the LLM and this is because these continuation messages are inter-woven in the messages sent to Anthropic's API. This is handled well with the select speaker retries, but further prompt tuning could help eliminate these anomalies\n",
    "\n",
    "Additional notes:\n",
    "\n",
    "- Would this have worked without the transforms? Taking out the transforms resulted in a run producing the following incorrect sequence: Scheduler to Subject_Export to Writer back to Writer then to Scheduler.\n",
    "- Tweaking - tweaking the system messages and descriptions for agents and the group chat select speaker nested chat also played a large role in steering the LLM to the correct output. A combination of prompt engineering and the transforms may be required to achieve consistent results.\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "autogen",
   "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",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
