⚡0 XP🔥0

Intelligent Agents and Environments

Lesson 2 of 8 ⏱ 5 min read ✎ 1 exercises ❓ 4-question quiz ▶ Runs Python

Agents, percepts and actions, the PEAS framework, types of environments, and the agent architectures from simple reflex agents to goal-based, utility-based and learning agents - with a vacuum-cleaner world in Python.

What is an agent?#

An agent is anything that perceives its environment through sensors and acts on it through actuators.

           percepts (what it senses)
   ┌──────────────────────────────────────┐
   │                                      ▼
ENVIRONMENT                            AGENT  (agent program: percepts → action)
   ▲                                      │
   └──────────────────────────────────────┘
            actions (what it does)
Agent Sensors Actuators
Robot vacuum bump sensor, dirt sensor, camera wheels, brushes, suction
Self-driving car cameras, radar, LiDAR, GPS steering, accelerator, brakes
Chatbot text typed by the user text replies, tool calls
UPI fraud system transaction details, device data approve, block, ask for OTP

A rational agent chooses the action that is expected to maximise its performance measure, given what it has perceived so far and what it knows.

हिंदी में समझें

Agent वो है जो अपने आस-पास (environment) को sensors से महसूस करता है और actuators से कोई काम करता है - जैसे robot vacuum गंदगी "देखता" है और साफ़ करता है। Rational agent वह काम चुनता है जिससे उसका लक्ष्य (performance measure) सबसे अच्छी तरह पूरा होने की उम्मीद हो।

PEAS - describing an agent's task#

Automated taxi Medical diagnosis assistant
Performance measure safe, fast, legal, comfortable trip, profit correct diagnosis, patient health, cost
Environment roads, traffic, pedestrians, weather patient, hospital, doctors
Actuators steering, brake, accelerator, horn, display questions, test suggestions, reports
Sensors cameras, GPS, speedometer, microphones symptoms entered, test results, scans

Writing the PEAS first forces you to decide what "good behaviour" means - the most important design decision.

Types of environments#

Property One side Other side
Observable fully (chess) partially (poker, driving in fog)
Outcome of actions deterministic (chess) stochastic (dice games, real traffic)
Time structure episodic - each decision independent (sorting parcels by photo) sequential - actions affect the future (driving, chess)
Change while thinking static (crossword) dynamic (traffic)
States and time discrete (chess squares) continuous (steering angle)
Other agents single-agent (puzzle) multi-agent (football, markets)

The hardest real-world problems - like driving - are partially observable, stochastic, sequential, dynamic, continuous and multi-agent all at once.

Agent architectures#

  1. Simple reflex agent - acts only on the current percept with condition-action rules (IF dirty THEN suck). Fast, but blind to history.
  2. Model-based reflex agent - keeps an internal state (a model of the parts of the world it cannot see right now).
  3. Goal-based agent - chooses actions that lead to a goal (uses search and planning).
  4. Utility-based agent - chooses actions that maximise a utility (how good an outcome is), trading off speed, safety and cost.
  5. Learning agent - improves its behaviour from experience (machine learning, reinforcement learning).

The vacuum-cleaner world in Python#

Two rooms, A and B. Each can be dirty or clean. The agent senses its location and whether that room is dirty.

▶ Try it YourselfPython
Ctrl + Enter to run
Output
step 1: percept ('A', 'dirty') -> suck  | world {'A': 'clean', 'B': 'dirty'} | score 10
step 2: percept ('A', 'clean') -> right | world {'A': 'clean', 'B': 'dirty'} | score 9
step 3: percept ('B', 'dirty') -> suck  | world {'A': 'clean', 'B': 'clean'} | score 19
step 4: percept ('B', 'clean') -> left  | world {'A': 'clean', 'B': 'clean'} | score 18
step 5: percept ('A', 'clean') -> right | world {'A': 'clean', 'B': 'clean'} | score 17
step 6: percept ('B', 'clean') -> left  | world {'A': 'clean', 'B': 'clean'} | score 16

The simple reflex agent keeps moving back and forth even after both rooms are clean, wasting energy. A model-based agent remembers what it has seen and stops:

▶ Try it YourselfPython
Ctrl + Enter to run
Output
step 1: ('A', 'dirty') -> suck  (score 10)
step 2: ('A', 'clean') -> right  (score 9)
step 3: ('B', 'dirty') -> suck  (score 19)
step 4: everything clean, stopping. Final score 19

The same performance measure, a better agent design, a better score.

Summary#

  • An agent maps percepts to actions; a rational agent maximises its expected performance measure.
  • Describe tasks with PEAS; classify environments by observability, determinism, time, dynamics, continuity and number of agents.
  • Architectures grow from simple reflex → model-based → goal-based → utility-based → learning agents.

Practice Exercises

Write your code, then press Check. Your program is tested automatically.

1

A thermostat reflex agent

Write thermostat(temp) returning "heat" below 20, "cool" above 26, otherwise "idle". Then build the list actions for the readings [18, 22, 27, 26, 19.5].

Quick Quiz

Q1.

In AI, an agent is...

Q2.

In PEAS, the "P" stands for...

Q3.

A simple reflex agent chooses actions based on...

Q4.

Chess (without a clock) is which kind of environment?