# Lab 1: Agent functions in the vacuum world — step-by-step guide

## Context

This laboratory accompanies Lecture 1 (slides 9–24) of 5DV248 Trustworthy Human-AI Interaction and follows AIMA Section 2.1 (Russell and Norvig, *Artificial Intelligence: A Modern Approach*). The page implements the vacuum-cleaner world used throughout the lecture: the classic two-square environment in which an agent perceives its location and the dirt status of the square it occupies, and responds with one of four actions. The point of the lab is that an agent is nothing more than a function from percepts to actions, and that you, as the designer, define that function.

## Objective

The objective is to understand, by direct experimentation, three ideas from the lecture:

1. An agent perceives its environment through percepts and acts on it through actuators; in this world the percept is the pair (location, status) and the actions are Left, Right, Suck and NoOp.
2. The agent function maps percept sequences to actions. Here it is expressed as four condition-action rules that you can edit.
3. The same environment, combined with different rules, produces very different agent behaviour. Behaviour lives in the rules, not in the environment.

## The interface

- The blue dot is the agent. It is the only thing that "decides": at every time step it receives the percept (location, status) of the square it occupies and executes the action selected by your rules. It never sees the world directly, only its current percept.
- The two large squares, labelled A and B, are the environment. A brown square is Dirty; a light square is Clean. Clicking a square toggles dirt on or off, so you design the situations the agent must face.
- The table on the right is your agent function: one row per possible percept, one dropdown per row. The defaults are exactly the REFLEX-VACUUM-AGENT from the slides (Suck if dirty, otherwise cross to the other square).
- Step executes one percept-action cycle and appends it to the log. Run repeats the cycle automatically; Stop pauses it. Reset restores both dirty squares, the agent location A and the original counters.
- The percept-action log records, for every time step, the percept the agent received and the action it took. This is the agent function evaluated before your eyes.
- The counters report the time step, the number of Suck actions, the number of moves and the dirt remaining.

## Your goal as a student

You play the designer, not the agent. Your goal is to predict, edit and verify:

1. Set the world to A Dirty and B Dirty. Before pressing Step, write down the sequence of actions you expect from the default rules. Run it and compare with your prediction.
2. Change the rule for (A, Clean) to NoOp. Which behaviour do you expect? Verify it and explain the difference in the log.
3. Clean both squares and continue running. Observe that the agent keeps moving although no dirt remains. Explain why: the rules only look at the current percept, and no percept ever tells the agent that the whole world is clean.
4. Devise, by editing the four rules, a rule set that you believe behaves well, and one that behaves badly. For each, describe in one sentence what makes the difference.
5. Finally, answer the central question of the lab: can any assignment of these four rules make the agent stop (NoOp) once both squares are clean? Argue your answer in terms of percepts. This prepares the discussion of memory and model-based agents in Lecture 1 and Lab 4.