AGENTIC AI IN A SIMPLE WAY - How to Make AI Agents That Argue Like a Teacher and Student (Using AutoGen!) ??????
Sudip Dasgupta
GenAI & AI Strategy Leader | ?? Global AI Project & Delivery Expert | ?? Thought Leader in GenAI, Agentic AI, RAG, & Knowledge Graphs | ?? Helping Enterprises Unlock AI Innovation
Ever wanted to watch two AI robots argue about physics? ?? Well, today, we’re going to make that happen!
We’ll create two AI agents:
They will discuss why a ball falls down when you drop it (a.k.a. gravity). And trust me, this conversation is going to be GOLD. ??
?? Prerequisites: Things You Need Before Starting
Before we begin, make sure you have:
? Python installed (version 3.7 or later).
? AutoGen installed (this makes our AI chat possible).
??? Install Python Packages (Do This First!)
Open your terminal (or command prompt) and type this:
pip install autogen
This installs AutoGen, which helps us create talking AI agents in Python.
Done? Great! ?? Let’s start coding!
?? Step 1: Create the AI Teacher and Student
Now, let’s write a simple Python script where:
Here’s the full code:
import autogen # Import autogen (our AI toolbox)
# Step 1: Create an AI world (like a classroom for our AI agents)
world = autogen.World()
# Step 2: Create the AI Teacher
teacher = world.create_agent(
name="Professor Gravity",
system_message="You are a strict but funny physics teacher. "
"You explain things simply, but if the student asks silly questions, respond with sarcasm."
)
# Step 3: Create the AI Student
student = world.create_agent(
name="Timmy the Curious",
system_message="You are a curious but confused student. "
"You ask a lot of weird and funny questions because you don’t fully understand science."
)
# Step 4: The student asks a physics question
question = "Why does a ball fall down when I drop it?" # Timmy is confused about gravity!
print(f"Student: {question}") # Print student's question
# Step 5: The teacher responds
teacher_reply = teacher.ask(question) # AI teacher answers
print(f"Teacher: {teacher_reply}") # Print teacher's reply
# Step 6: The student gets even more confused and asks another question
student_reply = student.ask(teacher_reply) # AI student responds based on what teacher said
print(f"Student: {student_reply}") # Print student's confused response
?? Let’s Break Down the Code (Line by Line!)
?? Step 1: Import the Magic
import autogen
?? What’s Happening?
We are importing AppGen, which is like a magical AI toolkit that helps us create smart and funny talking robots. ??
?? Step 2: Create an AI World
world = autogen.World()
?? What’s Happening?
We are creating an AI world, which is basically a classroom where our AI teacher and student will have their epic nerdy battle. ??
?? Step 3: Create the AI Teacher
teacher = world.create_agent(
name="Professor Gravity",
system_message="You are a strict but funny physics teacher. "
"You explain things simply, but if the student asks silly questions, respond with sarcasm."
)
?? What’s Happening?
We created Professor Gravity, the AI teacher.
? He is very smart and knows everything about physics.
? He is a little sarcastic when students ask dumb questions. ??
领英推荐
?? Step 4: Create the AI Student
student = world.create_agent(
name="Timmy the Curious",
system_message="You are a curious but confused student. "
"You ask a lot of weird and funny questions because you don’t fully understand science."
)
?? What’s Happening?
We created Timmy the Curious, the AI student.
? He loves asking questions (even the weird ones).
? He sometimes misunderstands everything. ??
?? Step 5: The Student Asks a Question
question = "Why does a ball fall down when I drop it?" # Timmy is confused about gravity!
print(f"Student: {question}") # Print student's question
?? What’s Happening?
Timmy (the student) asks a super basic physics question.
But don’t worry – he’s about to get more confused. ??
?? Step 6: The Teacher Explains
teacher_reply = teacher.ask(question) # AI teacher answers
print(f"Teacher: {teacher_reply}") # Print teacher's reply
?? What’s Happening?
Professor Gravity (our teacher) gives a serious answer like: "The ball falls because of gravity, which is the force pulling everything toward Earth."
Sounds smart, right? But wait… Timmy is still confused. ??
?? Step 7: The Student Responds (With More Confusion!)
student_reply = student.ask(teacher_reply) # AI student responds based on what teacher said
print(f"Student: {student_reply}") # Print student's confused response
?? What’s Happening? Timmy completely misunderstands and says something like: "Wait… so the Earth is a GIANT BALL MAGNET?!"
The teacher will probably sigh loudly before explaining again. ??
?? Step 8: Run the Code and Enjoy the Chaos!
When you run the script, here’s what might happen:
Student: Why does a ball fall down when I drop it?
Teacher: The ball falls because of gravity, a force that pulls objects toward the Earth.
Student: Oh! So you're saying the Earth is a giant ball magnet? What if I glue myself to the ground?
Teacher: No, Timmy. Gravity pulls on everything, not just balls. And glue won’t save you.
Student: What if I jump really high? Can I escape gravity?
Teacher: Only if you can jump at 40,270 km/h. Good luck with that. ??
?????? This is what peak AI comedy looks like.
??? Bonus: Customize Your AI Agents!
Want to make this even crazier? Try these:
?? Final Words
? You just built an AI teacher and student that actually talk!
? You now understand Agentic AI in AutoGen!
? You can customize and make them even funnier!
Now go have fun making AI robots argue about science! ????
Lead- Client Success Accenture | PGPM-21 GLIM Chennai | Power BI| IIBA ECBA| Product Management
1 个月Super informative and you just made learning so much fun!