AI FoundationsBeginner8 min02 / 14

Intelligent Agents

Discover how AI systems perceive the world, decide what to do, and act — all through a surprisingly simple loop that powers everything from thermostats to game-playing bots.

Your phone's GPS app is watching. Every few seconds it checks your location, looks at the road ahead, and decides whether to say "turn left" or "recalculate route". It never stops — perceive, decide, act, repeat. That rhythm is the heartbeat of almost every AI system ever built.

AI researchers gave this idea a name: the intelligent agent. An agent is anything that perceives its environment and acts on it to achieve a goal. The concept is beautifully general — it describes a chess-playing program, a self-driving car, a spam filter, and even a humble thermostat. Once you see the world through the agent lens, AI stops feeling like magic and starts feeling like engineering.

#Sensors, Actuators, and the Agent Function

Every agent connects to the world in two directions:

  • Sensors — the inputs. How the agent perceives its environment. A robot's camera, a thermostat's thermometer, a spam filter's incoming email.
  • Actuators — the outputs. How the agent acts. A robot's wheels, a thermostat's heating coil, a spam filter's "move to spam" button.

Everything in between — the brain that maps what the agent sees to what it does — is the agent function. That is the part we design when we build AI.

Think of it like

Think of a Thermostat

A thermostat is the world's simplest intelligent agent. Its sensor is a thermometer. Its actuator is the furnace switch. Its goal is to keep the room at 70°F.

Its entire agent function fits in one sentence: "If temperature < 70, turn on the furnace; otherwise, turn it off."

That's it — and yet it's genuinely intelligent behavior. Real AI agents follow the same pattern, just with vastly richer sensors, actuators, and decision functions.

#The Percept-Action Loop

Agents don't act once and walk away. They run a continuous percept-action loop:

  1. Perceive — read the current state of the environment. This snapshot is called a percept.
  2. Decide — run the percept through the agent function to choose an action.
  3. Act — execute the action, which changes the environment.
  4. Repeat — go back to step 1.

Here is the thermostat running this loop in pure Python:

The agent function maps each percept directly to an action. Simple, but genuinely intelligent.
def thermostat_agent(temperature, target=70):
    if temperature < target:
        return "turn_on_heat"
    else:
        return "turn_off_heat"

# Simulate several ticks of the percept-action loop
readings = [65, 68, 70, 72, 69]
for temp in readings:
    action = thermostat_agent(temp)
    print(f"Percept: {temp}F  ->  Action: {action}")

#Rationality and the Performance Measure

What makes an agent intelligent rather than just reactive? Rationality. A rational agent always chooses the action expected to maximize its performance measure — a score that captures how well it achieves its goal. For the thermostat: "minutes the room stays within 2°F of target". For a chess bot: "did we win?"

Rationality does NOT mean the agent knows the future or is always right. It means the agent makes the best possible choice given what it currently knows. Designing AI is largely about designing good performance measures and giving the agent enough information to optimize them.

Common mistake

Rational Does Not Mean Omniscient

A common mistake is thinking a "rational" agent must always succeed or must know everything. Neither is true.

Imagine picking a restaurant based on great reviews — rational! But if it's closed that night, your rational choice still led to a bad outcome. Rationality is about the quality of the decision process, not the outcome.

AI agents are the same: rational means doing the best you can with available information.

A richer example — the vacuum robot. Two inputs (location + dirt status), three possible actions. A complete two-room policy in 10 lines.
def vacuum_agent(location, status):
    """
    location: 'A' or 'B'
    status: 'dirty' or 'clean'
    """
    if status == "dirty":
        return "suck"
    elif location == "A":
        return "move_right"
    else:
        return "move_left"

percepts = [("A", "dirty"), ("A", "clean"), ("B", "dirty"), ("B", "clean")]
for loc, stat in percepts:
    print(f"Room {loc} is {stat:6s}  ->  {vacuum_agent(loc, stat)}")

#What Kind of World? Environment Properties

The type of environment shapes how complex the agent needs to be:

  • Observable vs. Partially Observable — Can the agent see the full state of the world? A chess board is fully observable. A poker game is partially observable — you can't see your opponent's cards. Partial observability forces the agent to remember past percepts and build an internal model of what it can't see.
  • Deterministic vs. Stochastic — Does every action have a guaranteed outcome? A thermostat is deterministic. A self-driving car is stochastic — brakes usually work, but ice may cause surprises.

Our thermostat and vacuum robot use hand-coded rules — every if/else was written by a human. These are simple reflex agents: they react to the current percept with no memory and no learning. Real AI systems go further. A learning agent observes how well its actions work and updates its own agent function to improve over time — that is exactly where machine learning enters. But the percept-action loop never changes. Whether the agent is a thermostat or a language model, it is always doing the same thing: perceiving and acting to maximize a goal.

Quick check

A spam filter reads incoming emails and either moves them to spam or leaves them in the inbox. It is designed to maximize the number of correctly sorted emails. Which part of this system is the agent's "performance measure"?

Key takeaways

  • An intelligent agent perceives its environment through sensors and acts through actuators in a continuous percept-action loop.
  • The agent function maps each percept to an action — this is the 'brain' you design when building AI.
  • A rational agent picks the action expected to maximize its performance measure given available information — it doesn't need to be omniscient.
  • Environment properties like observability and determinism determine how complex an agent needs to be.
  • All AI systems — from thermostats to neural networks — share the same fundamental agent framework; the sophistication is in the agent function.
Practice challenges
Test yourself · earn XP
0/4
Predict the output#1

This is the vacuum robot's agent function from the lesson, run over a full cycle of percepts. What does it print?

predict-output
def vacuum_agent(location, status):
    if status == "dirty":
        return "suck"
    elif location == "A":
        return "move_right"
    else:
        return "move_left"

percepts = [("B", "dirty"), ("B", "clean"), ("A", "clean")]
for loc, stat in percepts:
    print(vacuum_agent(loc, stat))
Fix the bug#2

This thermostat agent is supposed to turn on the heat when the room is below the target of 70F. It has a bug — what's wrong?

fix-bug
def thermostat_agent(temperature, target=70):
    if temperature < target:
        return "turn_off_heat"
    else:
        return "turn_on_heat"

print(thermostat_agent(65))
Fill in the blank#3

Complete the percept-action loop that runs the thermostat agent over a list of readings. The loop should feed each temperature (the percept) into the agent function to choose an action.

def thermostat_agent(temperature, target=70):
    if temperature < target:
        return "turn_on_heat"
    else:
        return "turn_off_heat"

readings = [65, 70, 72]
for temp in readings:
    action = (temp)
    print(f"Percept: {temp}F -> Action: {action}")
Reorder the lines#4

Put these lines in order to run one full turn of the percept-action loop inside a while loop, following the lesson's steps: perceive the current state, decide an action, act on it, then repeat.

1
    action = agent_function(percept)
2
    percept = read_environment()
3
    at_goal = act(action)
4
while not at_goal:
Your turn
Practice exercise

Build a simple game-playing agent for a number guessing game. The agent is trying to guess a secret number between 1 and 100. Each round it receives a percept: 'too_low', 'too_high', or 'correct'. It should use a binary search strategy — always guessing the midpoint of its remaining range — to find the number in the fewest guesses.

Implement the agent and simulate it finding the secret number 73. Print each percept and action (guess) until the agent succeeds.

Try it live — edit the code and hit Run to execute real Python:

solution.py · editable