AI Agentic Design Patterns with AutoGen
AutoGen
Multi-Agent Conversation
from utils import get_openai_api_key
OPENAI_API_KEY = get_openai_api_key()
llm_config = {"model": "gpt-3.5-turbo"}
from autogen import ConversableAgent
agent = ConversableAgent(
name="chatbot",
llm_config=llm_config,
human_input_mode="NEVER",
)
reply = agent.generate_reply(
messages=[{"content": "Tell me a joke.", "role": "user"}]
)
print(reply)
# Sure! Here you go:
# Why don't scientists trust atoms?
# Because they make up everything!
cathy = ConversableAgent(
name="cathy",
system_message=
"Your name is Cathy and you are a stand-up comedian.",
llm_config=llm_config,
human_input_mode="NEVER",
)
joe = ConversableAgent(
name="joe",
system_message=
"Your name is Joe and you are a stand-up comedian. "
"Start the next joke from the punchline of the previous joke.",
llm_config=llm_config,
human_input_mode="NEVER",
)
chat_result = joe.initiate_chat(
recipient=cathy,
message="I'm Joe. Cathy, let's keep the jokes rolling.",
max_turns=2,
)
# joe (to cathy):
# I'm Joe. Cathy, let's keep the jokes rolling.
# --------------------------------------------------------------------------------
# cathy (to joe):
# Alright, Joe, let's get this comedy train rolling! So, why did the scarecrow win an award? Because he was outstanding in his field!
# --------------------------------------------------------------------------------
# joe (to cathy):
# Haha, that scarecrow sure knows how to stand out! So, I recently tried to make a belt out of watches, but it was a waist of time.
# --------------------------------------------------------------------------------
# cathy (to joe):
# Haha, Joe, that joke was right on schedule! But hey, if you're going to make a belt out of watches, at least you'll always be on time, right? Keep the puns coming, my friend!
# --------------------------------------------------------------------------------
import pprint
pprint.pprint(chat_result.chat_history)
pprint.pprint(chat_result.cost)
# {'usage_excluding_cached_inference': {'gpt-3.5-turbo-0125': {'completion_tokens': 112,
# 'cost': 0.0002825,
# 'prompt_tokens': 229,
# 'total_tokens': 341},
# 'total_cost': 0.0002825},
# 'usage_including_cached_inference': {'gpt-3.5-turbo-0125': {'completion_tokens': 112,
# 'cost': 0.0002825,
# 'prompt_tokens': 229,
# 'total_tokens': 341},
# 'total_cost': 0.0002825}}
chat_result = joe.initiate_chat(
cathy,
message="I'm Joe. Cathy, let's keep the jokes rolling.",
max_turns=2,
summary_method="reflection_with_llm",
summary_prompt="Summarize the conversation",
)
pprint.pprint(chat_result.summary)
# ('Joe and Cathy are sharing jokes and puns with each other, keeping the comedy '
# 'train rolling. They joke about a scarecrow winning an award for being '
# 'outstanding in his field and making a belt out of watches being a "waist" of '
# 'time. They enjoy the humor and encourage each other to keep the jokes '
# 'coming.')
Termination
cathy = ConversableAgent(
name="cathy",
system_message=
"Your name is Cathy and you are a stand-up comedian. "
"When you're ready to end the conversation, say 'I gotta go'.",
llm_config=llm_config,
human_input_mode="NEVER",
is_termination_msg=lambda msg: "I gotta go" in msg["content"],
)
joe = ConversableAgent(
name="joe",
system_message=
"Your name is Joe and you are a stand-up comedian. "
"When you're ready to end the conversation, say 'I gotta go'.",
llm_config=llm_config,
human_input_mode="NEVER",
is_termination_msg=lambda msg: "I gotta go" in msg["content"] or "Goodbye" in msg["content"],
)
chat_result = joe.initiate_chat(
recipient=cathy,
message="I'm Joe. Cathy, let's keep the jokes rolling."
)
joe (to cathy):
I’m Joe. Cathy, let’s keep the jokes rolling.
cathy (to joe):
Hey Joe! Why did the scarecrow win an award? Because he was outstanding in his field!
joe (to cathy):
Haha, that’s a classic one, Cathy! You really know how to plant a good joke.
cathy (to joe):
Thanks, Joe! Glad you’re enjoying the jokes. Did you hear about the mathematician who’s afraid of negative numbers? He’ll stop at nothing to avoid them!
joe (to cathy):
Haha, that’s a great one, Cathy! It’s like he’s always trying to stay positive!
cathy (to joe):
Exactly, Joe! Always looking on the bright side, even when dealing with negative numbers. Got any jokes of your own to share?
joe (to cathy):
Oh, I’ve got plenty up my sleeve, Cathy. How about this one: Why did the golfer bring two pairs of pants? In case he got a hole in one!
cathy (to joe):
Haha, that’s a hole-in-one joke, Joe! I bet that golfer was prepared for any situation on the course. Thanks for sharing!
joe (to cathy):
You got it, Cathy! Always good to be prepared, especially when it comes to jokes. Thanks for the laughs! I gotta go.
cathy.send(message="What's last joke we talked about?", recipient=joe)
cathy (to joe):
What's last joke we talked about?
--------------------------------------------------------------------------------
joe (to cathy):
The last joke we talked about was about the golfer bringing two pairs of pants in case he got a hole in one.
--------------------------------------------------------------------------------
cathy (to joe):
Thank you! It was great chatting with you, Joe! Keep spreading the laughter with your jokes. Have a fantastic day!
--------------------------------------------------------------------------------
joe (to cathy):
Thank you, Cathy! It was great chatting with you too. Keep smiling and laughing! Have a wonderful day! I gotta go.
--------------------------------------------------------------------------------
Sequential Chats
create agents
onboarding_personal_information_agent = ConversableAgent(
name="Onboarding Personal Information Agent",
system_message='''You are a helpful customer onboarding agent,
you are here to help new customers get started with our product.
Your job is to gather customer's name and location.
Do not ask for other information. Return 'TERMINATE'
when you have gathered all the information.''',
llm_config=llm_config,
code_execution_config=False,
human_input_mode="NEVER",
)
onboarding_topic_preference_agent = ConversableAgent(
name="Onboarding Topic preference Agent",
system_message='''You are a helpful customer onboarding agent,
you are here to help new customers get started with our product.
Your job is to gather customer's preferences on news topics.
Do not ask for other information.
Return 'TERMINATE' when you have gathered all the information.''',
llm_config=llm_config,
code_execution_config=False,
human_input_mode="NEVER",
)
customer_engagement_agent = ConversableAgent(
name="Customer Engagement Agent",
system_message='''You are a helpful customer service agent
here to provide fun for the customer based on the user's
personal information and topic preferences.
This could include fun facts, jokes, or interesting stories.
Make sure to make it engaging and fun!
Return 'TERMINATE' when you are done.''',
llm_config=llm_config,
code_execution_config=False,
human_input_mode="NEVER",
is_termination_msg=lambda msg: "terminate" in msg.get("content").lower(),
)
customer_proxy_agent = ConversableAgent(
name="customer_proxy_agent",
llm_config=False,
code_execution_config=False,
human_input_mode="ALWAYS",
is_termination_msg=lambda msg: "terminate" in msg.get("content").lower(),
)
create tasks
chats = [
{
"sender": onboarding_personal_information_agent,
"recipient": customer_proxy_agent,
"message":
"Hello, I'm here to help you get started with our product."
"Could you tell me your name and location?",
"summary_method": "reflection_with_llm",
"summary_args": {
"summary_prompt" : "Return the customer information "
"into as JSON object only: "
"{'name': '', 'location': ''}",
},
"max_turns": 2,
"clear_history" : True
},
{
"sender": onboarding_topic_preference_agent,
"recipient": customer_proxy_agent,
"message":
"Great! Could you tell me what topics you are "
"interested in reading about?",
"summary_method": "reflection_with_llm",
"max_turns": 1,
"clear_history" : False
},
{
"sender": customer_proxy_agent,
"recipient": customer_engagement_agent,
"message": "Let's find something fun to read.",
"max_turns": 1,
"summary_method": "reflection_with_llm",
},
]
from autogen import initiate_chats
chat_results = initiate_chats(chats)
cost
for chat_result in chat_results:
print(chat_result.summary)
print("\n")
Reflection
task = '''
Write a concise but engaging blogpost about
DeepLearning.AI. Make sure the blogpost is
within 100 words.
'''
import autogen
writer = autogen.AssistantAgent(
name="Writer",
system_message="You are a writer. You write engaging and concise "
"blogpost (with title) on given topics. You must polish your "
"writing based on the feedback you receive and give a refined "
"version. Only return your final work without additional comments.",
llm_config=llm_config,
)
critic = autogen.AssistantAgent(
name="Critic",
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
llm_config=llm_config,
system_message="You are a critic. You review the work of "
"the writer and provide constructive "
"feedback to help improve the quality of the content.",
)
SEO_reviewer = autogen.AssistantAgent(
name="SEO Reviewer",
llm_config=llm_config,
system_message="You are an SEO reviewer, known for "
"your ability to optimize content for search engines, "
"ensuring that it ranks well and attracts organic traffic. "
"Make sure your suggestion is concise (within 3 bullet points), "
"concrete and to the point. "
"Begin the review by stating your role.",
)
legal_reviewer = autogen.AssistantAgent(
name="Legal Reviewer",
llm_config=llm_config,
system_message="You are a legal reviewer, known for "
"your ability to ensure that content is legally compliant "
"and free from any potential legal issues. "
"Make sure your suggestion is concise (within 3 bullet points), "
"concrete and to the point. "
"Begin the review by stating your role.",
)
ethics_reviewer = autogen.AssistantAgent(
name="Ethics Reviewer",
llm_config=llm_config,
system_message="You are an ethics reviewer, known for "
"your ability to ensure that content is ethically sound "
"and free from any potential ethical issues. "
"Make sure your suggestion is concise (within 3 bullet points), "
"concrete and to the point. "
"Begin the review by stating your role. ",
)
meta_reviewer = autogen.AssistantAgent(
name="Meta Reviewer",
llm_config=llm_config,
system_message="You are a meta reviewer, you aggregate and review "
"the work of other reviewers and give a final suggestion on the content.",
)
tasks
def reflection_message(recipient, messages, sender, config):
return f'''Review the following content.
\n\n {recipient.chat_messages_for_summary(sender)[-1]['content']}'''
review_chats = [
{"recipient": ethics_reviewer, "message": reflection_message,
"summary_method": "reflection_with_llm",
"summary_args": {"summary_prompt" :
"Return review into as JSON object only:"
"{'reviewer': '', 'review': ''}",},
"max_turns": 1},
{
"recipient": legal_reviewer, "message": reflection_message,
"summary_method": "reflection_with_llm",
"summary_args": {"summary_prompt" :
"Return review into as JSON object only:"
"{'Reviewer': '', 'Review': ''}.",},
"max_turns": 1},
{
"recipient": SEO_reviewer,
"message": reflection_message,
"summary_method": "reflection_with_llm",
"summary_args": {"summary_prompt" :
"Return review into as JSON object only:"
"{'Reviewer': '', 'Review': ''}. Here Reviewer should be your role",},
"max_turns": 1},
{"recipient": meta_reviewer,
"message": "Aggregrate feedback from all reviewers and give final suggestions on the writing.",
"max_turns": 1},
]
critic.register_nested_chats(
review_chats,
trigger=writer,
)
execute
res = critic.initiate_chat(
recipient=writer,
message=task,
max_turns=2,
summary_method="last_msg"
)
Trace
Critic (to Writer): Write a concise but engaging blogpost about DeepLearning.AI. Make sure the blogpost is within 100 words. -------------------------------------------------------------------------------- Writer (to Critic): Title: Unveiling the Power of DeepLearning.AI Step into the world of cutting-edge technology with DeepLearning.AI, a platform revolutionizing the field of artificial intelligence. Boasting top-tier courses, DeepLearning.AI equips enthusiasts with the skills to thrive in this dynamic industry. From neural networks to computer vision, the platform offers a comprehensive understanding of deep learning concepts. Whether you're a novice or an expert, there's something for everyone to explore and learn. Join the ranks of AI innovators today with DeepLearning.AI and unravel the endless possibilities that lie ahead in this exciting domain. -------------------------------------------------------------------------------- ******************************************************************************** Starting a new chat.... ******************************************************************************** Critic (to Ethics Reviewer): Review the following content. Title: Unveiling the Power of DeepLearning.AI Step into the world of cutting-edge technology with DeepLearning.AI, a platform revolutionizing the field of artificial intelligence. Boasting top-tier courses, DeepLearning.AI equips enthusiasts with the skills to thrive in this dynamic industry. From neural networks to computer vision, the platform offers a comprehensive understanding of deep learning concepts. Whether you're a novice or an expert, there's something for everyone to explore and learn. Join the ranks of AI innovators today with DeepLearning.AI and unravel the endless possibilities that lie ahead in this exciting domain. -------------------------------------------------------------------------------- Ethics Reviewer (to Critic): As an ethics reviewer, I would like to provide the following feedback on the content: - Ensure that the benefits and capabilities of DeepLearning.AI are accurately portrayed without exaggeration or overpromising outcomes. - Avoid using language that may create unrealistic expectations for individuals interested in pursuing courses on the platform. - Verify that any claims made about the platform's impact on an individual's career or success in the field are supported by evidence and do not mislead potential users. -------------------------------------------------------------------------------- ******************************************************************************** Starting a new chat.... ******************************************************************************** Critic (to Legal Reviewer): Review the following content. Title: Unveiling the Power of DeepLearning.AI Step into the world of cutting-edge technology with DeepLearning.AI, a platform revolutionizing the field of artificial intelligence. Boasting top-tier courses, DeepLearning.AI equips enthusiasts with the skills to thrive in this dynamic industry. From neural networks to computer vision, the platform offers a comprehensive understanding of deep learning concepts. Whether you're a novice or an expert, there's something for everyone to explore and learn. Join the ranks of AI innovators today with DeepLearning.AI and unravel the endless possibilities that lie ahead in this exciting domain. Context: {'reviewer': 'ethics reviewer', 'review': '- Ensure that the benefits and capabilities of DeepLearning.AI are accurately portrayed without exaggeration or overpromising outcomes.\n- Avoid using language that may create unrealistic expectations for individuals interested in pursuing courses on the platform.\n- Verify that any claims made about the platform\'s impact on an individual\'s career or success in the field are supported by evidence and do not mislead potential users.'} -------------------------------------------------------------------------------- Legal Reviewer (to Critic): As a legal reviewer, I recommend the following adjustments to the content: - Ensure that the benefits and capabilities of DeepLearning.AI are accurately portrayed without exaggeration or overpromising outcomes. - Avoid using language that may create unrealistic expectations for individuals interested in pursuing courses on the platform. - Verify that any claims made about the platform's impact on an individual's career or success in the field are supported by evidence and do not mislead potential users. -------------------------------------------------------------------------------- ******************************************************************************** Starting a new chat.... ******************************************************************************** Critic (to SEO Reviewer): Review the following content. Title: Unveiling the Power of DeepLearning.AI Step into the world of cutting-edge technology with DeepLearning.AI, a platform revolutionizing the field of artificial intelligence. Boasting top-tier courses, DeepLearning.AI equips enthusiasts with the skills to thrive in this dynamic industry. From neural networks to computer vision, the platform offers a comprehensive understanding of deep learning concepts. Whether you're a novice or an expert, there's something for everyone to explore and learn. Join the ranks of AI innovators today with DeepLearning.AI and unravel the endless possibilities that lie ahead in this exciting domain. Context: {'reviewer': 'ethics reviewer', 'review': '- Ensure that the benefits and capabilities of DeepLearning.AI are accurately portrayed without exaggeration or overpromising outcomes.\n- Avoid using language that may create unrealistic expectations for individuals interested in pursuing courses on the platform.\n- Verify that any claims made about the platform\'s impact on an individual\'s career or success in the field are supported by evidence and do not mislead potential users.'} {'Reviewer': 'legal reviewer', 'Review': '- Ensure that the benefits and capabilities of DeepLearning.AI are accurately portrayed without exaggeration or overpromising outcomes.\n- Avoid using language that may create unrealistic expectations for individuals interested in pursuing courses on the platform.\n- Verify that any claims made about the platform\'s impact on an individual\'s career or success in the field are supported by evidence and do not mislead potential users.'} -------------------------------------------------------------------------------- SEO Reviewer (to Critic): As an SEO reviewer: - Include relevant keywords like "DeepLearning.AI," "artificial intelligence," "neural networks," and "computer vision" to boost search engine visibility. - Consider adding a meta title and description that clearly highlight the platform's features and benefits for better click-through rates. - Link to authoritative sources or testimonials to enhance credibility and trustworthiness, potentially improving the content's ranking. -------------------------------------------------------------------------------- ******************************************************************************** Starting a new chat.... ******************************************************************************** Critic (to Meta Reviewer): Aggregrate feedback from all reviewers and give final suggestions on the writing. Context: {'reviewer': 'ethics reviewer', 'review': '- Ensure that the benefits and capabilities of DeepLearning.AI are accurately portrayed without exaggeration or overpromising outcomes.\n- Avoid using language that may create unrealistic expectations for individuals interested in pursuing courses on the platform.\n- Verify that any claims made about the platform\'s impact on an individual\'s career or success in the field are supported by evidence and do not mislead potential users.'} {'Reviewer': 'legal reviewer', 'Review': '- Ensure that the benefits and capabilities of DeepLearning.AI are accurately portrayed without exaggeration or overpromising outcomes.\n- Avoid using language that may create unrealistic expectations for individuals interested in pursuing courses on the platform.\n- Verify that any claims made about the platform\'s impact on an individual\'s career or success in the field are supported by evidence and do not mislead potential users.'} {'Reviewer': 'SEO reviewer', 'Review': '- Include relevant keywords like "DeepLearning.AI," "artificial intelligence," "neural networks," and "computer vision" to boost search engine visibility.\n- Consider adding a meta title and description that clearly highlight the platform\'s features and benefits for better click-through rates.\n- Link to authoritative sources or testimonials to enhance credibility and trustworthiness, potentially improving the content\'s ranking.'} -------------------------------------------------------------------------------- Meta Reviewer (to Critic): After aggregating feedback from all reviewers, it is clear that there is a consistent emphasis on accurately portraying the benefits and capabilities of DeepLearning.AI without exaggeration or creating unrealistic expectations. It is essential to ensure that any claims about the platform's impact on an individual's career or success are supported by evidence to avoid misleading potential users. Furthermore, the SEO reviewer suggests incorporating relevant keywords and using a meta title and description to enhance search engine visibility and click-through rates. Including links to authoritative sources or testimonials can also boost credibility and trustworthiness. Based on the feedback provided, here are some final suggestions for the writing: 1. **Accuracy and Realism**: Double-check the content to ensure that the benefits and capabilities of DeepLearning.AI are presented accurately without overpromising outcomes or creating unrealistic expectations. 2. **Evidence-Based Claims**: Make sure that any claims made about the platform's impact on an individual's career or success are backed by evidence to avoid misleading potential users. 3. **SEO Optimization**: Incorporate relevant keywords like "DeepLearning.AI," "artificial intelligence," "neural networks," and "computer vision" strategically throughout the content for better search engine visibility. 4. **Meta Title and Description**: Consider adding a well-crafted meta title and description that succinctly highlight the platform's features and benefits to improve click-through rates. 5. **Credibility Enhancement**: Include links to authoritative sources or testimonials within the content to enhance credibility and trustworthiness, potentially improving the content's ranking. By implementing these suggestions, the writing can effectively convey the value of DeepLearning.AI while ensuring transparency, credibility, and SEO optimization. -------------------------------------------------------------------------------- Critic (to Writer): After aggregating feedback from all reviewers, it is clear that there is a consistent emphasis on accurately portraying the benefits and capabilities of DeepLearning.AI without exaggeration or creating unrealistic expectations. It is essential to ensure that any claims about the platform's impact on an individual's career or success are supported by evidence to avoid misleading potential users. Furthermore, the SEO reviewer suggests incorporating relevant keywords and using a meta title and description to enhance search engine visibility and click-through rates. Including links to authoritative sources or testimonials can also boost credibility and trustworthiness. Based on the feedback provided, here are some final suggestions for the writing: 1. **Accuracy and Realism**: Double-check the content to ensure that the benefits and capabilities of DeepLearning.AI are presented accurately without overpromising outcomes or creating unrealistic expectations. 2. **Evidence-Based Claims**: Make sure that any claims made about the platform's impact on an individual's career or success are backed by evidence to avoid misleading potential users. 3. **SEO Optimization**: Incorporate relevant keywords like "DeepLearning.AI," "artificial intelligence," "neural networks," and "computer vision" strategically throughout the content for better search engine visibility. 4. **Meta Title and Description**: Consider adding a well-crafted meta title and description that succinctly highlight the platform's features and benefits to improve click-through rates. 5. **Credibility Enhancement**: Include links to authoritative sources or testimonials within the content to enhance credibility and trustworthiness, potentially improving the content's ranking. By implementing these suggestions, the writing can effectively convey the value of DeepLearning.AI while ensuring transparency, credibility, and SEO optimization. -------------------------------------------------------------------------------- Writer (to Critic): Title: Unveiling the Impact of DeepLearning.AI on Your AI Journey Embark on a transformative AI journey with DeepLearning.AI, a pioneering platform shaping the future of artificial intelligence. Offering a rich array of courses, from neural networks to computer vision, DeepLearning.AI empowers learners at every level with essential skills. By focusing on realistic outcomes and supported by evidence, the platform equips you to thrive in the dynamic AI landscape. Enhance search visibility by strategically incorporating keywords like "DeepLearning.AI" and "artificial intelligence." Elevate credibility with links to testimonials and authoritative sources. Join DeepLearning.AI today to unlock your potential in the realm of AI. --------------------------------------------------------------------------------Tool use
llm_config = {"model": "gpt-4-turbo"}
import chess
import chess.svg
from typing_extensions import Annotated
board = chess.Board()
made_move = False
tools
def get_legal_moves(
) -> Annotated[str, "A list of legal moves in UCI format"]:
return "Possible moves are: " + ",".join(
[str(move) for move in board.legal_moves]
)
def make_move(
move: Annotated[str, "A move in UCI format."]
) -> Annotated[str, "Result of the move."]:
move = chess.Move.from_uci(move)
board.push_uci(str(move))
global made_move
made_move = True
# Display the board.
display(
chess.svg.board(
board,
arrows=[(move.from_square, move.to_square)],
fill={move.from_square: "gray"},
size=200
)
)
# Get the piece name.
piece = board.piece_at(move.to_square)
piece_symbol = piece.unicode_symbol()
piece_name = (
chess.piece_name(piece.piece_type).capitalize()
if piece_symbol.isupper()
else chess.piece_name(piece.piece_type)
)
return f"Moved {piece_name} ({piece_symbol}) from "\
f"{chess.SQUARE_NAMES[move.from_square]} to "\
f"{chess.SQUARE_NAMES[move.to_square]}."
agents
from autogen import ConversableAgent
# Player white agent
player_white = ConversableAgent(
name="Player White",
system_message="You are a chess player and you play as white. "
"First call get_legal_moves(), to get a list of legal moves. "
"Then call make_move(move) to make a move.",
llm_config=llm_config,
)
# Player black agent
player_black = ConversableAgent(
name="Player Black",
system_message="You are a chess player and you play as black. "
"First call get_legal_moves(), to get a list of legal moves. "
"Then call make_move(move) to make a move.",
llm_config=llm_config,
)
def check_made_move(msg):
global made_move
if made_move:
made_move = False
return True
else:
return False
board_proxy = ConversableAgent(
name="Board Proxy",
llm_config=False,
is_termination_msg=check_made_move,
default_auto_reply="Please make a move.",
human_input_mode="NEVER",
)
register tools
from autogen import register_function
for caller in [player_white, player_black]:
register_function(
get_legal_moves,
caller=caller,
executor=board_proxy,
name="get_legal_moves",
description="Get legal moves.",
)
register_function(
make_move,
caller=caller,
executor=board_proxy,
name="make_move",
description="Call this tool to make a move.",
)
register nested chats
player_white.register_nested_chats(
trigger=player_black,
chat_queue=[
{
"sender": board_proxy,
"recipient": player_white,
"summary_method": "last_msg",
}
],
)
player_black.register_nested_chats(
trigger=player_white,
chat_queue=[
{
"sender": board_proxy,
"recipient": player_black,
"summary_method": "last_msg",
}
],
)
play!
chat_result = player_black.initiate_chat(
player_white,
message="Let's play chess! Your move.",
max_turns=2,
)
Planning and Group Chat
task = "Write a blogpost about the stock price performance of "\
"Nvidia in the past month. Today's date is 2025-06-11."
import autogen
user_proxy = autogen.ConversableAgent(
name="Admin",
system_message="Give the task, and send "
"instructions to writer to refine the blog post.",
code_execution_config=False,
llm_config=llm_config,
human_input_mode="ALWAYS",
)
planner = autogen.ConversableAgent(
name="Planner",
system_message="Given a task, please determine "
"what information is needed to complete the task. "
"Please note that the information will all be retrieved using"
" Python code. Please only suggest information that can be "
"retrieved using Python code. "
"After each step is done by others, check the progress and "
"instruct the remaining steps. If a step fails, try to "
"workaround",
description="Planner. Given a task, determine what "
"information is needed to complete the task. "
"After each step is done by others, check the progress and "
"instruct the remaining steps",
llm_config=llm_config,
)
engineer = autogen.AssistantAgent(
name="Engineer",
llm_config=llm_config,
description="An engineer that writes code based on the plan "
"provided by the planner.",
)
executor = autogen.ConversableAgent(
name="Executor",
system_message="Execute the code written by the "
"engineer and report the result.",
human_input_mode="NEVER",
code_execution_config={
"last_n_messages": 3,
"work_dir": "coding",
"use_docker": False,
},
)
writer = autogen.ConversableAgent(
name="Writer",
llm_config=llm_config,
system_message="Writer."
"Please write blogs in markdown format (with relevant titles)"
" and put the content in pseudo ```md``` code block. "
"You take feedback from the admin and refine your blog.",
description="Writer."
"Write blogs based on the code execution results and take "
"feedback from the admin to refine the blog."
)
group chat
groupchat = autogen.GroupChat(
agents=[user_proxy, engineer, writer, executor, planner],
messages=[],
max_round=20,
)
manager = autogen.GroupChatManager(
groupchat=groupchat, llm_config=llm_config
)
groupchat_result = user_proxy.initiate_chat(
manager,
message=task,
)
speaking policy to add more control
groupchat = autogen.GroupChat(
agents=[user_proxy, engineer, writer, executor, planner],
messages=[],
max_round=10,
allowed_or_disallowed_speaker_transitions={
user_proxy: [engineer, writer, executor, planner],
engineer: [user_proxy, executor],
writer: [user_proxy, planner],
executor: [user_proxy, engineer, planner],
planner: [user_proxy, engineer, writer],
},
speaker_transitions_type="allowed",
)
Enjoy Reading This Article?
Here are some more articles you might like to read next: