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: Agent=Perception+Reasoning+Action\text{Agent} = \text{Perception} + \text{Reasoning} + \text{Action}

  • 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: Dirty(RoomA)TELL(KB,Dirty(RoomA))\text{Dirty}(\text{RoomA}) \rightarrow \text{TELL}(\text{KB}, \text{Dirty}(RoomA))

    • Decide: ASK(KB,WhatShouldIDo?)Clean(RoomA)\text{ASK}(\text{KB}, \text{WhatShouldIDo?}) \rightarrow \text{Clean}(\text{RoomA})

    • Act: Execute Clean(RoomA)\text{Clean}(\text{RoomA}) and then TELL(KB,¬Dirty(RoomA))\text{TELL}(\text{KB}, \neg \text{Dirty}(RoomA)) to update the state.

Knowledge Base Rules and Reasoning: Temperature Example

  • KB Facts:

    • Temperature(18)\text{Temperature}(18)

    • DesiredTemp(22)\text{DesiredTemp}(22)

    • HeaterStatus(off)\text{HeaterStatus}(\text{off})

  • KB Rules (Logic):

    • \text{TurnOnHeater} \leftarrow \text{Temperature}(t) \wedge \text{DesiredTemp}(d) \wedge (t < d) \wedge \text{HeaterStatus}(\text{off})

    • TurnOffHeaterTemperature(t)DesiredTemp(d)(td)HeaterStatus(on)\text{TurnOffHeater} \leftarrow \text{Temperature}(t) \wedge \text{DesiredTemp}(d) \wedge (t \geq d) \wedge \text{HeaterStatus}(\text{on})

  • Inference Process (ASK):

    • The agent asks "What action should I take?"

    • Evaluation: (18 < 22) \wedge \text{HeaterStatus}(\text{off}) is True.

    • Result: The rule TurnOnHeater fires.

    • Update: Agent switches heater ON and executes TELL(KB,HeaterStatus(on))\text{TELL}(\text{KB}, \text{HeaterStatus}(\text{on}))

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: PerceptCondition MatchingAction\text{Percept} \rightarrow \text{Condition Matching} \rightarrow \text{Action}

  • 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: PerceptUpdate Internal StateCondition MatchingAction\text{Percept} \rightarrow \text{Update Internal State} \rightarrow \text{Condition Matching} \rightarrow \text{Action}

  • 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: PerceptUpdate StateCheck GoalSearch/PlanAction\text{Percept} \rightarrow \text{Update State} \rightarrow \text{Check Goal} \rightarrow \text{Search/Plan} \rightarrow \text{Action}

  • 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 a\vec{a} from S0\text{S}_0 achieves the Goal and is Legal?

  • Precondition Axioms:

    • Poss(goThru(d,r1,r2),s)Connected(d,r1,r2)InRoom(robot,r1,s)\text{Poss}(goThru(d, r_1, r_2), s) \equiv Connected(d, r_1, r_2) \wedge InRoom(robot, r_1, s)

    • Poss(pushThru(x,d,r1,r2),s)Connected(d,r1,r2)InRoom(robot,r1,s)InRoom(x,r1,s)\text{Poss}(pushThru(x, d, r_1, r_2), s) \equiv Connected(d, r_1, r_2) \wedge InRoom(robot, r_1, s) \wedge InRoom(x, r_1, s)

  • Successor State Axioms: Logic that determines if an object is in a room after an action.

    • General rule: InRoom(x,r,do(a,s))γ+(x,r,a,s)(InRoom(x,r,s)¬γ(x,r,a,s))\text{InRoom}(x, r, do(a, s)) \equiv \gamma^{+}(x, r, a, s) \vee (\text{InRoom}(x, r, s) \wedge \neg \gamma^{-}(x, r, a, s))

    • This accounts for the Frame Problem: objects stay where they are unless an action explicitly moves them.

  • Five Logical Clauses for Successor State:

    1. Non-robot objects are unaffected by goThru actions.

    2. Non-robot objects are unaffected by pushThru actions performed on other objects.

    3. Object xx stays in its location unless xx itself is the object being pushed.

    4. The robot moves to a new room when it performs a pushThru action.

    5. 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:

    1. The goal is achieved.

    2. The goal becomes impossible.

    3. 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."