Logical Agents and Planning Study Guide
Fundamentals of Logical Agents
Definition of a Logical Agent: A logical agent functions by deducing what actions to take based on a Knowledge Base (KB) consisting of "words" or symbolic representations about the world.
Composition of the Knowledge Base (KB):
Axioms: General information and rules regarding how the universe works.
Percept Sentences: Specific facts derived from the agent's experience in a particular reality.
Decision-Making Basis: Decision-making is grounded in explicit, verifiable symbolic reasoning. It is distinct from simple pattern matching or reflex-based reactions.
Core Requirements for a Logical Agent:
A method to represent internal beliefs about the world.
A method to reason about how specific actions change the state of the world.
A method to plan sequence of actions to achieve a designated goal.
The Agent Architecture and Inference Loop
Agent Formula:
The Inference Engine: This component applies logical rules to the Knowledge Base (KB) to derive new conclusions and determine actions.
Core Operations:
TELL: The process of adding a new fact to the KB (typically after perceiving an environmental stimulus).
ASK: The process of querying the KB to determine the next appropriate action.
Example Logic Loop (Vacuum Agent):
Perceive:
Decide:
Act: Execute and then to update the state.
Knowledge Base Rules and Reasoning: Temperature Example
KB Facts:
KB Rules (Logic):
\text{TurnOnHeater} \leftarrow \text{Temperature}(t) \wedge \text{DesiredTemp}(d) \wedge (t < d) \wedge \text{HeaterStatus}(\text{off})
Inference Process (ASK):
The agent asks "What action should I take?"
Evaluation: (18 < 22) \wedge \text{HeaterStatus}(\text{off}) is True.
Result: The rule
TurnOnHeaterfires.Update: Agent switches heater ON and executes
Hierarchy of Agent Types
Type | Decision Mechanism | Example |
|---|---|---|
Simple reflex | If-then rules based ONLY on current percept | Thermostat (fixed threshold) |
Model-based reflex | Internal state + rules; remembers the past | Roomba with a room map |
Goal-based | Considers future states to achieve goals | GPS navigator |
Logical agent | Full Knowledge Base + Inference Engine | BDI agent, theorem prover |
Simple Reflex Agents
Core Concept: Actions are based solely on the current percept. These agents have no memory of previous states and no internal model of the world.
Process Flow:
Programmatic Structure:
def simple_reflex_agent(percept):
rule = match_rule(percept, rules)
action = rule.action
return action
Example rules for a Vacuum:
If Current location is dirty $\rightarrow$ Clean
If Current location is clean $\rightarrow$ Move forward
If Bump into wall $\rightarrow$ Turn right / Turn left
Limitations:
No memory: Cannot handle sequences or historical context.
Partially observable environments: If the agent can't see the full state, it may enter infinite loops or act incorrectly.
Inflexible: Cannot adapt to any situation not explicitly covered by its rules.
Model-Based Reflex Agents
Core Concept: Solves the memory limitation of reflex agents by maintaining an internal representation of the world that is updated with every percept.
Components of the Model:
Transition Model: Knowledge of how the world changes over time independently and as a result of actions.
Sensor Model: Knowledge of what the current percept indicates about the invisible parts of the world.
Process Flow:
Programmatic Structure:
def model_based_reflex_agent(percept, state, model, rules):
state = update_state(state, percept, model)
rule = match_rule(state, rules)
action = rule.action
return action
Applications:
Vacuum World: Remembers which rooms were cleaned even if they aren't currently visible.
Self-Driving Car: Tracks objects that move out of sensor range or remembers signal phases from seconds ago.
Strengths:
Handles partial observability.
Context-aware decisions.
Limitations: Still rule-based (no forward-looking planning/optimization); the internal model can drift from reality if the transition/sensor models are inaccurate.
Goal-Based Agents
Core Concept: Rather than just reacting, these agents think ahead to choose actions that lead to a specific desired state (a goal).
Process Flow:
Operational Logic:
If the goal is not yet achieved, search for a sequence of actions that reaches it.
Changing behavior is simple: modify the goal rather than rewriting rules.
Comparison: Model-Based Reflex vs. Goal-Based:
Both have internal states.
Only Goal-Based has an explicit Goal and the ability to plan ahead.
Goal-Based agents know when to stop and are flexible to new objectives.
Planning and Situation Calculus
Planning Definition: The process of determining future states and observing the world during execution to re-plan as necessary.
Situation Calculus: A logic framework used to formalize how actions affect the world.
Formal Goal: Given everything known (KB), can we conclude that executing a sequence of actions from achieves the Goal and is Legal?
Precondition Axioms:
Successor State Axioms: Logic that determines if an object is in a room after an action.
General rule:
This accounts for the Frame Problem: objects stay where they are unless an action explicitly moves them.
Five Logical Clauses for Successor State:
Non-robot objects are unaffected by
goThruactions.Non-robot objects are unaffected by
pushThruactions performed on other objects.Object stays in its location unless itself is the object being pushed.
The robot moves to a new room when it performs a
pushThruaction.Frame Rule: An object only appears in a room if an action explicitly moved it there.
Belief-Desire-Intention (BDI) Model
Beliefs: The agent's internal model of what it thinks is true. These can be wrong or incomplete and are updated via perception.
Desires: The total set of goals the agent would like to achieve (e.g., "all rooms clean" or "save battery"). These may be conflicting.
Intentions: The specific desires the agent has committed to. Commitment is vital as it prevents the agent from wasting time "re-deliberating" at every step.
Commitment Logic: The agent follows through on intentions until:
The goal is achieved.
The goal becomes impossible.
A significantly better option appears.
Real-World Interaction Example:
Belief: "It's raining outside."
Desire: "I want to stay dry."
Intention: "I am committed to taking an umbrella."