Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lab1: Agents Implementations

Open in Colab

What You’ll Learn

  • Build simple AI agents (reflex, model-based, goal-based)

Prerequisites: Basic Python knowledge

Setup

Import required libraries for our implementations.

✓ Libraries imported successfully!

1. Simple Reflex Agent

A reflex agent makes decisions based only on the current percept (observation).

Example: Thermostat Agent

The agent reads room temperature and decides to turn heater on/off.

Testing Thermostat Agent:
Room at 18°C → HEAT_ON
Room at 25°C → HEAT_OFF
Room at 22°C → HEAT_OFF

Visualization: Agent Behavior Over Time

<Figure size 1000x600 with 2 Axes>
Final temperature: 22.2°C

Enhanced termostat agent with tolerance

To reduce frequent heater state switching, we can introduce a tolerance level.

Time	Temp	Action
------------------------------
0	18.0°C	heat
1	18.6°C	heat
2	18.9°C	heat
3	19.3°C	heat
4	19.7°C	heat
5	20.3°C	heat
6	20.8°C	heat
7	21.5°C	idle
8	21.3°C	idle
9	21.3°C	idle
10	21.1°C	idle
11	21.0°C	heat
12	21.5°C	idle
13	21.3°C	idle
14	21.2°C	idle
15	21.2°C	idle
16	21.3°C	idle
17	21.1°C	idle
18	21.2°C	idle
19	21.3°C	idle

Final temperature: 21.1°C

visualization of enhanced agent behavior

<Figure size 1000x600 with 2 Axes>

2. Model-Based Agent

A model-based agent maintains an internal state to track the world.

Example: Vacuum Cleaner Agent

The agent remembers which rooms it has cleaned.

Vacuum Agent Cleaning Process:
Step 1: Room A → CLEAN
Step 2: Room B → MOVE_TO_B
Step 3: Room B → CLEAN
Step 4: Room C → MOVE_TO_C
Step 5: Room C → CLEAN
Step 6: Room C → DONE

Final state: {'A': True, 'B': True, 'C': True}