AI Notes
Complete guide to intelligent agents in AI covering agent types, PEAS framework, agent architectures, and how agents perceive and act in their environments.
Introduction
The concept of an intelligent agent is central to modern AI. Rather than asking "Can machines think?", the agent-based approach asks: "Can machines act intelligently?" An agent is anything that perceives its environment through sensors and acts upon it through actuators.
You are an agent. Your eyes and ears are sensors; your hands and mouth are actuators. A thermostat is a simple agent too — it senses temperature and acts by turning heating on or off. AI research focuses on building software (and sometimes hardware) agents that act intelligently.
What is an Agent?
Formally, an agent is characterized by its agent function:
The agent function maps the entire history of percepts to an action. The agent program is the concrete implementation of this function.
The PEAS Framework
To design an intelligent agent, we need to specify four things (PEAS):
| Component | Description | Example (Self-Driving Car) |
|---|---|---|
| Performance Measure | How do we evaluate success? | Safety, time, comfort, legality |
| Environment | Where does the agent operate? | Roads, traffic, weather |
| Actuators | How does the agent act? | Steering, brakes, accelerator, signals |
| Sensors | How does the agent perceive? | Cameras, LiDAR, GPS, speedometer |
PEAS Examples
# PEAS specification for different agents
peas_examples = {
"Vacuum Cleaner": {
"Performance": "Cleanliness, efficiency, battery usage",
"Environment": "Room with dirt, obstacles, furniture",
"Actuators": "Wheels, vacuum motor, brush",
"Sensors": "Dirt sensor, bump sensor, cliff sensor",
},
"Chess AI": {
"Performance": "Win rate, game quality",
"Environment": "Chess board (8x8 grid, pieces)",
"Actuators": "Move pieces (digital or robotic arm)",
"Sensors": "Board state (camera or digital input)",
},
"Medical Diagnosis": {
"Performance": "Accuracy, patient outcomes, cost",
"Environment": "Hospital, patient data, test results",
"Actuators": "Display diagnosis, suggest treatment",
"Sensors": "Patient symptoms, lab results, images",
},
"Stock Trader": {
"Performance": "Portfolio returns, risk-adjusted returns",
"Environment": "Financial markets, news, economic data",
"Actuators": "Buy/sell orders",
"Sensors": "Price feeds, news feeds, financial reports",
},
}
for agent, specs in peas_examples.items():
print(f"\n{'='*50}")
print(f"Agent: {agent}")
print(f"{'='*50}")
for key, value in specs.items():
print(f" {key}: {value}")Types of Agents
1. Simple Reflex Agent
Acts only on current percept, ignoring history. Uses condition-action rules (if-then).
class SimpleReflexAgent:
"""Agent that acts based on current percept only."""
def __init__(self):
self.rules = {
"dirty": "clean",
"clean": "move",
"obstacle": "turn",
}
def act(self, percept):
"""Map current percept directly to action."""
return self.rules.get(percept, "idle")
# Usage
agent = SimpleReflexAgent()
print(agent.act("dirty")) # → clean
print(agent.act("clean")) # → move
print(agent.act("obstacle")) # → turnLimitation: Can't handle partially observable environments. If you can't see the full state, you might make wrong decisions.
2. Model-Based Reflex Agent
Maintains an internal model of the world to handle partial observability.
3. Goal-Based Agent
Uses goals to decide actions. Can plan ahead by considering "what will happen if I do X?"
4. Utility-Based Agent
Not just "reach the goal" but "reach it in the BEST way possible." Uses a utility function to evaluate how desirable each state is.
class UtilityBasedAgent:
"""Agent that maximizes expected utility."""
def __init__(self):
self.utility_weights = {
"time": -0.3, # Less time is better
"cost": -0.4, # Less cost is better
"quality": 0.5, # More quality is better
"safety": 0.8, # Safety is most important
}
def utility(self, state):
"""Calculate utility of a state."""
total = 0
for factor, weight in self.utility_weights.items():
total += weight * state.get(factor, 0)
return total
def act(self, possible_actions, predict_outcomes):
"""Choose action that maximizes expected utility."""
best_action = None
best_utility = float('-inf')
for action in possible_actions:
expected_state = predict_outcomes(action)
u = self.utility(expected_state)
if u > best_utility:
best_utility = u
best_action = action
return best_action5. Learning Agent
Can improve its performance over time by learning from experience.
Agent Comparison Table
| Agent Type | Memory | Planning | Learning | Optimality |
|---|---|---|---|---|
| Simple Reflex | None | None | None | Poor |
| Model-Based | Internal state | None | None | Better |
| Goal-Based | State + Goals | Yes | None | Good |
| Utility-Based | State + Utility | Yes | None | Optimal |
| Learning | All above | Yes | Yes | Improves |
Key Takeaways
- An agent perceives and acts in an environment
- PEAS helps specify agent requirements clearly
- Agent architectures range from simple reflexes to learning systems
- More complex agents can handle more complex environments
- The learning agent architecture is the most general and powerful
Interview Questions
Q1: What is the difference between an agent function and an agent program?
The agent function is the abstract mathematical description — it maps every possible percept sequence to an action. The agent program is the concrete implementation of this function running on physical hardware. The agent function is an external description of behavior; the agent program is the internal mechanism. An agent function might be infinite (all possible histories), while the program must be finite and computable.
Q2: Explain the PEAS framework with an example of an online shopping recommendation agent.
Performance: Click-through rate, purchase conversion, user satisfaction, diversity of recommendations. Environment: E-commerce website, user browsing history, product catalog, other users' behavior. Actuators: Display recommended products, send notification emails, adjust ranking. Sensors: User clicks, purchases, time spent on pages, search queries, ratings, cart additions.
Q3: Why can't a simple reflex agent handle a partially observable environment?
A simple reflex agent maps the current percept directly to an action with no memory. In a partially observable environment, the agent can't see the full state — the same percept might correspond to different actual states requiring different actions. Without memory to track past observations and build an internal model, the agent can't distinguish between these states and will make incorrect decisions. A model-based agent solves this by maintaining internal state.
Q4: What makes a utility-based agent better than a goal-based agent?
A goal-based agent only distinguishes between goal states (success) and non-goal states (failure) — it's binary. A utility-based agent assigns a numerical value to every state, allowing it to choose the BEST path among multiple options that all achieve the goal. For example, two routes might both get you to work (goal achieved), but one is faster and cheaper (higher utility).
Q5: Describe the components of a learning agent and their roles.
A learning agent has four components: (1) Performance Element — selects actions based on current knowledge (the "normal" agent), (2) Critic — evaluates how well the agent is doing based on a fixed performance standard, (3) Learning Element — uses feedback from the critic to improve the performance element, (4) Problem Generator — suggests exploratory actions that might lead to new learning opportunities, even if they're suboptimal in the short term.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Intelligent Agents in AI.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Artificial Intelligence topic.
Search Terms
artificial-intelligence, artificial intelligence, artificial, intelligence, fundamentals, intelligent, agents, intelligent agents in ai
Related Artificial Intelligence Topics