The idea of the agent is the unifying concept of modern AI: everything is studied as something that perceives and acts.

Agent and Environment

An agent is anything that perceives its environment through sensors and acts upon it through actuators. A human agent has eyes and ears as sensors, hands and legs as actuators. A robot has cameras and motors. A software agent has keystrokes, files and network packets as percepts and writes to the screen or files as actions. The complete history of everything the agent has perceived is its percept sequence. The agent's behaviour is described by the agent function, a mapping from percept sequences to actions; the agent program is the concrete implementation of this function that runs on the physical architecture.

Definition: Agent. An entity that perceives its environment through sensors and acts on it through actuators; its behaviour is described by an agent function mapping percept sequences to actions.

The Vacuum Cleaner World

The standard small example is a vacuum-cleaner world with two squares, A and B, each clean or dirty. The agent perceives its location and whether the square is dirty, and can Left, Right or Suck. A simple agent function is: if the current square is dirty, suck; otherwise move to the other square. Whether this is a good agent depends on how we measure success.

Rationality

A rational agent is one that, for each possible percept sequence, selects an action expected to maximise its performance measure, given the evidence from the percept sequence and its built-in knowledge. Rationality depends on four things: the performance measure that defines success, the agent's prior knowledge of the environment, the actions it can perform, and its percept sequence to date. The performance measure should reflect what we want in the environment, not how we think the agent should behave: reward the amount of dirt cleaned, or better the cleanliness over time, not simply "number of times it sucks", which a silly agent could maximise by dumping dirt and cleaning it again.

Rational Is Not Omniscient

Rationality is not omniscience (knowing the actual outcome), clairvoyance (predicting the future) or perfection. A rational agent maximises expected performance, whereas perfection maximises actual performance. Crossing a road after looking and seeing no traffic is rational even if a falling object hits you. Rationality also requires information gathering (looking before crossing), exploration, learning from percepts, and autonomy: an agent relying only on its designer's built-in knowledge, not on its own percepts, lacks autonomy and fails when conditions change.

Table 1.2: Rational agent: four requirements

Element Meaning Vacuum example
Performance measure What counts as success Clean squares over time
Prior knowledge What the agent knows of the environment Layout of A and B
Actions What it can do Left, Right, Suck
Percept sequence What it has perceived so far [A, Dirty], [A, Clean]

Example 1.2: Vacuum agent performance

Problem: The two-square world starts with A dirty and B dirty and the agent in A. The agent suck-if-dirty else move. Score one point per clean square per time step over 4 steps; compute the score.

Solution:

  1. t = 1: perceives [A, Dirty] → Suck; after the action A is clean, B dirty: 1 clean square → 1 point.
  2. t = 2: perceives [A, Clean] → Right; in B; 1 clean square → 1 point.
  3. t = 3: perceives [B, Dirty] → Suck; both clean → 2 points.
  4. t = 4: perceives [B, Clean] → Left; both clean → 2 points.

Result: Total score 1 + 1 + 2 + 2 = 6 over four steps.

def agent(percept):
    loc, status = percept
    if status == "Dirty":
        return "Suck"
    return "Right" if loc == "A" else "Left"
world = {"A": "Dirty", "B": "Dirty"}
loc, score = "A", 0
for t in range(1, 5):
    act = agent((loc, world[loc]))
    if act == "Suck":
        world[loc] = "Clean"
    else:
        loc = "B" if act == "Right" else "A"
    score += sum(v == "Clean" for v in world.values())
    print(t, act, world, "score", score)

Output

1 Suck {'A': 'Clean', 'B': 'Dirty'} score 1
2 Right {'A': 'Clean', 'B': 'Dirty'} score 2
3 Suck {'A': 'Clean', 'B': 'Clean'} score 4
4 Left {'A': 'Clean', 'B': 'Clean'} score 6

Common mistakes

  • Defining the performance measure by the agent's behaviour rather than the desired state of the environment.
  • Equating rationality with perfection or knowing the outcome.
  • Forgetting that the percept sequence, not just the current percept, may be needed.
  • Confusing the agent function (abstract mapping) with the agent program (implementation).

Key takeaways

  • An agent perceives through sensors and acts through actuators.
  • The agent function maps percept sequences to actions; the agent program implements it.
  • A rational agent maximises expected performance given its percepts and knowledge.
  • Rational does not mean omniscient or perfect.

Practice questions

  1. What is a percept sequence?
  2. State what rationality depends on.
  3. Is a rational agent always successful?

Answers to the practice questions

  1. The complete history of everything the agent has perceived.
  2. Performance measure, prior knowledge, available actions and the percept sequence.
  3. No; it maximises expected performance, not actual outcomes.

Sources

  • Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit I