AI AI-01.01
Agents and environments
Agents that perceive and act, PEAS descriptions, the properties that make environments easy or hard, and reflex, goal-based and utility-based agents.
The big idea
A robot vacuum, a chess program, a self-driving car and an AI assistant that books flights look nothing alike, but they share one shape. Each one takes in information about its world, decides, and does something that changes the world. That shape is called an agentAnything that perceives its environment through sensors and acts on it through actuators, choosing actions to achieve its goals., and it is the most useful single idea in AI, because it turns "make it intelligent" into a concrete question: given what it has perceived so far, which action should it take next?
Describing any AI system as an agent forces you to say what it can sense, what it can do, what world it lives in and how success is measured. Those four answers usually tell you which techniques will work, before you write a line of code.
Picture a thermostat, then a person running a household budget. Both perceive (temperature; bills) and act (heat on; spend or save). The difference is in how they choose, and that difference is what this lesson classifies.
How it works
Step 1: The agent loop
- A perceptWhat an agent senses at one moment, such as a camera frame, a reading or a message. is what the agent senses at one instant; the percept sequence is everything it has sensed so far.
- An action is something the agent can do that affects the environment.
- The agent program maps percepts to actions. Designing it is the job of AI.
Step 2: Describe the task with PEAS
Before choosing an algorithm, write a PEASPerformance measure, Environment, Actuators, Sensors: a four-part description of an agent's task. description:
| Robot vacuum | Automated taxi | Flight booking assistant | |
|---|---|---|---|
| Performance | floor cleaned, battery used, nothing broken | safe, legal, fast, comfortable, profitable | right flight, low price, few user turns |
| Environment | rooms, furniture, pets | roads, traffic, pedestrians, weather | airline APIs, user, calendar |
| Actuators | wheels, brushes, suction | steering, throttle, brakes, signals | search and booking calls, messages |
| Sensors | bump sensors, dirt sensor, lidar | cameras, radar, GPS, speedometer | API responses, user messages |
The performance measure matters most. It defines what "good behavior" means, and a badly chosen measure produces an agent that games it: a vacuum rewarded for "dirt collected" might learn to dump dirt and collect it again.
Step 3: What makes an environment hard
Environments differ along a few dimensions, and each one changes what kind of agent you need:
- Fully or partially observable: can the agent see everything relevant? Chess is fully observable; poker and driving are not.
- Deterministic or stochastic: does an action always have the same result? A puzzle move does; a dice roll or a skid does not.
- Episodic or sequential: is each decision independent (classifying one photo) or does it affect the future (every chess move)?
- Static or dynamic: does the world change while the agent thinks? A crossword waits; traffic does not.
- Discrete or continuous: a fixed set of states and moves (a board game) versus smooth quantities (steering angle, speed).
- Single or multi-agent: are there other agents, cooperating or competing?
The hardest real environments, such as driving, are partially observable, stochastic, sequential, dynamic, continuous and multi-agent all at once.
Step 4: Four kinds of agent program
From simplest to most capable:
- Simple reflex agents act on the current percept with if-then rules: "if dirty, suck". Fast and simple, but helpless when the right action depends on what it cannot currently see.
- Model-based reflex agents keep an internal state, a model of the parts of the world they cannot see right now, such as "I already cleaned the kitchen".
- Goal-based agents consider what their actions will lead to and choose ones that reach a goal, which requires search and planning. Most of this module is about how they search.
- Utility-based agents go further: when several outcomes reach the goal, or goals conflict, they choose the action with the highest expected utilityA number scoring how desirable an outcome is, letting an agent trade off goals such as speed against safety., trading off speed, cost, safety and risk.
Any of these can also be a learning agent that improves its program from experience. And an LLM agent that calls tools in a loop is the same structure: messages and tool results are percepts, tool calls are actions. See Function calling and tool use .
Try it
Going deeper
Rationality is not omniscience
A rational agentAn agent that chooses the action expected to maximize its performance measure, given what it has perceived and knows. picks the action that maximizes its expected performance given what it knows. It can still have a bad outcome: a driver who checks both ways and is hit by a car that ran a red light acted rationally. Judging agents by expected performance rather than outcomes is what makes reasoning under uncertainty, covered in Probability for AI (recap) , possible.
Specify the objective carefully
Because agents optimize what you measure, a sloppy performance measure is dangerous. A recommendation system optimizing watch time may promote outrage; a game agent may find a scoring bug instead of winning. This problem of specifying what we really want returns, at much larger scale, in Alignment and interpretability, the big picture .
Trade-offs
| Option | Wins when | Loses when |
|---|---|---|
| Simple reflex agent | Fully observable, fast-reacting tasks with clear rules: thermostats, simple filters | Anything needing memory, planning or trade-offs |
| Goal-based agent | Problems with a clear goal and known actions: routing, puzzles, scheduling | Situations where many outcomes satisfy the goal and some are much better |
| Utility-based agent | Trade-offs and uncertainty: driving, trading, recommendations | Cases where a good utility function is hard to write or to compute |
Common mistakes
- Starting with the algorithm before writing a PEAS description. The environment's properties decide which algorithm can work.
- Writing a performance measure that can be gamed. The agent will find the loophole.
- Assuming the environment is fully observable when it is not. A reflex agent that cannot see the whole situation makes confident, wrong moves.
- Forgetting other agents. Traffic, markets and games change because others react to you.
Check yourself
-
In the agent loop, what does an actuator do?
Show answer
B. Carries out the chosen action in the environment Sensors bring percepts in; actuators carry actions out.
-
Which environment is partially observable?
Show answer
C. Poker In poker you cannot see the other players' cards.
-
A navigation app picks between three routes that all arrive, weighing time, tolls and fuel. What kind of agent is this?
Show answer
D. Utility-based Several outcomes reach the goal; scoring their desirability is what a utility-based agent does.
-
Why does the performance measure matter so much?
Show answer
B. Agents optimize what is measured, so a flawed measure leads to unwanted behavior An agent will maximize exactly what you measure, loopholes included.
Recap
- An agent perceives through sensors and acts through actuators, in a loop.
- PEAS (performance, environment, actuators, sensors) describes any agent's task.
- Environments vary: observable or not, deterministic or not, episodic or sequential, static or dynamic, discrete or continuous, single or multi-agent.
- Agent programs range from simple reflex to model-based, goal-based and utility-based.
- Agents optimize their performance measure, so define it carefully.