Skip to main content

Transform Messages for Non-OpenAI Models

Open In Colab Open on GitHub

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.

If you’re new to Transform Messages, see the introduction to Transform Messages.

Reducing context sizes

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.

To handle longer contexts using transforms, essentially reducing them effectively for smaller context windows, please see the page on compressing text.

Incorporating an agent’s name

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.

comedian = ConversableAgent(
name="Jack", # Not included in messages for non-OpenAI inference
llm_config=phi2,
system_message="Your name is Jack and you are a comedian.",
)

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.

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.

As we won’t be using OpenAI, we will use the Anthropic client to demonstrate.

We’ll start by importing our modules and setting our config.

import os

from autogen import ConversableAgent

config_list_claude = [
{
"model": "claude-3-5-sonnet-20240620",
"api_key": os.getenv("ANTHROPIC_API_KEY"),
"api_type": "anthropic",
"cache_seed": None, # Ensure we're not caching any results
}
]
/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
from .autonotebook import tqdm as notebook_tqdm

Now we add two agents, both comedians who will make up jokes about the other using their name.

cathy = ConversableAgent(
"Cathy",
system_message="Your name is Cathy and you are a part of a duo of comedians.",
llm_config={"config_list": config_list_claude},
human_input_mode="NEVER",
)

joe = ConversableAgent(
"Joe",
system_message="Your name is Joe and you are a part of a duo of comedians.",
llm_config={"config_list": config_list_claude},
human_input_mode="NEVER",
)

Let’s start the chat without using the transform and see how it performs.

result = joe.initiate_chat(cathy, message="People say I have a funny name, tell me a joke about it.", max_turns=2)
Joe (to Cathy):

People say I have a funny name, tell me a joke about it.

--------------------------------------------------------------------------------
Cathy (to Joe):

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!

--------------------------------------------------------------------------------
Joe (to Cathy):

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.

As Joe, the other half of your comedy duo, I'll play along with your prompt:

"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!'"

How's that for a quick improvised joke about your name, partner?

--------------------------------------------------------------------------------
Cathy (to Joe):

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:

"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!"

How's that for a comeback, partner? I think we're really on a roll here. Should we take this act on the road?

--------------------------------------------------------------------------------

As we can see from the chat, Cathy doesn’t know Joe’s name at the start.

Now, we’ll create a transform that injects the names into the messages and apply that transform to both agents.

# Import our transforms
from autogen.agentchat.contrib.capabilities import transform_messages
from autogen.agentchat.contrib.capabilities.transforms import TextMessageContentName

# Create a name transform
# This will inject the agent's name for a message into the start of the message content.
# E.g. "'Jack' said\n..."
name_transform = TextMessageContentName(position="start", format_string="'{name}' said:\n")

# Create the TransformMessages that will be applied.
# In this case we are only putting in one transform but you could
# stack the transforms if you also wanted to do others, like
# compress the text. Transforms are performed sequentially.
context_handling = transform_messages.TransformMessages(transforms=[name_transform])

# Add it to both agents so when they run inference it will apply to the messages
context_handling.add_to_agent(cathy)
context_handling.add_to_agent(joe)

Let’s try that chat again now that we’re injecting the names.

result = joe.initiate_chat(cathy, message="People say I have a funny name, tell me a joke about it.", max_turns=2)
Joe (to Cathy):

People say I have a funny name, tell me a joke about it.

--------------------------------------------------------------------------------
1 message(s) changed to incorporate name.
Cathy (to Joe):

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:

Why did Joe's friends call him "Volcano"?
Because he was always erupting with short outbursts!

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!

--------------------------------------------------------------------------------
2 message(s) changed to incorporate name.
Joe (to Cathy):

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:

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?"

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"?

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!

--------------------------------------------------------------------------------
3 message(s) changed to incorporate name.
Cathy (to Joe):

'Cathy' said:
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!

As for jazzing up your name, I've got a few suggestions that might tickle your funny bone:

1. "Joe-normous" - for when you're feeling larger than life.
2. "Joevius Maximus" - if you're going for that Roman emperor vibe.
3. "Joe-pacabra" - half man, half mysterious creature.
4. "Joehemoth" - for those days when you feel particularly beastly.
5. "Average Joe-seidon" - god of the sea... and mediocrity.

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.

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?

--------------------------------------------------------------------------------

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.

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.

Transforms in group chats

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.

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.

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.

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).

The scenario in the example is the production of two kid-friendly long-form articles on cloud formations.

Let’s start by creating our three team members:

  • Subject_Expert will select a cloud formation and provide some bullet points about it.
  • Writer will write long-form content, about 2,000 words, for the selected cloud formation based on the bullet points.
  • 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’.
sme_agent = ConversableAgent(
"Subject_Expert",
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.",
description="An expert on cloud formations, great at developing ideas to write about.",
llm_config={"config_list": config_list_claude},
human_input_mode="NEVER",
)

scheduler = ConversableAgent(
"Scheduler",
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'.",
description="A marketing expert that's excellent at managing the production of articles.",
llm_config={"config_list": config_list_claude},
human_input_mode="NEVER",
)

writer = ConversableAgent(
"Writer",
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.",
description="An excellent writer, takes given topics and writes long-form articles.",
llm_config={"config_list": config_list_claude},
human_input_mode="NEVER",
)

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.

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.

These exclusions are used to minimise any loss of instruction in those messages as they are critical for speaker selection.

from autogen.agentchat.contrib.capabilities.text_compressors import LLMLingua
from autogen.agentchat.contrib.capabilities.transforms import TextMessageCompressor, TextMessageContentName

# Create transform to inject name
# This will inject the agent's name for a message into the start of the message content.
# E.g. "'Subject_Expert' said\n..."
name_transform = TextMessageContentName(
position="start",
format_string="'{name}' said:\n",
filter_dict={
"role": ["system"],
"name": ["checking_agent"],
}, # don't add the name for the select speaker-specific nested-chat agents
)

# Create transform to compress messages
# If you don't have LLMLingua installed: pip install LLMLingua
llm_lingua = LLMLingua()
compress_transform = TextMessageCompressor(
text_compressor=llm_lingua,
min_tokens=1000, # Don't compress if total tokens in list of messages is <= 1000
filter_dict={
"role": ["system"],
"name": ["checking_agent"],
}, # don't compress messages specifically for the select speaker prompts
)

# Create the TransformMessages that will be applied
# In this case we are only putting in one transform but you could
# stack the transforms if you also wanted to do others, like
# compressing the text. Transforms are performed sequentially.
select_speaker_transforms = transform_messages.TransformMessages(
transforms=[
compress_transform,
name_transform,
]
)

With transforms created, we can apply them to the group chat’s select speaker nested chat.

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.

from autogen import GroupChat, GroupChatManager

group_chat = GroupChat(
agents=[sme_agent, scheduler, writer],
messages=[],
max_round=10,
select_speaker_message_template="""You manage a team that produces and releases articles.
The roles available in the team are:
{roles}
Take the task given and coordinate the production of one or more articles.
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.
Finally, you can output the word 'TERMINATE' to signify the end of the task.""",
select_speaker_prompt_template="Read the above conversation, select the next person from {agentlist} and only return the role.",
# Transforms applied to the group chat speaker selection when in 'auto' mode
select_speaker_transform_messages=select_speaker_transforms,
select_speaker_auto_verbose=True, # See the selection process
)

manager = GroupChatManager(
groupchat=group_chat,
llm_config={"config_list": config_list_claude},
is_termination_msg=lambda x: "TERMINATE" in x.get("content", ""),
)

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.

# We add the transforms to the team of agents so they understand who has said what and the messages are compressed to save tokens
select_speaker_transforms.add_to_agent(sme_agent)
select_speaker_transforms.add_to_agent(scheduler)
select_speaker_transforms.add_to_agent(writer)

Start the chat and show the cost at the end.

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.

chat_result = scheduler.initiate_chat(
recipient=manager,
message="We need a couple of articles on different cloud formations, let's get some help on creating them!",
)

print(f"The cost of the chat was:\n{chat_result.cost}")
Scheduler (to chat_manager):

We need a couple of articles on different cloud formations, let's get some help on creating them!

--------------------------------------------------------------------------------
checking_agent (to speaker_selection_agent):

Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.

--------------------------------------------------------------------------------
1 message(s) changed to incorporate name.
speaker_selection_agent (to checking_agent):

Subject_Expert

--------------------------------------------------------------------------------
>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Subject_Expert

Next speaker: Subject_Expert

1 message(s) changed to incorporate name.
Subject_Expert (to chat_manager):

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.

Cloud Formation: Cumulus Clouds

Summary:
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.

Bullet points for a kid-friendly article:

• Cumulus clouds are nicknamed "fair weather clouds"
• They look like fluffy white cotton balls or popcorn in the sky
• Cumulus clouds usually have flat bottoms and rounded tops
• They form when warm air rises from the ground and cools as it goes up
• These clouds are made of tiny water droplets
• Cumulus clouds typically appear on sunny, pleasant days
• They often form in the late morning and disappear by evening
• Sometimes cumulus clouds can grow into big thunderstorms
• Pilots of small planes often avoid flying through cumulus clouds because they can be bumpy
• Cumulus clouds can cast fun shadows on the ground
• They're great for cloud-watching and imagining shapes (like animals or objects)
• Artists often include cumulus clouds in their paintings of sunny landscapes

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!

--------------------------------------------------------------------------------
checking_agent (to speaker_selection_agent):

Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.

--------------------------------------------------------------------------------
2 message(s) changed to incorporate name.
speaker_selection_agent (to checking_agent):

Writer

--------------------------------------------------------------------------------
>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Writer

Next speaker: Writer

2 message(s) changed to incorporate name.
Writer (to chat_manager):

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:

Fluffy Friends in the Sky: All About Cumulus Clouds

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!

What Are Cumulus Clouds?

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.

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.

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!

How Do Cumulus Clouds Form?

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!

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.

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.

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.

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!

When Can We See Cumulus Clouds?

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!

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.

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.

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.

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.

Cumulus Clouds and Weather

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.

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!

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.

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.

Fun with Cumulus Clouds

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:

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.

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.

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.

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.

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.

Cumulus Clouds in Art and Culture

Cumulus clouds are so beautiful and recognizable that they've become a popular subject in art and culture.

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.

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!).

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.

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.

The Science Behind Cumulus Clouds

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:

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.

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.

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.

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.

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!

Conclusion

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.

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.

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!

--------------------------------------------------------------------------------
checking_agent (to speaker_selection_agent):

Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.

--------------------------------------------------------------------------------
1282 tokens saved with text compression.
3 message(s) changed to incorporate name.
speaker_selection_agent (to checking_agent):

Scheduler

--------------------------------------------------------------------------------
>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Scheduler

Next speaker: Scheduler

1282 tokens saved with text compression.
3 message(s) changed to incorporate name.
Scheduler (to chat_manager):

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.

Articles written: 1

Please continue with the next article or task.

--------------------------------------------------------------------------------
checking_agent (to speaker_selection_agent):

Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.

--------------------------------------------------------------------------------
1311 tokens saved with text compression.
4 message(s) changed to incorporate name.
speaker_selection_agent (to checking_agent):

Subject_Expert

--------------------------------------------------------------------------------
>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Subject_Expert

Next speaker: Subject_Expert

1311 tokens saved with text compression.
4 message(s) changed to incorporate name.
Subject_Expert (to chat_manager):

'Subject_Expert' said:
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:

Cloud Formation: Stratus Clouds

• Stratus clouds are low-lying, gray clouds that often cover the entire sky
• They look like a big, gray blanket stretched across the sky
• The word "stratus" comes from the Latin word for "layer" or "spread out"
• These clouds usually form less than 6,000 feet (1,800 meters) above the ground
• Stratus clouds often bring light rain or drizzle, but not heavy downpours
• Sometimes, stratus clouds can touch the ground - we call this fog!
• They form when a large area of warm air rises slowly and cools down
• Stratus clouds can make the day look gloomy and overcast
• They don't have distinct shapes like cumulus clouds do
• These clouds can stick around for hours or even days
• Stratus clouds are common in cool, damp climates
• They often form in the morning and can clear up by afternoon
• Pilots need to be careful when flying through stratus clouds because they can reduce visibility

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.

--------------------------------------------------------------------------------
checking_agent (to speaker_selection_agent):

Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.

--------------------------------------------------------------------------------
1475 tokens saved with text compression.
5 message(s) changed to incorporate name.
speaker_selection_agent (to checking_agent):

Writer

--------------------------------------------------------------------------------
>>>>>>>> Select speaker attempt 1 of 3 successfully selected: Writer

Next speaker: Writer

1475 tokens saved with text compression.
5 message(s) changed to incorporate name.
Writer (to chat_manager):

'Writer' said:
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:

The Gray Blanket in the Sky: All About Stratus Clouds

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.

What are Stratus Clouds?

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!

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.

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!

How Do Stratus Clouds Form?

The formation of stratus clouds is an interesting process that involves some cool science. Here's how it happens:

1. Warm Air Rises: Just like with other cloud types, it all starts with warm air rising from the Earth's surface.

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!

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.

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.

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.

Stratus clouds can form in a couple of different ways:

• When a layer of warm air moves over a cooler surface (like when warm air moves over a cool ocean).
• 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.

Weather Associated with Stratus Clouds

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:

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.

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!

3. Cool Temperatures: Because stratus clouds block out the sun, days with these clouds tend to be cooler than clear, sunny days.

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.

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.

Stratus Clouds Around the World

Stratus clouds are common in many parts of the world, but they're especially frequent in certain areas:

• 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.

• 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.

• Arctic and Antarctic Regions: The cold polar regions often have stratus clouds, contributing to their characteristically gray skies.

Stratus Clouds and Daily Life

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:

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.

2. Solar Power: Stratus clouds can reduce the effectiveness of solar panels by blocking out sunlight.

3. Aviation: Pilots need to be very careful when flying through stratus clouds because they can greatly reduce visibility.

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!

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.

Fun Facts About Stratus Clouds

Let's explore some interesting tidbits about these gray sky blankets:

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.

2. Natural Air Conditioning: Stratus clouds act like nature's air conditioning, keeping the Earth cool by reflecting sunlight back into space.

3. Cloud Forests: In some mountainous tropical areas, stratus clouds constantly cover the forest, creating a unique ecosystem called a "cloud forest."

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!

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.

Stratus Cloud Variations

While stratus clouds are generally uniform layers, there are a few variations:

1. Stratus Nebulosus: This is the classic, featureless gray layer we typically think of as stratus clouds.

2. Stratus Fractus: These are ragged, broken pieces of stratus clouds, often seen during or after rain.

3. Altostratus: These are similar to stratus but form at higher altitudes, creating a thinner, more translucent layer.

4. Nimbostratus: These are thick, dark stratus clouds that produce steady rain or snow.

Activities to Learn About Stratus Clouds

Even though stratus clouds aren't as visually exciting as some other cloud types, there are still fun ways to learn about them:

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.

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.

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.

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.

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.

Conclusion

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.

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!

So keep your eyes on the skies, young meteorologists, and enjoy exploring the fascinating world of stratus clouds!

--------------------------------------------------------------------------------
checking_agent (to speaker_selection_agent):

Read the above conversation, select the next person from ['Subject_Expert', 'Scheduler', 'Writer'] and only return the role.

--------------------------------------------------------------------------------
2485 tokens saved with text compression.
6 message(s) changed to incorporate name.
speaker_selection_agent (to checking_agent):

Please continue.

--------------------------------------------------------------------------------
>>>>>>>> Select speaker attempt #1 failed as it did not include any agent names.
checking_agent (to speaker_selection_agent):

You didn't choose a speaker. As a reminder, to determine the speaker use these prioritised rules:
1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name
2. If it refers to the "next" speaker name, choose that name
3. Otherwise, choose the first provided speaker's name in the context
The names are case-sensitive and should not be abbreviated or changed.
The only names that are accepted are ['Subject_Expert', 'Scheduler', 'Writer'].
Respond with ONLY the name of the speaker and DO NOT provide a reason.

--------------------------------------------------------------------------------
2487 tokens saved with text compression.
7 message(s) changed to incorporate name.
speaker_selection_agent (to checking_agent):

Scheduler

--------------------------------------------------------------------------------
>>>>>>>> Select speaker attempt 2 of 3 successfully selected: Scheduler

Next speaker: Scheduler

2485 tokens saved with text compression.
6 message(s) changed to incorporate name.
Scheduler (to chat_manager):

'Scheduler' said:
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.

Articles written: 2

Since we've reached our target number of articles, I'll now say: TERMINATE

--------------------------------------------------------------------------------
The cost of the chat was:
{'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}}}
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

There’s a lot to digest in the above code, let’s break it down.

  1. It successfully did the task, getting two articles written (Yay!)
  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
  3. Transform messages show the number of messages incorporating the name and the tokens saved during the process
  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

Additional notes:

  • 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.
  • 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.