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#
- Simple reflex agent - acts only on the current percept with condition-action rules (
IF dirty THEN suck). Fast, but blind to history. - Model-based reflex agent - keeps an internal state (a model of the parts of the world it cannot see right now).
- Goal-based agent - chooses actions that lead to a goal (uses search and planning).
- Utility-based agent - chooses actions that maximise a utility (how good an outcome is), trading off speed, safety and cost.
- 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.
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 16The 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:
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 19The 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.