UPI Study › Courses › Introduction to Artificial Intelligence › Free lessons › Lesson 2.5 Free with a free account
Reactive Agents: Condition-Action Responses
Introduction to Artificial Intelligence · Chapter 2: Intelligence, Cognition, and Agent DesignSection 2.5 · lesson 13 of 6911 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Artificial Intelligence.
Lesson complete
Earn the 3 college credits for Introduction to Artificial Intelligence
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: How Model-Based Agents Track Their World →← Building Blocks of Intelligent AgentsNext lesson: How Model-Based Agents Track Their World →
In this lesson
How simple reflex agents use condition-action rules and where they fail.
- Define a reactive agent and write condition-action rules for it
- Explain why rule order, a default rule, and coverage of percepts matter
- Trace a reactive agent and identify partial observability and looping problems
- Decide when a purely reactive design is the right choice
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,610 words). Read along, or search it.
Opening Example
Reflexes in People and Machines
Touch a hot pan, and your hand pulls away before you have time to think. No memory of the last burn, no plan. A sensor detects something, and a ready-made response fires. Some of the most useful machines work exactly this way. An automatic door opens when it senses a person. A thermostat switches the heater when the room gets cold. And a cliff sensor stops a toy robot at the edge of a table. These are reactive agents, the simplest kind of intelligent agent. How much can pure reflexes do, and where do they run out?
Definition
Acting on the Current Percept Alone
An agent senses its surroundings through sensors, and acts on them through actuators. What the sensors report at a given moment is called a percept. A reactive agent, also called a simple reflex agent, chooses its action using only the current percept. It keeps no record of the past. It holds no picture of how the world works. And it doesn't think ahead about the results of its actions. It matches what it senses now against a list of rules, and carries out the action of the matching rule. Then it does it all again.
Condition-Action Rules
If a Condition, Then an Action
The building block is the condition-action rule: if a condition, then an action. The condition tests the current percept. The action is what the agent does when the test is true. An automatic door: if a person is detected in front of it, open. If no person is detected for 5 seconds, close. A toy robot: if the cliff sensor reports no floor ahead, stop and back up. A streetlight: if the light level is below the set value, switch the lamp on.
Design Steps
Six Steps to Build a Reactive Agent
Building a reactive agent takes six design steps, and no advanced technique. List the percepts: exactly what the sensors report. List the actions the agent can take. Then write a rule for each situation that matters. Order the rules by priority, because the agent uses the first rule that matches. Add a default rule at the end, so it always has something to do. And test every kind of percept, to check that each one leads to a sensible action.
Agent Cycle
Read, Match, Act, Repeat
Once the rules exist, the agent runs one short cycle, over and over. Read the sensors, to get the current percept. Go down the rule list, and find the first rule whose condition is true. Carry out that rule's action. Then go back to the start. Writing this cycle as pseudocode, and then as code, comes in chapter 3.
Rule Priority
Why Safety Rules Go First
Order really matters. A delivery robot has two rules. Rule X: if the battery is low, go to the charger. Rule Y: if an obstacle is closer than 10 centimeters, stop. Now the battery is low, and an obstacle is 5 centimeters away. Both conditions are true. With the battery rule first, the robot heads for the charger, and keeps driving toward the obstacle. A collision is likely. With the obstacle rule first, it stops before the obstacle. That's safe, and charging resumes once the path is clear. Safety rules belong at the top of the list.
Coverage
Every Sensor Multiplies the Situations
A reactive agent also needs a sensible response for every percept it might meet. And each extra sensor multiplies the number of situations. If each sensor gives one of four readings, one sensor gives 4 combinations. Two give 16, and three give 64. Five sensors give 1,024. Ten give over a million. In practice, many combinations share a rule. But the work of writing and checking rules still grows fast.
Classic Example
The Thermostat as Reactive Agent
Now two classic examples. A basic thermostat is the textbook reactive agent. Its sensor is a thermometer, and its only actuator is the heater switch. Rule one: if the reading is below 20 degrees Celsius, heater on. Rule two, the default: anything else, heater off. It doesn't need to remember how warm it was an hour ago, model how heat leaks through the walls, or predict tomorrow's weather. The current reading is enough.
Practical Fix
A Buffer to Stop Flickering
But a single threshold, sitting exactly at the target, makes the heater flip on and off, over and over. A real device would wear out quickly. The usual fix is a small buffer: switch on below 19 degrees, and off above 21. But in between, the heater must keep doing whatever it's already doing. So the agent has to know its current heater setting, by remembering its last action, or by sensing its own switch.
Classic Example
A Two-Square Vacuum World
The second classic is a tiny cleaning world with two squares, A and B. Each square is clean or dirty. The vacuum senses only the square it's standing in. Its percept has two parts: where it is, and whether that square is dirty. It can suck, move right, or move left. Its rules: one, if the current square is dirty, suck. Two, at A and clean, move right. Three, at B and clean, move left. Each of the four possible percepts triggers exactly one rule.
Trace
Cleaning Finished, Pacing Forever
Trace it. Both squares start dirty, and the agent starts at A. Step one: A, dirty. Rule one fires, and it sucks. Step two: A, clean. Rule two, move right. Step three: B, dirty. Suck. Now everything is clean. Step four: B, clean. Rule three, move left. Step five: A, clean, move right. Step six: B, clean, move left. And from then on: right, left, right, left. The job was finished at step three, but the agent never stops.
Quick Check
Starting at B With A Dirty
Quick check. Same agent, same three rules. This time A is dirty, B is clean, and the agent starts at B. How many actions does it take until both squares are clean? Pause, and predict. After two actions. At B, its own square is clean, so rule three sends it left. That's one. At A, the square is dirty, so rule one makes it suck. That's two, and both squares are clean. Then it keeps pacing back and forth anyway. One action is tempting, because only A is dirty. But the agent can't sense A from B. It has to move there first.
First Limit
Partial Observability Hides the World
That points to the first limit: partial observability. The sensors reveal only part of what's going on. The vacuum at A, seeing a clean square, gets the percept A, clean, whether B is clean or dirty. If B is clean, the best choice is to stop. If B is dirty, it's to go and clean B. But rule two sends the agent right in both cases. The trouble comes from what the agent can't sense, not from a mistake in the rule.
Second Limit
Endless Loops Without Memory
The second limit follows. A reactive agent can't remember where it's been, or what it's already done, so it can fall into an endless loop without noticing. Left, right, left, right. Loops aren't limited to one agent. Picture two people meeting in a narrow corridor, each following the rule: if someone is in front of me, step toward the window. They step aside together, face each other again, and repeat. Neither one remembers that this already happened.
Remedies
Randomness, More Sensors, or Memory
There are three ways to deal with these limits. Add randomness: a coin flip between two actions can break a repeating pattern. But behavior gets less predictable. Add more sensors: a richer percept shows more of the world, so fewer situations look alike. But that means more hardware, and many more rules. Or give the agent a memory, so it can tell it's repeating itself, or that the job is done. But then it's no longer purely reactive. That's the next step in agent design.
When Reactive Is Enough
Five Signs a Reflex Design Fits
Despite these limits, reactive agents are everywhere, and for the right job they're the best choice. A reactive design fits when most of five things are true. The current percept contains what's needed. The environment is simple and stable, so a short rule list covers it. Speed matters, with no time to deliberate, as with an emergency stop. The behavior must be easy to check: a short rule list can be tested exhaustively. And cost and reliability matter, because reactive agents need little memory, and little computing power.
Quick Check
Smoke Alarm, Mower, or Maze
Quick check. Three jobs for a simple machine. Sound an alarm whenever smoke is detected. Mow every strip of a lawn exactly once. Or find the way out of a maze, using a sensor that sees only the nearest wall. Which job can a purely reactive agent do well? Pause, and decide. The smoke alarm. Its current percept, smoke or no smoke, says everything the decision needs, and the response must be instant. Mowing each strip exactly once is the tempting second choice. But the mower must know which strips it has already cut, and that takes memory. And in the maze, the same view of a wall occurs in many places. It needs memory, or a map.
Layered Systems
A Reflex as a Safety Net
Reactive behavior often lives as one layer inside a more capable system. A warehouse robot may plan its route with sophisticated methods, yet keep a simple reflex: the moment a bumper sensor is pressed, stop the wheels. That reflex works even when the planner is busy, or has made a mistake. It's a fast safety net.
Key Takeaways
Rules, Order, Limits, and Fit
To sum up. A reactive agent picks its action from the current percept alone, using condition-action rules. Rules are checked in order, so priority matters, and a default rule means it's never left without an action. Partial observability makes different situations look the same, and without memory it can loop forever. And reactive agents are enough when the current percept holds what the decision needs. They also make fast reflexes inside bigger systems.
Reflection
Which Mower Behaviors Need Memory
Here's something to think about. A robot lawn mower has a bump sensor and a rain sensor. Which of its behaviors could be purely reactive? And which would be hard, or impossible, without remembering something?
About Introduction to Artificial Intelligence at UPI Study
Introduction to Artificial Intelligence (Computer Science 373) is a self-paced online course of 69 video lessons in 9 chapters, from intelligent agents and search to game strategy, neural networks, logic and reasoning, machine learning, language, robotics and AI ethics. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: AI vs Current Trends in CS and IT
Why take it here
Why students take Introduction to Artificial Intelligence with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Artificial Intelligence carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About Reactive Agents: Condition-Action Responses
What is a simple reflex agent in AI?
Why does rule order matter in a reactive agent?
What are the limitations of simple reflex agents?
When is a reactive agent the right choice?
About the Introduction to Artificial Intelligence course
How many college credits is Introduction to Artificial Intelligence?
How much does Introduction to Artificial Intelligence cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Artificial Intelligence take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Artificial Intelligence.
69 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
3 credits · NCCRSEnroll →