Agents and Environments
Prerequisites
- What is AI? — Understanding the Rational Agent approach
- Types of AI — Basic classification of AI systems
🎯 Learning Objectives
- Define what an agent is and identify its components (sensors and actuators)
- Understand the relationship between an agent and its environment
- Distinguish between agent function and agent program
- Define and use the concept of percept sequence
- Analyze real-world systems as agents and identify their sensors, actuators, and environments
- Solve GATE-style questions on agent-environment modeling
1. An Intuitive Introduction
Imagine you are sitting in a self-driving car. The car has cameras, LIDAR, radar, and GPS (its sensors) that constantly gather information about the road, other vehicles, pedestrians, and traffic signals. Based on this information, the car makes decisions: turn left, accelerate, brake, or change lanes. It executes these decisions through its steering wheel, accelerator, and brakes (its actuators).
In AI terminology, the self-driving car is an agent. The road, other cars, pedestrians, weather, and traffic rules form its environment. The car perceives the environment through sensors and acts upon it through actuators. This simple yet powerful abstraction is the foundation of all modern AI.
But agents are not just robots or cars. Consider these everyday examples:
- You are an agent: your eyes, ears, and skin are sensors; your hands, legs, and voice are actuators; the world is your environment.
- A spam filter is an agent: its sensor is the incoming email text; its actuator is the classify action (spam/not spam); its environment is the email stream.
- A thermostat is an agent: it senses temperature and acts by turning a heater on or off.
The agent-environment framework is the central organizing concept of AI in the GATE DA syllabus. Every subsequent topic—search algorithms, game playing, logical reasoning, machine learning—is about designing agents that act intelligently in various environments. Expect 1–3 direct questions on agent definitions and their components.
2. Formal Definition of an Agent
An agent is anything that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators.
This definition is deliberately broad. It applies to:
| Agent | Sensors | Actuators | Environment |
|---|---|---|---|
| Human | Eyes, ears, skin, tongue, nose | Hands, legs, vocal cords | Physical world |
| Robot | Cameras, infrared, touch sensors | Motors, grippers, speakers | Factory floor, warehouse |
| Software agent | Keystrokes, file contents, network data | Screen output, file writes, network packets | Operating system, internet |
| Thermostat | Temperature sensor | Heater switch (on/off) | Room |
2.1 Percept and Percept Sequence
A percept is the agent’s perceptual input at any given instant—the content that its sensors provide at one moment in time.
The percept sequence is the complete history of everything the agent has ever perceived. An agent’s choice of action can depend on the entire percept sequence observed to date, but not on anything it hasn’t perceived.
Example: Consider a vacuum-cleaner agent in a two-square world (Square A and Square B). Each square is either Clean or Dirty. At each time step, the agent perceives its current location and the status of that square.
- At time 1, the agent is in Square A and it’s Dirty. Percept:
[A, Dirty] - At time 2, after cleaning, it’s still in A and it’s now Clean. Percept:
[A, Clean] - At time 3, it moves to B and finds it Dirty. Percept:
[B, Dirty]
The percept sequence so far is: [A, Dirty], [A, Clean], [B, Dirty]. The agent’s next action can depend on this entire history.
3. Agent Function vs. Agent Program
This distinction is crucial and frequently tested in GATE:
The agent function maps every possible percept sequence to an action. It is a mathematical (abstract) description of the agent’s behavior.
f : P* → A
where P* is the set of all possible percept sequences and A is the set of actions.
The agent program is a concrete implementation of the agent function. It runs on a physical computing device (the agent architecture). The agent program takes the current percept as input and returns an action.
agent = architecture + program
| Aspect | Agent Function | Agent Program |
|---|---|---|
| Nature | Abstract / Mathematical | Concrete / Implementation |
| Input | Entire percept sequence | Current percept (may maintain internal memory) |
| Size | Can be infinitely large (all possible sequences) | Finite code running on hardware |
| Representation | A lookup table (conceptually) | Rules, search, neural network, etc. |
| Analogy | The “specification” or “what to do” | The “code” or “how to do it” |
The agent function is an external characterization of the agent’s behavior—it describes what action the agent takes for every possible percept history. The agent program is the internal implementation. Multiple different agent programs can implement the same agent function. For example, a lookup table and a neural network could both implement the same input-output mapping.
3.1 The Table-Driven Agent
Conceptually, the simplest agent program is a table-driven agent: a giant lookup table that stores the action for every possible percept sequence. While this trivially implements any agent function, it is wildly impractical:
Consider a chess-playing agent. A chess position has about 1047 legal states. If the agent considers sequences of moves, the table would need entries for every possible sequence of board states seen so far—an astronomically large number. Even storing a table for a simple 2×2 grid world over 100 time steps would require 2100 entries. The table-driven approach demonstrates that we need smarter agent programs that compress the agent function into compact code.
4. The Agent-Environment Interface
The interaction between an agent and its environment follows a simple cycle:
- Perceive: The agent receives a percept from the environment through its sensors.
- Decide: The agent program processes the percept (possibly considering past percepts) and selects an action.
- Act: The agent executes the action on the environment through its actuators.
- Update: The environment transitions to a new state (which may or may not be affected by the agent’s action).
- Repeat: The cycle continues.
Environment ⟶ [Sensors] ⟶ Percept ⟶ [Agent Program] ⟶ Action ⟶ [Actuators] ⟶ Environment
This loop is sometimes called the sense-think-act cycle or the perception-action loop. It is fundamental to understanding how all AI agents operate.
4.1 Environment States
The environment has a state at every instant. The agent’s action may change the state. Other processes in the environment (other agents, natural dynamics) may also change the state. The agent may or may not be able to observe the full state—this determines whether the environment is fully observable or partially observable (covered in detail in the PEAS Framework topic).
5. The Vacuum-Cleaner World
The vacuum-cleaner world is the canonical example used by Russell & Norvig to illustrate agents. Understanding it thoroughly is essential for GATE.
Setup
- Two squares: A (left) and B (right)
- Each square is either Clean or Dirty
- The agent (vacuum cleaner) is in one square at a time
- Percepts: [location, status] — e.g., [A, Dirty]
- Actions: Left, Right, Suck, NoOp
Agent Function (Partial Table)
| 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 |
| … | … |
Notice how the table grows exponentially with the length of the percept sequence. A simple reflex agent (covered in Agent Types) can implement this agent function with just four rules, ignoring the percept history entirely and acting only on the current percept.
Simple Reflex Agent Program (Pseudocode)
function VACUUM-AGENT(percept):
location, status = percept
if status == Dirty:
return Suck
else if location == A:
return Right
else:
return Left
6. Worked Examples
Question: In the vacuum-cleaner world, the agent starts in Square A (Dirty) and Square B is also Dirty. The agent uses the simple reflex program above. Trace through the agent’s actions and percept sequence for 4 time steps.
Solution:
- Time 1: Percept = [A, Dirty]. Action = Suck. (Square A becomes Clean)
- Time 2: Percept = [A, Clean]. Action = Right. (Agent moves to B)
- Time 3: Percept = [B, Dirty]. Action = Suck. (Square B becomes Clean)
- Time 4: Percept = [B, Clean]. Action = Left. (Agent moves to A)
Percept sequence: [A, Dirty], [A, Clean], [B, Dirty], [B, Clean]
Result: Both squares are clean after 3 steps. The agent continues to oscillate between A and B (doing no useful work). A more sophisticated agent would use NoOp when both squares are clean.
Question: Identify the sensors, actuators, percepts, actions, and environment for a chess-playing software agent (like Stockfish).
Solution:
- Sensors: The interface that receives the current board state (positions of all pieces) and the opponent’s last move. In a digital game, this is provided as data from the game server.
- Actuators: The interface that sends the agent’s chosen move to the game server (e.g., “e2 to e4”).
- Percepts: The current board configuration plus the game history (moves made so far). Example: “White pawn on e4, Black pawn on e5, …”
- Actions: All legal moves from the current position. Each action specifies a piece and its destination square.
- Environment: The chessboard (8×8 grid), the rules of chess, and the opponent player.
Agent function: Maps every possible game history (sequence of board positions) to the best next move.
Agent program: Uses minimax search with alpha-beta pruning and evaluation functions to select moves efficiently (rather than a lookup table).
Question: A hospital deploys an AI system to assist doctors in diagnosing diseases based on patient symptoms, lab test results, and medical history. Model this as an agent.
Solution:
- Agent: The medical diagnosis AI system.
- Sensors: Input interfaces that receive patient data—symptoms (fever, cough, fatigue), lab results (blood counts, X-ray images), and medical history (past conditions, medications, allergies).
- Actuators: Output interface that displays the diagnosis (disease name, probability), recommended tests, and suggested treatment plans to the doctor.
- Percepts: Each patient encounter forms a percept: {symptoms: [fever, cough], lab_results: [WBC: 12000, CRP: elevated], history: [diabetes]}. The percept sequence includes all patients seen so far.
- Actions: Output a diagnosis (e.g., “Pneumonia with 87% confidence”), recommend additional tests (e.g., “Order chest CT scan”), or suggest treatment (e.g., “Prescribe antibiotics”).
- Environment: The hospital setting, patient population, available tests, disease prevalence in the region, and the doctor who makes final decisions.
Key insight: The environment is partially observable (the agent cannot see the patient’s internal organs directly), stochastic (diseases have probabilistic symptoms), and sequential (a previous diagnosis may influence future tests).
7. GATE-Style Example Questions
Question: Which of the following is NOT a component of an intelligent agent?
(A) Sensors (B) Actuators (C) Compiler (D) Environment
Answer: (C) Compiler. An agent is defined by its sensors (to perceive), actuators (to act), and its environment. A compiler is a software development tool, not a component of the agent framework.
Question: The agent function for a vacuum cleaner in a 2-square world maps percept sequences to actions. If the agent operates for T time steps and each percept has 4 possible values ([A, Clean], [A, Dirty], [B, Clean], [B, Dirty]), how many entries does the agent function table have for percept sequences of length exactly T?
Answer: 4T. There are 4 possible percepts per time step. For a sequence of length exactly T, the number of distinct sequences is 4 × 4 × … × 4 = 4T. The total table size for sequences up to length T is 41 + 42 + … + 4T = (4T+1 − 4) / 3.
8. Common Mistakes & Misconceptions
The agent function is a mathematical abstraction (a mapping from all percept sequences to actions). The agent program is a concrete implementation that runs on hardware. The function is the “what”; the program is the “how.” In GATE, if a question asks about the “agent function,” think of it as the complete behavioral specification.
An agent only knows what its sensors tell it. The percept may give incomplete or noisy information about the true environment state. Don’t assume the agent has full knowledge unless the problem explicitly states the environment is “fully observable.”
Students sometimes focus only on the agent (sensors + actuators + program) and forget that the environment is a critical part of the model. The agent’s design depends heavily on the properties of the environment (which we study in PEAS).
📚 Summary
- An agent perceives its environment through sensors and acts through actuators.
- A percept is the sensory input at one instant; the percept sequence is the entire history of percepts.
- The agent function is an abstract mathematical mapping from percept sequences to actions: f : P* → A.
- The agent program is a concrete implementation of the agent function running on hardware (the architecture): agent = architecture + program.
- A table-driven agent stores the complete agent function but is impractical due to exponential table size.
- The perception-action loop (sense → decide → act → repeat) is the fundamental cycle of all AI agents.
- The vacuum-cleaner world is the canonical example for understanding agents, percepts, and actions.
References
- Russell, S. & Norvig, P. (2020). Artificial Intelligence: A Modern Approach (4th ed.). Pearson. — Chapter 2, Sections 2.1–2.2.
- Poole, D. & Mackworth, A. (2017). Artificial Intelligence: Foundations of Computational Agents (2nd ed.). Cambridge University Press. — Chapter 2.
- Wooldridge, M. (2009). An Introduction to MultiAgent Systems (2nd ed.). Wiley. — Chapter 1.