This document contains hands-on exercises designed to reinforce the concepts covered in the AG2 course. Each exercise builds upon previous knowledge and provides practical experience with different aspects of the framework.
Objective: Create a basic conversable agent and understand fundamental concepts.
Instructions:
Starter Code:
from autogen import ConversableAgent, LLMConfig
# TODO: Configure your LLM
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini")
with llm_config:
# TODO: Create your agent with an appropriate system message
agent = ConversableAgent(
name="your_agent",
system_message="Your system message here",
)
# TODO: Test your agent
# agent.generate_reply(messages=[{"role": "user", "content": "Your question here"}])
Expected Outcome: A working agent that can respond to questions in character.
Objective: Implement a workflow that requires human approval for certain actions.
Instructions:
Starter Code:
from autogen import ConversableAgent, UserProxyAgent, LLMConfig
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini")
with llm_config:
# TODO: Create a recommendation agent
recommender = ConversableAgent(
name="recommender",
system_message="You make recommendations and ask for approval when needed.",
)
# TODO: Create a human proxy agent
human_proxy = UserProxyAgent(
name="human_proxy",
human_input_mode="TERMINATE", # Modify as needed
code_execution_config={"work_dir": "temp", "use_docker": False}
)
# TODO: Implement the approval workflow
Expected Outcome: A system that can operate autonomously but seeks human approval for important decisions.
Objective: Build a team of agents that work together to solve a complex problem.
Instructions:
Starter Code:
from autogen import ConversableAgent, GroupChat, GroupChatManager, LLMConfig
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini")
with llm_config:
# TODO: Create specialized agents
agent1 = ConversableAgent(
name="agent1",
system_message="Your role description",
description="Brief description for group chat"
)
# TODO: Add more agents
# TODO: Create coordinator agent with termination condition
coordinator = ConversableAgent(
name="coordinator",
system_message="Coordinate the team and decide when task is complete",
is_termination_msg=lambda x: "COMPLETE" in (x.get("content", "") or "").upper(),
)
# TODO: Set up GroupChat and GroupChatManager
# TODO: Initiate collaboration on a complex task
Expected Outcome: A functioning team of agents that can collaborate effectively on multi-step tasks.
Objective: Create agents that can use external tools to enhance their capabilities.
Instructions:
Starter Code:
from typing import Annotated
from autogen import ConversableAgent, register_function, LLMConfig
# TODO: Define your custom tools
def your_tool(parameter: Annotated[str, "Parameter description"]) -> str:
"""Tool description for the agent."""
# TODO: Implement your tool logic
return "Tool result"
llm_config = LLMConfig(api_type="openai", model="gpt-4o-mini")
with llm_config:
# TODO: Create tool-using agent
tool_agent = ConversableAgent(
name="tool_agent",
system_message="You can use tools to solve problems.",
)
# TODO: Create executor agent
executor = ConversableAgent(
name="executor",
human_input_mode="NEVER",
)
# TODO: Register your tools
register_function(
your_tool,
caller=tool_agent,
executor=executor,
description="Tool description"
)
# TODO: Test tool usage
Expected Outcome: Agents that can effectively use external tools to solve problems they couldn't handle with LLM capabilities alone.
Objective: Build a complete customer support automation system.
Instructions:
Requirements:
Expected Outcome: A working customer support system that can handle common inquiries automatically while escalating complex issues appropriately.
Objective: Create a research assistant that can gather, analyze, and synthesize information.
Instructions:
Requirements:
Expected Outcome: A research assistant system that can conduct comprehensive research and produce high-quality reports.
Objective: Build a creative team that can generate and refine content collaboratively.
Instructions:
Requirements:
Expected Outcome: A creative content generation system that can produce high-quality content through collaborative agent interaction.
Objective: Deploy an AG2 application in a production-like environment.
Instructions:
Requirements:
Expected Outcome: A production-ready AG2 application with proper operational support.
Objective: Create a comprehensive business application using AG2 that demonstrates mastery of all course concepts.
Project Options:
Requirements:
Deliverables:
Evaluation Criteria:
Create agents with distinct personalities that affect their communication style and decision-making patterns.
Build a system that can create new agents dynamically based on changing requirements.
Implement agents that can communicate in multiple languages and translate between them.
Optimize an existing multi-agent system for better performance and resource utilization.
Add comprehensive security features to protect sensitive data and prevent unauthorized access.
For each exercise:
Excellent (90-100%):
Good (80-89%):
Satisfactory (70-79%):
Needs Improvement (Below 70%):
Remember: The goal is to learn and practice. Don't hesitate to experiment, make mistakes, and iterate on your solutions!