Mod 1.1AI Agents and their Core Components
Level 1›Module 1.1
Module 1.145 min

AI Agents and their Core Components

Understand what makes an AI system an agent, explore its core components, and see how they work together.

By the end of this module, you will:

  • Understand what an AI agent is and how it differs from a simple LLM
  • Learn the 4 core components: Reasoning, Tools, Memory & Perception
  • Explore the agent loop (perception → reasoning → action → observation)
  • Run live agent code simulation in browser

1. What is an AI Agent?

An AI agent is more than just a chatbot. It can understand its environment, make decisions, use external tools, and take actions to achieve a goal — with minimal human intervention.

LLM = Recipe Book

Contains immense knowledge and text recipes, but cannot touch the stove.

vs

Agent = Executive Chef

Takes action, holds utensils, tastes feedback, and adapts to finish the dish.

✍️

"Instructor note: Chatbots talk, but Agents work! An LLM generates words; an agent takes real actions in the world."

2. The 4 Core Components

Every production AI agent is composed of four interconnected modules:

Cognitive Engine

Implementation: 1. Reasoning

Pure Python
if "financial" in user_goal:
    next_action = "call_mock_financial_db"
💡

"Mental model: Brain = Reasoning, Hands = Tools, Notebook = Memory, Eyes = Perception!"

3. The Agent Loop

Swipe steps →

The agent continuously loops through perception, reasoning, and action until its task is solved:

→→→→
Step 1:Agent receives user prompt or environment trigger.
📌

"Loop rule: The cycle repeats until the agent declares 'task complete' or hits a safe max turn safeguard."

4. See It in Action (Live Simulation)

Watch the agent loop execute in real-time. Tap Play Trace to step through:

Trace(6/6)
👤
User Goal Prompt

“What is the YoY revenue growth for TECH?”

1. Perception

Received user query & parsed context

2. Reasoning

Need to fetch verified financial data for TECH

3. Tool Use

Calling financial_db(ticker='TECH')

4. Observation

Got data: 2025 = $12.0B, 2026 = $14.2B

5. Reasoning

Calculate percentage: ((14.2 - 12) / 12) * 100

6. Final AnswerActive

18.33% YoY Growth synthesized for user

Agent completed the task! Result: 18.33% YoY Growth.

5. Try It Yourself (Interactive Code Runner)

Pure Python agent implementation. Choose target company and tap Run:

Target:
1"""
2Module 1.1: Anatomy of an AI Agent in Pure Python
3Demonstrating the 4 Core Components:
41. Reasoning Engine (Cognitive brain)
52. Tools (External capabilities)
63. Memory (Context & state buffer)
74. Perception (User input & tool observations)
8"""
9
10import json
11from typing import Dict, Any, List
12
13# --- COMPONENT 2: TOOLS (Actuators) ---
14def calculate_growth(revenue_2025: float, revenue_2026: float) -> str:
15 """Calculates percentage growth between two financial years."""
16 growth = ((revenue_2026 - revenue_2025) / revenue_2025) * 100
17 return f"{growth:.2f}% YoY Growth"
18
19def mock_financial_db(ticker: str) -> Dict[str, Any]:
20 """Simulates a database lookup for verified company earnings."""
21 data = {
22 "TECH": {"2025": 12.0, "2026": 14.2, "unit": "Billion USD"},
23 "AUTO": {"2025": 8.5, "2026": 9.1, "unit": "Billion USD"}
24 }
25 return data.get(ticker.upper(), {"error": "Company ticker not found"})
26
27TOOLS = {
28 "mock_financial_db": mock_financial_db,
29 "calculate_growth": calculate_growth
30}
31
32# --- COMPONENT 3: MEMORY MECHANISM ---
33class AgentMemory:
34 def __init__(self):
35 self.history: List[Dict[str, str]] = []
36
37 def record(self, role: str, content: str):
38 self.history.append({"role": role, "content": content})
39
40# --- COMPONENT 1 & 4: REASONING ENGINE & PERCEPTION-ACTION ---
41class SimpleAIAgent:
42 def __init__(self, name: str):
43 self.name = name
44 self.memory = AgentMemory()
45
46 def reason_and_act(self, user_goal: str) -> str:
47 # 1. Perception
48 self.memory.record("user", user_goal)
49
50 # 2. Reasoning & Tool Invocation
51 tool_output = TOOLS["mock_financial_db"]("TECH")
52 self.memory.record("observation", json.dumps(tool_output))
53
54 # 3. Second Reasoning Step & Math
55 growth = TOOLS["calculate_growth"](tool_output["2025"], tool_output["2026"])
56
57 # 4. Final Reflection & Output
58 answer = f"TechCorp achieved {growth}."
59 self.memory.record("assistant", answer)
60 return answer
📝

"Notice: The agent never guessed or hallucinated the growth math — it invoked the calculator tool deterministically!"

6. Common Misconceptions

Two traps that beginner AI engineers frequently fall into:

Trap #1

A single prompt is NOT an agent

A long system prompt in a single API call is just prompt engineering. An agent requires an autonomous loop, tools, and observation feedback.

Trap #2

LLMs are NOT calculators

LLMs predict text statistically. They cannot do exact math reliably. Equipping agents with calculators or Python execution tools is non-negotiable.

Key Takeaways

  • An agent is autonomous, goal-directed, and adaptive.
  • It has 4 core components: reasoning, tools, memory, and perception.
  • The agent loop drives the action-observation cycle to solve tasks.

"Pro tip: Always write automated unit tests for your tools before handing them over to an autonomous LLM loop!"

Knowledge Check Quiz

Quick 3-question check to test what you learned in Module 1.1.

Ready to Level Up?

Next: Module 1.2 • The Agent Loop & Prompt Engineering

Learn how prompt chaining and Chain-of-Thought unlock structured agent reasoning.

Next Module