Lesson 05 · Artificial intelligence · 12 min
Agents and PEAS
An agent senses and acts. PEAS is how you write down what it's for. I fill in the table my notebook left empty, then race three agents in the same dusty world.

After this you can
- Write a PEAS description for any agent, including your own projects
- Classify an environment: observable, deterministic, episodic, static, discrete
- Tell reflex, model-based, goal-based, utility-based and learning agents apart
An agent is anything that perceives its environment through sensors and acts on it through actuators. A thermostat is one. So is a self-driving car, a spam filter, and you. The last lesson ended with the idea that AI means building agents that do the right thing. This one asks the obvious next question: right according to whom, and measured how?
My page answers with a definition and a table. The definition: a performance measure “defines the criterion for success of an agent's behaviour.” The table is headed PEAS, with Taxi Driver in the first row, and every cell is empty. I'll fill it in below.
Rational, not perfect
A rational agent picks the action expected to score best on its performance measure, given everything it has perceived so far and whatever it knew to begin with. That's narrower than it sounds. It isn't omniscient: it can only act on what it has seen. And it isn't judged on luck: a driver who checks the mirror and is hit by something nobody could have seen still made the rational choice.
The performance measure comes first, and it's easy to get wrong. Reward a cleaning robot for the amount of dirt it sucks up, and the best strategy is to dump the dirt back out and suck it up again. The standard advice is to measure what you want the world to look like, not how you think the agent should behave: a clean floor, not dirt collected.
Three agents, one world
Here's that robot in a corridor of eight rooms. Dust settles at random, and all three agents get exactly the same dust at exactly the same moments. Each one can only sense the room it's standing in. The performance measure is the share of time the rooms were clean.
Stay put
0% clean · 0 moves
If my room is dirty, suck. Otherwise do nothing.
Simple reflex
0% clean · 0 moves
If my room is dirty, suck. Otherwise move left or right at random.
Model-based
0% clean · 0 moves
Remember when I last saw each room. Suck if dirty, else head for the room I haven't checked longest.
The agent that stays put never wastes a move and scores the worst. If the measure were “spend as little energy as possible,” it would win. The reflex agent wanders at random, so it often doubles back over rooms it just cleaned. The model-based agent has the same sensors but keeps one extra piece of state, when it last saw each room, and that memory alone makes it cleaner with fewer moves. Press New world a few times: the order rarely changes.
import randomdef reflex_vacuum_agent(percept): """Condition-action rules on the current percept only. No memory.""" location, dirty = percept if dirty: return "suck" return random.choice(["left", "right"])class ModelBasedVacuumAgent: """Same sensors, plus a memory of when it last saw each room.""" def __init__(self, rooms): self.last_seen = {r: -1 for r in range(rooms)} self.t = 0 def __call__(self, percept): location, dirty = percept self.t += 1 self.last_seen[location] = self.t if dirty: return "suck" # Head for the room it has checked least recently, nearest first. others = [r for r in self.last_seen if r != location] def worth(r): return (self.t - self.last_seen[r]) - 2 * abs(r - location) target = max(others, key=worth) return "right" if target > location else "left"PEAS: the table, filled in
Before you design an agent, write down its task environment. PEAS is the checklist: Performance measure, Environment, Actuators, Sensors. Here is my notebook's taxi row, plus three agents closer to home, including two of my own projects.
| Agent | Performance | Environment | Actuators | Sensors |
|---|---|---|---|---|
| Taxi driver | Safe, fast, legal, comfortable trips; profit; little disruption to other road users | Roads, traffic, pedestrians, police, passengers, weather | Steering, accelerator, brake, indicators, horn, display | Cameras, radar, speedometer, GPS, engine sensors, microphone |
| CropScan | Correct diagnoses; few confident wrong answers; honest “not a crop”; useful advice | Farmers, leaves of three crops, light, phones, no signal | Screen: diagnosis, confidence, treatment, care plan | Phone camera, the gallery, weather data when online |
| Ride dispatcher | Short pickup times, drivers kept busy, fair fares, few cancellations | Riders, drivers, traffic, the city's roads at rush hour | Match a rider to a driver, set the price, send notifications | GPS from every phone, ride requests, cancellations, ratings |
| Fraud checker | Fraud caught, honest payments rarely blocked, decisions in milliseconds | Payments, customers, fraudsters who adapt | Approve, decline, hold for review, ask for a code | Amount, merchant, device, location, payment history |
What kind of environment?
The second half of a task description is the environment's properties. They decide which kind of agent can cope.
| Property | The easy side | The hard side |
|---|---|---|
| Observable | Fully: the sensors see everything that matters | Partially: some of the state is hidden |
| Agents | Single | Multi: others are cooperating or competing |
| Deterministic | The next state follows from the action | Stochastic: outcomes are uncertain |
| Episodic | Each decision stands alone | Sequential: today's choice changes tomorrow |
| Static | The world waits while the agent thinks | Dynamic: it changes anyway |
| Discrete | A finite set of states and actions | Continuous: positions, speeds, time |
| Observable | Agents | Outcomes | Episodes | Changes | States | |
|---|---|---|---|---|---|---|
| Chess | Fully | Multi | Deterministic | Sequential | Static | Discrete |
| Taxi driving | Partially | Multi | Stochastic | Sequential | Dynamic | Continuous |
| CropScan | Partially | Single | Stochastic | Episodic | Static | Continuous |
| Ride dispatch | Partially | Multi | Stochastic | Sequential | Dynamic | Discrete |
CropScan's episodic column is a big part of why a single neural network works for it: each photo is judged on its own and nothing carries over. A taxi gets the hard side of every column, and that's why self-driving took decades.
Five kinds of agent
The agent types build on each other. Each one adds a single capability to the one before.
Simple reflex
Condition-action rules on the current percept: if hot, pull back. Fast and fine when the environment is fully observable. The example on my AI page.
Model-based
Keeps internal state about the parts of the world it can't see right now, like the vacuum's memory of each room.
Goal-based
Knows what it's trying to reach and plans a sequence of actions to get there. A route planner. This is where search comes in.
Utility-based
Goals are pass or fail; utility is a score. A taxi doesn't only want to arrive, it trades speed against safety and cost.
Learning
Improves from feedback: a critic judges how it did, and a learning element changes the agent. CropScan's model was learned from labelled photos rather than written by hand.
Try it
01Write PEAS for a phone app you speak to in Twi that sets reminders.
Show the answerHide the answer
02Classify a crossword puzzle's environment.
Show the answerHide the answer
03The reflex vacuum gets a new rule: if the room is clean, always move right, and turn around at the end. Is it still a simple reflex agent?
Show the answerHide the answer
Further reading
- Artificial Intelligence: A Modern Approach, chapter 2 ↗
Intelligent agents, PEAS and the environment properties, where this whole page comes from.
- AIMA code: agents and the vacuum world ↗
The book's own Python implementations. agents.py has every agent type from this lesson.
- Elements of AI ↗
Free, gentle, and good on the question of what counts as intelligent behaviour.