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.

Agents Assignments

Open in Colab

Overview

In this assignment, you will implement two different types of agents for two distinct problems:

  1. Assignment 1: Reflex Agent for a Traffic Light Controller

  2. Assignment 2: Model-Based Agent for a Security Patrol

Submission Requirements:

  • Complete all TODO sections

  • Run all test cells to verify your implementations

  • Answer the reflection questions at the end

Grading:

  • Assignment 1: 40 points

  • Assignment 2: 40 points

  • Reflection Questions: 20 points


Assignment 1: Reflex Agent - Traffic Light Controller (40 points)

Problem Description

You will implement a Simple Reflex Agent that controls a traffic light at an intersection. The agent perceives the current traffic conditions and decides which light to show.

Environment

  • 4-way intersection with North-South (NS) and East-West (EW) traffic

  • Each direction has a sensor that detects: 'none', 'light', 'moderate', or 'heavy' traffic

  • The traffic light can be in one of two states: 'NS_GREEN' (North-South green, East-West red) or 'EW_GREEN' (East-West green, North-South red)

Agent Specification

Your reflex agent should follow these rules:

  1. If current light is 'NS_GREEN' and EW traffic is 'heavy' while NS traffic is 'none' or 'light' → Switch to 'EW_GREEN'

  2. If current light is 'EW_GREEN' and NS traffic is 'heavy' while EW traffic is 'none' or 'light' → Switch to 'NS_GREEN'

  3. If both directions have 'heavy' traffic → Keep current state (don’t switch too frequently)

  4. If both directions have 'none' traffic → Keep current state

  5. Otherwise, switch to the direction with heavier traffic


Assignment 2: Model-Based Agent - Security Patrol Agent (40 points)

Problem Description

You will implement a Model-Based Reflex Agent that patrols a building with multiple rooms. Unlike the reflex agent, this agent maintains an internal model to remember which rooms it has visited.

Environment

  • A building with 6 rooms arranged in a line (Room 0 to Room 5)

  • The agent can move: 'LEFT', 'RIGHT', or 'STAY'

  • Each room can have a security event: 'clear' or 'alert'

  • The agent earns points for checking rooms and responding to alerts

Agent Specification

Your model-based agent should:

  1. Track visit history: Remember when each room was last visited

  2. Prioritize unvisited rooms: Prefer rooms not checked recently

  3. Respond to alerts: Always move toward rooms with alerts

  4. Patrol efficiently: Don’t stay in one place too long

Key difference from reflex agent: The model-based agent remembers past visits to make better patrol decisions.


Reflection Questions (20 points)

Answer the following questions in the cells below:

Question 1 (5 points)

What are the key limitations of the reflex agent (Traffic Light Controller) compared to the model-based agent (Security Patrol)? Give specific examples from your implementations.

Your answer here:

Question 2 (5 points)

How does maintaining an internal model (visit history) help the patrol agent make better decisions? What would happen if it only used current percepts like a reflex agent?

Your answer here:

Question 3 (5 points)

Could the traffic light controller benefit from being a model-based agent? What kind of internal model would you add, and how would it improve performance?

Your answer here:

Question 4 (5 points)

For each agent, identify the PEAS components (Performance measure, Environment, Actuators, Sensors):

Traffic Light Controller:

  • Performance:

  • Environment:

  • Actuators:

  • Sensors:

Security Patrol Agent:

  • Performance:

  • Environment:

  • Actuators:

  • Sensors:


Submission Checklist

Before submitting, make sure:

  • Assignment 1: TrafficLightReflexAgent.decide() is implemented

  • Assignment 1: All test cases pass

  • Assignment 2: SecurityPatrolAgent methods are implemented:

    • update_model()

    • get_least_recently_visited()

    • decide()

  • Assignment 2: At least 3 test cases pass

  • All 4 reflection questions are answered

  • All cells run without errors

Good luck! 🚀