1. Agents and Environments
Source: AIMA 4th Ed, Chapter 2 (Section 2.1), physical PDF pp. 99–102
Introduction
Chapter 2 makes the concept of rational agents concrete. It begins by establishing foundational vocabulary: what an agent is, how it relates to its environment, and how its behavior is formally specified. This vocabulary anchors everything that follows — both in this chapter and throughout the book.
Core Definitions
Agent
An agent is anything that can be viewed as: - perceiving its environment through sensors, and - acting upon that environment through actuators
Examples across agent types:
| Agent type | Sensors | Actuators |
|---|---|---|
| Human | Eyes, ears, skin, nose, tongue | Hands, legs, vocal tract |
| Robot | Cameras, infrared range finders, sonar | Motors, wheels, grippers |
| Software agent | File contents, network packets, keyboard/mouse/voice | Writing files, sending packets, displaying output |
The agent abstraction is a tool for analysis, not a hard
ontological divide. A calculator could be modeled as an agent that
receives "2+2=" and acts by displaying "4" —
but this analysis adds no insight. The framework is most useful where
tasks require nontrivial decision-making with significant computational
resources.
Environment
The environment is the part of the universe that an agent interacts with — specifically the part that: - affects what the agent perceives, and - is affected by the agent’s actions
In principle the environment is “everything”; in practice it is scoped to what matters for the task at hand.
Percept
A percept is the content an agent’s sensors are perceiving at any given instant — the atomic unit of sensory input at a single moment in time.
Percept Sequence
The percept sequence is the complete history of everything the agent has ever perceived — the full chronological record of all percepts received to date.
Fundamental constraint on agents:
An agent’s choice of action at any given instant can depend on its built-in knowledge and on the entire percept sequence observed to date, but not on anything it hasn’t perceived.
This rules out “psychic” agents but explicitly permits agents that use memory of past observations to inform current decisions.
The Agent Function (Formal Specification)
The agent function is the complete mathematical specification of an agent’s behavior:
f : P* -> A
where: - P* = set of all possible percept sequences (of
any finite length) - A = set of possible actions
The function maps any percept sequence to an action. Key properties:
- It is an external characterization — it describes behavior from the outside without saying anything about internal mechanism
- It is in principle tabulable: given the agent, try every possible percept sequence, record the resulting action. The table is the agent function.
- For most non-trivial agents this table is astronomically large or infinite
Agent Program (Internal Implementation)
The agent program is the concrete implementation of the agent function running on physical hardware:
agent = architecture + program
| Concept | What it is |
|---|---|
| Agent function | Abstract mathematical mapping: P* -> A |
| Agent program | Concrete code running on the agent architecture |
| Agent architecture | Physical computing substrate (hardware + OS) |
The agent program typically takes only the current percept as input — not the full percept sequence — because nothing more is directly available from the environment at the moment of action. If history matters, the program must maintain internal memory to reconstruct it.
The Vacuum-Cleaner World (Running Example)
The book’s primary running example throughout Chapter 2.
Setup: - World: two squares, A and
B, each either Clean or
Dirty - Agent starts in square A - Percept format:
[location, status] — e.g., [A, Dirty] -
Available actions: Right, Left,
Suck, NoOp
Simple agent function rule: if the current square is dirty, suck; otherwise, move to the other square.
Partial agent function table (Figure 2.3):
| Percept sequence | Action |
|---|---|
| [A, Clean] | Right |
| [A, Dirty] | Suck |
| [B, Clean] | Left |
| [B, Dirty] | Suck |
| [A, Clean], [A, Clean] | Right |
| [A, Clean], [A, Dirty] | Suck |
| [A, Clean], [A, Clean], [A, Clean] | Right |
| [A, Clean], [A, Clean], [A, Dirty] | Suck |
| … | … |
The table grows without bound unless a cap is placed on percept sequence length.
Agent-Environment Interaction Loop (Figure 2.1)
+-----------------------------------------------------------+
| AGENT |
| |
| Sensors <--(Percepts)--+ ENVIRONMENT |
| | | |
| v | |
| [ Agent Program ] | (the "?" in Figure 2.1) |
| | | |
| v | |
| Actuators --(Actions)--+ |
+-----------------------------------------------------------+
The runtime loop: 1. Environment emits a percept, received by the agent’s sensors 2. Agent program processes the percept (may update internal memory) 3. Agent program selects and emits an action 4. Action is executed via actuators, modifying the environment 5. New state of environment generates the next percept — repeat
Why the Table-Driven Approach Fails
The TABLE-DRIVEN-AGENT (Figure 2.7) literally stores and looks up the full agent function table:
function TABLE-DRIVEN-AGENT(percept) returns an action
persistent: percepts (sequence, initially empty)
table (fully specified, indexed by percept sequences)
append percept to percepts
action <- LOOKUP(percepts, table)
return action
It correctly implements the agent function — but is computationally doomed:
- Table size =
sum_{t=1}^{T} |P|^tentries, where|P|= number of distinct percepts,T= agent lifetime - Automated taxi, 8 cameras, 70 MB/s input: over
10^{600,000,000,000}entries for one hour of driving - Chess: at least
10^{150}entries - Atoms in the observable universe:
< 10^{80}
The key challenge for AI: write programs that produce rational behavior from a compact program rather than a vast table. This is the central motivation for the four agent architectures in Section 2.4.
Important Distinctions for Quals
- Agent function vs. agent program — the distinction is always tested. One is abstract/mathematical; the other is concrete/computational.
- Percept vs. percept sequence — actions depend on the full history, not just the current moment. But the program may only receive the current percept as input.
- The agent abstraction is analytical — it is applied where useful, not everywhere possible.
- The environment is scoped — “the part of the universe that matters” for the agent’s task, not everything.
Cross-References
- Section 2.2 → What makes an agent good? Rationality and performance measures
- Section 2.3 → PEAS framework; taxonomy of environment properties
- Section 2.4 → Four canonical agent architectures (simple reflex through learning agents)
- Ch. 16 → Decision-theoretic agents (utility maximization under uncertainty)
- Ch. 22 → Reinforcement learning — agents that learn their agent function from experience