PHL EDU WITH AI • AI Agents Series Part 3/5
AI Agents کیسے کام کرتے ہیں؟
How Do AI Agents Work Internally?
ایجنٹ کا اندرونی نظام — ReAct، Memory، Tools اور Planning
سمجھیں کیسے یہ ذہین پروگرام اتنا ہوشیار ہے!
سمجھیں کیسے یہ ذہین پروگرام اتنا ہوشیار ہے!
The Internal System — ReAct, Memory, Tools and Planning
Understand how this intelligent program is so smart!
Understand how this intelligent program is so smart!
🧠ReAct Loop
💾Memory Types
🔧Tool Calling
🎯Planning
AI Agent کا دماغ — اندر کیا ہوتا ہے؟
Inside an AI Agent’s Brain — What Happens?
جب آپ AI Agent کو کوئی کام دیتے ہیں، تو پردے کے پیچھے ایک پیچیدہ مگر خوبصورت عمل ہوتا ہے۔ Agent سوچتا ہے → عمل کرتا ہے → نتیجہ دیکھتا ہے → دوبارہ سوچتا ہے — یہ چکر تب تک چلتا ہے جب تک کام مکمل نہ ہو۔
When you give a task to an AI Agent, a complex but beautiful process happens behind the scenes. The agent Thinks → Acts → Observes → Thinks Again — this cycle continues until the task is complete.
LLM Brain
سوچنے کا مرکز
The thinking center
Memory
یادداشت کا نظام
Memory system
Tools
کام کے اوزار
Working tools
Planning
منصوبہ بندی
Strategic planning
Action
حقیقی عمل
Real-world action
ReAct Loop — Agent کا سوچنے کا طریقہ
ReAct Loop — How an Agent Thinks
📌 ReAct = Reasoning + Acting — یہ وہ طریقہ ہے جس سے AI Agent سوچتا اور کام کرتا ہے۔ ہر قدم پر وہ سوچتا ہے، کام کرتا ہے، نتیجہ دیکھتا ہے۔
📌 ReAct = Reasoning + Acting — This is how an AI Agent thinks and works. At every step it thinks, acts, then observes the result.
T
🤔 Thought — سوچ
“مجھے MDCAT Biology کے بارے میں معلومات چاہیے۔ میں پہلے Wikipedia سرچ کروں گا۔”
“I need information about MDCAT Biology. I’ll search Wikipedia first.”
A
⚡ Action — عمل
search_tool(“MDCAT Biology Pakistan syllabus 2026”)
Agent نے سرچ ٹول چلایا اور نتائج لیے۔
Agent ran the search tool and got results.
O
👁️ Observation — مشاہدہ
سرچ کے نتائج آئے: “MDCAT میں Biology کے 68 سوالات ہوتے ہیں…” — Agent نے یہ معلومات یاد کر لیں۔
Search results came: “MDCAT has 68 Biology questions…” — Agent stored this information.
T
🤔 Thought — دوبارہ سوچ
“اچھا، اب مجھے یہ معلومات ترتیب دینی ہیں اور MCQs بنانی ہیں۔” — کام مکمل ہونے تک یہ چکر چلتا ہے!
“Good, now I need to organize this info and create MCQs.” — This cycle continues until task is done!
Chain of Thought — سوچ کی زنجیر
Chain of Thought — The Thinking Chain
Chain of Thought یعنی Agent ایک ہی دفعہ جواب نہیں دیتا — وہ مسئلہ چھوٹے چھوٹے حصوں میں توڑتا ہے اور ایک ایک کر کے حل کرتا ہے۔
Chain of Thought means the agent doesn’t just answer immediately — it breaks the problem into small steps and solves them one by one.
❌ بغیر Chain of Thought / Without CoT
سوال: “12 × 15 + 8 کیا ہے؟”
جواب: “188” — غلط یا صحیح بتائے بغیر!
جواب: “188” — غلط یا صحیح بتائے بغیر!
Q: “What is 12 × 15 + 8?”
A: “188” — right or wrong, no explanation!
A: “188” — right or wrong, no explanation!
✅ Chain of Thought کے ساتھ / With CoT
سوال: “12 × 15 + 8 کیا ہے؟”
سوچ: “پہلے 12 × 15 = 180
پھر 180 + 8 = 188″
جواب: “188 ✅” — قدم بہ قدم!
سوچ: “پہلے 12 × 15 = 180
پھر 180 + 8 = 188″
جواب: “188 ✅” — قدم بہ قدم!
Q: “What is 12 × 15 + 8?”
Think: “First 12 × 15 = 180
Then 180 + 8 = 188″
A: “188 ✅” — step by step!
Think: “First 12 × 15 = 180
Then 180 + 8 = 188″
A: “188 ✅” — step by step!
💡 یاد رکھیں: جتنی پیچیدہ مسئلہ، اتنا زیادہ Chain of Thought فائدہ مند۔ یہی وجہ ہے کہ اچھے AI Agents ذہین انسانوں کی طرح “سوچ سوچ کر” کام کرتے ہیں!
💡 Remember: The more complex the problem, the more useful Chain of Thought becomes. This is why good AI Agents work by “thinking carefully” like intelligent humans!
AI Agent کی یادداشت — 4 اقسام
AI Agent Memory — 4 Types
Sensory Memory
ابھی آنے والی معلومات — آپ کا آخری پیغام یا سوال۔ بہت مختصر مدت کے لیے۔
Immediate incoming information — your last message or question. Very short-term.
Short-Term Memory
چل رہی گفتگو کا سیاق و سباق (Context Window)۔ ہزاروں الفاظ تک یاد رکھ سکتا ہے۔
Current conversation context (Context Window). Can remember thousands of words.
Long-Term Memory
بیرونی ڈیٹابیس میں محفوظ یادیں۔ Vector DB استعمال ہوتا ہے۔ مہینوں یاد رہتا ہے!
Memories stored in external database. Vector DB is used. Remembers for months!
Episodic Memory
پچھلے تجربات کی یادیں — کیا کام کیا، کیا نہیں کیا۔ Agent اس سے سیکھتا ہے!
Memories of past experiences — what worked, what didn’t. The agent learns from this!
| Memory Type | مثال / Example | دورانیہ / Duration | ٹول / Tool |
|---|---|---|---|
| Sensory | آپ کا سوال Your question | سیکنڈز | Context |
| Short-Term | پوری گفتگو Full conversation | گھنٹے | Context Window |
| Long-Term | آپ کی پسند Your preferences | مہینے | Vector DB |
| Episodic | پرانے کام Past tasks | ہمیشہ | Database |
Tool Calling — Agent اوزار کیسے استعمال کرتا ہے؟
Tool Calling — How Does an Agent Use Tools?
AI Agent اکیلے بہت محدود ہے۔ لیکن جب اسے ٹولز دے دیے جائیں تو یہ سب کچھ کر سکتا ہے۔ ٹول ایسے ہے جیسے ڈاکٹر کو اوزار دے دیے جائیں — پھر وہ کیا نہیں کر سکتا!
An AI Agent alone is very limited. But when given tools, it can do everything. Tools are like giving a doctor instruments — then what can’t they do!
🌐Web Search
💻Code Executor
📧Email Sender
📊Google Sheets
🗓️Calendar
📁File Manager
🖼️Image Gen
🔔Notifications
💬WhatsApp API
🏦Payment APIs
🗄️Database
🌍Browser Control
مثال: Agent کو ای میل بھیجنے کا کام دیا گیا —
Example: Agent is given the task to send an email —
// Agent سوچتا ہے / Agent thinks:
Thought: “I need to send an email. I’ll use the email_tool.”// Agent ٹول چلاتا ہے / Agent calls tool:
Action: email_tool({
to: “student@example.com”,
subject: “MDCAT Study Plan Ready”,
body: “آپ کا مطالعہ کا منصوبہ تیار ہے…”
})// نتیجہ / Result:
Observation: “Email sent successfully ✅”
Planning Strategies — Agent منصوبہ کیسے بناتا ہے؟
Planning Strategies — How Does an Agent Plan?
| Strategy | کام کا طریقہ / How it Works | بہترین استعمال / Best For |
|---|---|---|
| ReAct | سوچو ← کرو ← دیکھو — بار بار Think ← Do ← Observe — repeatedly | سرچ tasks |
| Plan & Execute | پہلے پورا منصوبہ بناؤ، پھر عمل کرو First build full plan, then execute | Complex projects |
| Tree of Thoughts | کئی راستے آزماؤ، بہترین چنو Explore multiple paths, choose best | Problem solving |
| Reflexion | غلطیوں سے سیکھو اور بہتر کرو Learn from mistakes and improve | Long tasks |
Multi-Agent System — ٹیم میں کام
Multi-Agent System — Working as a Team
بالکل جیسے ہسپتال میں ڈاکٹر، نرس، لیب ٹیکنیشن مل کر مریض کا علاج کرتے ہیں — Multi-Agent System میں کئی AI Agents ٹیم میں کام کرتے ہیں!
Just like a hospital where doctors, nurses, and lab technicians work together to treat a patient — in a Multi-Agent System, several AI Agents work as a team!
| Agent کی قسم / Agent Type | کام / Role | مثال / Example |
|---|---|---|
| 👑 Orchestrator | سربراہ Agent — سب کو ہدایت دیتا ہے Lead agent — gives directions to all | Manager |
| 🔍 Research Agent | انٹرنیٹ سے معلومات لاتا ہے Fetches information from internet | Researcher |
| ✍️ Writer Agent | مواد لکھتا اور ترتیب دیتا ہے Writes and organizes content | Content Writer |
| ✅ Critic Agent | کام چیک کرتا اور غلطیاں بتاتا ہے Reviews work and points out errors | Editor |
| 📤 Publisher Agent | آخری کام publish یا بھیجتا ہے Publishes or delivers final output | Publisher |
🚀 پارٹ 5 میں: ہم آپ کو اپنا Multi-Agent System بنانا سکھائیں گے — CrewAI کی مدد سے!
🚀 In Part 5: We’ll teach you to build your own Multi-Agent System — using CrewAI!
📚 AI Agents مکمل سیریز
📚 Complete AI Agents Series
📖 MDCAT Vocabulary Series
📖 MDCAT Vocabulary Series
🎮 MDCAT پریکٹس گیمز
🎮 MDCAT Practice Game Levels
🔗 مفید لنکس
🔗 Useful Links
📌 خصوصی ہدایات
📌 Special Tips
ReAct loop کو سمجھنا سب سے اہم ہے۔ جب آپ دیکھیں کہ Agent غلطی کر رہا ہے تو اس کی ہدایات بہتر کریں — وہ سیکھے گا!
Understanding the ReAct loop is most important. When you see an agent making mistakes, improve its instructions — it will learn!
Agent کو Long-Term Memory دینا اسے آپ کا ذاتی مددگار بنا دیتا ہے جو آپ کی پسند، عادات اور کام یاد رکھے۔
Giving an agent Long-Term Memory makes it your personal assistant that remembers your preferences, habits and work.
پارٹ 4 میں ہم سیکھیں گے کہ یہ تمام چیزیں کاروبار اور تعلیم میں کیسے استعمال کی جاتی ہیں — بالکل عملی مثالوں کے ساتھ!
In Part 4, we’ll learn how all these things are used in business and education — with completely practical examples!
✦ Team : PHL EDU WITH AI ✦




