Lesson 2 / 25
Intelligent Agents and Environments
Perceive, decide, act, repeat.
The agent view of AI
A useful way to frame AI is the agent: anything that perceives its environment through sensors and acts on it through actuators, choosing actions to maximise a performance measure. Environments differ: fully or partially observable, deterministic or stochastic, single or multi-agent, static or dynamic, discrete or continuous. Agent designs range from simple reflex agents (condition-action rules) to goal-based, utility-based and learning agents. The rest of AI is largely about building the decision-making part.
A reflex agent in a two-room vacuum world, run
I ran this with plain Python 3 (standard library only), with fixed random seeds where randomness is used. A simple rule (suck if dirty, otherwise move to the other room) cleans both rooms in three steps, then keeps moving back and forth because a reflex agent has no memory or goal to tell it to stop. Its score is 17 (10 per clean, minus 1 per move).
# A simple reflex agent in a two-room vacuum world
def agent(percept):
room, dirty = percept
if dirty: return "suck"
return "right" if room == "A" else "left"
world = {"A": True, "B": True}; room = "A"; score = 0
for step in range(5):
action = agent((room, world[room]))
if action == "suck": world[room] = False; score += 10
else: room = "B" if action == "right" else "A"; score -= 1
print(f"step {step}: action {action:<5} -> now in {room}, dirty rooms {[r for r in world if world[r]]}")
print("performance score:", score)
Output:
step 0: action suck -> now in A, dirty rooms ['B'] step 1: action right -> now in B, dirty rooms ['B'] step 2: action suck -> now in B, dirty rooms [] step 3: action left -> now in A, dirty rooms [] step 4: action right -> now in B, dirty rooms [] performance score: 17
Define the performance measure first
Decide what "doing well" means (clean floor, low energy, short time) before designing the agent; it changes the right behaviour.
Quick check: What does a simple reflex agent base its action on?
- Only the current percept, using condition-action rules
- A full model of the future
- A learned value function
- A conversation history
Answer
Only the current percept, using condition-action rules — No memory, no planning.