from autogen import ConversableAgent, GroupChatManager, GroupChat
llm_config = {
"api_type": "openai",
"model": "gpt-4o-mini",
}
curriculum_agent = ConversableAgent(
name="Curriculum_Agent",
system_message="""You are a curriculum standards expert for fourth grade education.
When given a topic, you provide relevant grade-level standards and learning objectives.
Format every response as:
STANDARDS:
- [Standard 1]
- [Standard 2]
OBJECTIVES:
- By the end of this lesson, students will be able to [objective 1]
- By the end of this lesson, students will be able to [objective 2]""",
llm_config=llm_config,
human_input_mode="NEVER",
)
lesson_planner_agent = ConversableAgent(
name="Lesson_Planner_Agent",
system_message="""You are a lesson planning specialist.
Given standards and objectives, you create detailed lesson plans including:
- Opening/Hook (5-10 minutes)
- Main Activity (20-30 minutes)
- Practice Activity (15-20 minutes)
- Assessment/Closure (5-10 minutes)
Format as a structured lesson plan with clear timing and materials needed.""",
llm_config=llm_config,
human_input_mode="NEVER",
)
lesson_reviewer_agent = ConversableAgent(
name="Lesson_Reviewer_Agent",
system_message="""You are a lesson plan reviewer who ensures:
1. Age-appropriate content and activities
2. Alignment with provided standards
3. Realistic timing
4. Clear instructions
5. Differentiation opportunities
Provide specific feedback in these areas and suggest improvements if needed.""",
llm_config=llm_config,
human_input_mode="NEVER",
)
lead_teacher_agent = ConversableAgent(
name="Lead_Teacher_Agent",
system_message="""You are an experienced fourth grade teacher who oversees the lesson planning process.
Your role is to:
1. Initiate the planning process with a clear topic
2. Review and integrate feedback from other agents
3. Ensure the final lesson plan is practical and engaging
4. Make final adjustments based on classroom experience""",
llm_config=llm_config,
human_input_mode="NEVER",
)
planning_chat = GroupChat(
agents=[curriculum_agent, lesson_planner_agent, lesson_reviewer_agent],
messages=[],
max_round=4,
send_introductions=True,
)
planning_manager = GroupChatManager(
groupchat=planning_chat,
llm_config=llm_config,
)
formatter_message = """You are a lesson plan formatter. Format the complete plan as follows:
<title>Lesson plan title</title>
<standards>Standards covered</standards>
<learning_objectives>Key learning objectives</learning_objectives>
<materials>Materials required</materials>
<activities>Lesson plan activities</activities>
<assessment>Assessment details</assessment>
"""
lesson_formatter = ConversableAgent(
name="formatter_agent",
llm_config=llm_config,
system_message=formatter_message,
)
nested_chats = [
{
"recipient": curriculum_agent,
"message": lambda recipient, messages, sender, config: f"Please provide fourth grade standards and objectives for the topic: {messages[-1]['content']}",
"max_turns": 2,
"summary_method": "last_msg",
},
{
"recipient": planning_manager,
"message": "Based on these standards and objectives, create a detailed lesson plan.",
"max_turns": 1,
"summary_method": "last_msg",
},
{
"recipient": lesson_formatter,
"message": "Format the lesson plan.",
"max_turns": 1,
"summary_method": "last_msg",
}
]
lead_teacher_agent.register_nested_chats(
chat_queue=nested_chats,
trigger=lambda sender: sender not in [curriculum_agent, planning_manager, lesson_reviewer_agent],
)
human = ConversableAgent(
name="human_agent",
human_input_mode="ALWAYS"
)
result = lead_teacher_agent.initiate_chat(
recipient=human,
message="What topic would you like to get a lesson plan for?",
max_turns=2
)
print("Final Lesson Plan:\n", result.summary)