跳到主要内容

为非OpenAI模型转换消息

Open In Colab Open on GitHub

除了OpenAI之外,还有多种模型可供选择,而且它们各自具有不同的功能。较小的上下文窗口和不同的API可能需要调整您的工作流程,以便与它们配合使用。

如果你对转换消息不熟悉,请参阅转换消息介绍

减少上下文大小

尽管上下文窗口在不断增加,但仍有许多模型的上下文窗口较小(例如2K、4K或8K token),这些窗口可能无法处理你的工作流程中的消息。

要使用变换处理更长的上下文,基本上是为了在较小的上下文窗口中有效地减少它们,请参阅压缩文本页面。

整合代理的名称

有趣的是,当使用非OpenAI模型时,如以下示例中的Jack这样的代理名称并不包含在消息中。这意味着在推理过程中,模型无法知晓该名称,除非我们将它包含在消息文本的主体中。

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

当使用OpenAI模型时,名称字段被包含在内,AutoGen文档中的示例可能依赖于这一事实。因此,它在您现有的工作流程中可能不会成为问题,但重要的是要意识到并能够处理它。

在下面的简单双代理聊天示例中,我们将使用TextMessageContentName变换(可从Transforms模块中获得),将代理的名称添加到消息中。

由于我们不会使用OpenAI,我们将使用Anthropic客户端进行演示。

我们首先导入模块并设置配置。

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

现在我们添加两个代理,他们都是喜剧演员,将会用对方的名字编笑话。

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",
)

让我们在不使用transform的情况下开始聊天,看看它的表现如何。

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?

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

从聊天中可以看出,Cathy一开始并不知道Joe的名字。

现在,我们将创建一个转换,将名称注入消息中,并将该转换应用于两个代理。

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

既然我们注入了这些名称,让我们再次尝试那个聊天。

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?

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

我们可以从这段对话中看到,Cathy在她的第一条回复信息中使用了Joe的名字,这表明通过使用转换来整合名字使得Cathy代理能够识别Joe。

在上述情况下,当群聊管理器基于name选择代理时,使用auto选择模式(默认)的群聊中,所使用的变换变得至关重要。

在群聊中转换

如上所述,在使用非OpenAI模型时,在使用auto代理选择模式时,将代理名称注入到消息中非常重要。这样做可以让模型更好地理解每个消息属于哪个代理。

此外,群聊可能会涉及大量消息,因此也会消耗大量token。为了帮助保持模型上下文窗口内的上下文,可以使用压缩转换。

以下是一个结合了这两种转换的群聊示例,并依赖于LLM使用代理名称来确定和选择下一个代理。

我们将使用之前示例中的Anthropic的Claude 3.5 Sonnet配置作为所有代理和群聊管理器(用于选择下一个发言的代理)的LLM。

示例中的场景是制作两篇关于云层形成的适合儿童阅读的长篇文章。

让我们从创建三名团队成员开始:

  • Subject_Expert 将选择一个云形成并提供一些关于它的要点。
  • Writer 将根据选定的云服务生成基于要点的长篇内容,大约2000字。
  • 调度器负责将任务传递给群组聊天管理器,确定是否需要继续编写更多文章,并通过说‘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",
)

现在我们创建两个转换,一个用于注入name,另一个用于压缩消息,如果所有消息组合的估计标记数超过1,000个标记。

由于这些转换将应用于在群聊中嵌套的聊天,其中下一个发言者被选择,我们向转换添加一个过滤器,使其不应用于system消息和来自checking_agent的消息,checking_agent是嵌套聊天中选择下一个发言者的代理。

这些排除项用于最小化那些消息中的指令丢失,因为它们对说话者选择至关重要。

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,
]
)

创建了转换后,我们可以将它们应用到群聊的选择 发言者嵌套聊天中。

除了将变换应用于群聊的select_speaker_transform_messages参数外,我们还提供了关于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 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)

开始聊天并显示最终费用。

注意:群聊中的select_speaker_auto_verbose已设置为True,因此你可以在每条消息之间看到说话者选择的过程。

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

上面的代码中需要理解的内容很多,让我们来分解一下。

  1. 它成功完成了任务,写了两篇文章(耶!)
  2. 代理的顺序已成功选择:从Scheduler到Subject_Expert再到Writer,然后返回到Scheduler到Subject_Expert再到Writer再到Scheduler,最后由Scheduler终止。
  3. 转换消息显示包含名称以及在过程中保存的令牌的消息数量
  4. 我们偶尔会看到下一个代理名称“请继续。”被LLM提出,这是因为这些继续消息被编织在发送给Anthropic的API的消息中。这通过选择发言者重试处理得很好,但进一步的提示调整可以帮助消除这些异常。

附加说明:

  • 如果没有这些转换,这还能正常工作吗?移除转换后,运行产生了以下不正确的序列:从 Scheduler 到 Subject_Export 再到 Writer,然后返回到 Writer,最后到 Scheduler。
  • 调整 - 调整系统消息和代理描述以及群聊选择发言者嵌套聊天在引导LLM到正确输出方面也起到了很大作用。可能需要结合提示工程和转换来实现一致的结果。