AI Agent کیسے کام کرتے ہیں؟ ReAct، میموری، ٹولز اور پلاننگ کی مکمل وضاحت (حصہ 3)
AI Agent Architecture Explained: ReAct, Memory, Tools and Planning (Part 3)
- The model never “runs” a tool itself: it asks for one, your program runs it and returns the result.
- ReAct (2022) lets a model alternate between reasoning and acting; most agent loops descend from it.
- Memory is mostly engineering: the context window plus saved notes and retrieval.
- Anthropic advises starting with the simplest solution and adding agent autonomy only when needed.
The Agent Loop in One Picture
Anthropic’s engineering team separates workflows (code paths fixed in advance) from agents (the model decides the steps and tools). Whatever the framework, an agent is a loop: the model reads the goal and context, chooses an action, the action runs, the result goes back into context, and the loop repeats until the model answers or a limit is reached.
# simplified pseudo-code (not tied to one vendor)
messages = [{"role": "user", "content": "Compare 3 free IELTS prep sites"}]
for step in range(MAX_STEPS): # always cap the loop
reply = model(messages, tools=[web_search, read_page])
if reply.tool_call: # the model only ASKS for a tool
result = run_tool(reply.tool_call) # YOUR code actually runs it
messages += [reply, tool_result(result)]
else:
print(reply.text) # final answer
breakThree consequences follow. The step cap protects you from endless loops and surprise bills. Every tool result is untrusted input. And everything the agent “knows” at any moment must fit in its context.
ReAct Explained: Reason, Act, Observe
ReAct comes from a 2022 research paper by Yao and colleagues. The idea: let the model write a short thought, take an action (such as a search), read the observation, and think again. This reduces guessing because the model checks facts before continuing. Related ideas include chain-of-thought prompting (Wei et al., 2022), which asks the model to reason in steps.
| Step | Example |
|---|---|
| Thought | I need current IELTS fee information. |
| Action | web_search(“IELTS test fee Pakistan”) |
| Observation | Results list from official test providers. |
| Thought | Official source found; I should quote it and note the date. |
Modern “reasoning” models do much of this thinking internally, but the loop around them still follows the same shape.
More on PHL EDU
PHL EDU WITH AI: Empowering your future with free education, AI tools, LMS, and digital skill solutions
How Tool Calling and MCP Work
Tool calling: you describe tools to the model (name, purpose, inputs). When the model decides a tool is needed, it returns a structured request such as a function name and arguments. Your code runs it, then sends the output back. This is why permissions, logging and approval belong in your code, not in the prompt.
MCP (Model Context Protocol): an open standard for connecting AI apps to tools and data, introduced by Anthropic in late 2024. In December 2025, Anthropic donated MCP to the Agentic AI Foundation, a Linux Foundation fund co-founded by Anthropic, Block and OpenAI. Instead of writing a custom connector for every app, a developer can expose a tool once as an MCP server.
A2A (Agent2Agent): a protocol for agents to discover and talk to other agents. Google donated it to the Linux Foundation in June 2025. MCP connects an agent to tools; A2A connects agents to each other.
AI Agent Memory: Short-Term, Long-Term and Retrieval
- Short-term memory: the context window, meaning everything currently sent to the model. It is limited, so long tasks need summaries.
- Long-term memory: information saved outside the model, such as files, a database or a vector database, and loaded back when relevant.
- Retrieval (RAG): searching your documents and giving only the relevant passages to the model, which helps it answer from your own sources.
- Memory types used in research: episodic (what happened before), semantic (facts) and procedural (how to do things).
Memory can also be wrong or poisoned. Store sources with each memory and let users review or delete what the agent saved.
Planning Patterns and Multi-Agent Systems
- Prompt chaining: a fixed sequence of model calls, each using the previous output.
- Routing: classify the request, then send it to a specialised path.
- Parallelization: run independent subtasks at the same time.
- Orchestrator-workers: a lead model splits the task and delegates to worker models.
- Evaluator-optimizer: one model drafts, another critiques, and the draft improves.
- Reflexion and Tree of Thoughts: research methods where the agent learns from failed attempts or explores several reasoning paths.
The first five are patterns described by Anthropic. A multi-agent system applies these ideas with several role-based agents (researcher, writer, reviewer). It can improve quality on complex jobs, but it uses more tokens and adds more places to fail, so use it only when one agent is not enough.
Top AI Agent Frameworks in 2026
| Framework | Best for | Notes |
|---|---|---|
| LangGraph | Stateful, controllable agents | Models agents as graphs; works across many model providers. |
| CrewAI | Role-based agent teams | Fast to prototype; supports MCP and A2A. |
| OpenAI Agents SDK | Lightweight agents on OpenAI | Released March 2025 as the production successor to Swarm. |
| Google ADK | Gemini and Google Cloud | Launched April 2025 with A2A support. |
| Claude Agent SDK | Coding and tool-heavy agents | Renamed from the Claude Code SDK; uses the same harness as Claude Code. |
Why agents fail, and how to test
Common failures: wrong tool choice, looping, ignoring instructions, and following instructions hidden in web pages or emails (prompt injection, ranked first in the OWASP Top 10 for LLM applications). Build a test set of real questions with known good answers, include tricky and hostile inputs, log every step, and re-run the tests after every change.
Next: put this into practice with no-code building in Part 2, see real use cases in Part 4, or follow the full A to Z tutorial in Part 5.
AI Agents Complete Guide: All 5 Parts
- What Are AI Agents? (Part 1)
- How to Build an AI Agent for Free (Part 2)
- AI Agent Architecture: How AI Agents Work (Part 3) (you are here)
- AI Agents for Business & Students (Part 4)
- AI Agent Tutorial A to Z: Build, Test & Deploy (Part 5)
AI Agents مکمل گائیڈ: تمام 5 حصے
- AI Agents کیا ہیں؟ (حصہ 1)
- AI Agent مفت میں کیسے بنائیں (حصہ 2)
- AI Agent کا نظام: یہ کیسے کام کرتے ہیں (حصہ 3) (آپ یہاں ہیں)
- بزنس اور طلباء کے لیے AI Agents (حصہ 4)
- AI Agent ٹیوٹوریل A to Z: بنائیں، ٹیسٹ کریں، Deploy کریں (حصہ 5)
Sources and Further Reading
ذرائع اور مزید مطالعہ
- Anthropic: Building effective agents
- ReAct paper (Yao et al., 2022)
- Chain-of-Thought paper (Wei et al., 2022)
- Reflexion paper (Shinn et al., 2023)
- Tree of Thoughts paper (Yao et al., 2023)
- Model Context Protocol
- OWASP GenAI Security Project
Facts and prices in this guide were last checked in October 2026. Tools change quickly, so confirm current details on each official website.
اس گائیڈ کی معلومات اور قیمتیں اکتوبر 2026 میں چیک کی گئی تھیں۔ ٹولز تیزی سے بدلتے ہیں، اس لیے ہر آفیشل ویب سائٹ پر موجودہ تفصیل ضرور دیکھیں۔
Frequently Asked Questions
What is AI agent architecture?
It is the design of an agent: a model for reasoning, instructions, tools to take actions, memory for context, and a loop that checks results. Guardrails and human approval sit around it.
What is a ReAct agent?
A ReAct agent alternates between reasoning and acting: it writes a thought, uses a tool, reads the result and repeats. The idea comes from a 2022 research paper by Yao and colleagues.
What is MCP in AI agents?
Model Context Protocol is an open standard for connecting AI apps to tools and data. Anthropic introduced it in 2024 and donated it to the Linux Foundation’s Agentic AI Foundation in December 2025.
Do AI agents really learn from experience?
Not automatically. They usually improve within a task through feedback, and across tasks only if you give them memory such as saved notes. Training a new model is a separate process.
Which AI agent framework should a beginner learn first?
Start with a no-code tool like n8n or Make to learn the ideas. If you code in Python, CrewAI is quick for prototypes and LangGraph gives more control.
PHL EDU Old Posts
PHL EDU WITH AI: Empowering your future with free education, AI tools, LMS, and digital skill solutions
PHL EDU Eco System
Explore more free tools from PHL EDU WITH AI:




