Knowledge-Based Agent Demo

Interactive Visualization of the KB-AGENT Algorithm

Back to Lecture Overview

The KB-AGENT Algorithm

function KB-AGENT(percept) returns an action persistent: KB, a knowledge base t, a counter, initially 0, indicating time TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t)) action ← ASK(KB, MAKE-ACTION-QUERY(t)) TELL(KB, MAKE-ACTION-SENTENCE(action, t)) t ← t + 1 return action

Key Operations: TELL Adds a sentence to the KB | ASK Queries the KB to infer information

Select Scenario

Understanding Agent Actions
🔄 Turn: Rotates in place (changes arrow direction)
No position change - only orientation changes
➡️ Forward: Moves to adjacent cell
Position changes in current direction

Environment

Time Step: 0
Ready to Start
KB Syntax Guide
TELLAdd a new fact to the Knowledge Base
ASKQuery the KB to infer information
Location(Agent, [x, y], t)Agent is at position [x,y] at time t
Percept([...], t)What the agent senses at time t
Action(type, t)Action taken at time t

Knowledge Base (KB)

// Knowledge Base is empty
Understanding This Entry

Process Steps

1
Perception Processing

Convert percept into logical sentence and TELL to KB

2
Action Selection

Use ASK to query KB and infer best action

3
Action Execution

Add chosen action to KB and execute in environment

4
Update & Continue

Increment time counter and repeat cycle

How to Use This Demo

Interactive Tip: Click on any entry in the Knowledge Base to see a detailed explanation of what it means! The explanation will stay visible until you click "Next Step" or "Reset".
Getting Started:
  1. Choose a scenario (Simple World, Wumpus World, or Navigation)
  2. Click Start to initialize the KB-Agent
  3. Click Next Step to advance through each phase
  4. Watch how the KB grows with each cycle
  5. Click KB entries to understand the syntax
What to Observe:
  • How percepts are converted to logical sentences
  • The difference between TELL (add facts) and ASK (query)
  • How the agent reasons to select actions
  • The time counter incrementing with each cycle
  • Knowledge accumulation over time

Understanding the Demo

How It Works:
  • Perceive: Agent senses the environment (e.g., breeze, stench)
  • Update KB: Converts percepts to logical sentences using TELL
  • Infer: Uses ASK to reason about the world
  • Act: Selects and executes the best action
Key Concepts:
  • Declarative: Agent stores "what" it knows, not "how" to act
  • Inference: Uses logical reasoning to derive new facts
  • Persistent KB: Knowledge accumulates over time
  • Time-Aware: Each percept and action is timestamped

Example KB Syntax Explanations

Here are examples of what you'll learn when you click on KB entries during the demo:

TELL: Percept([Stench, Breeze], 4)

Means: At time 4, the agent sensed Stench and Breeze. This information is being added to the KB. The agent will use this to infer that there might be danger nearby.

ASK: BestAction(3)

Means: At time 3, the agent is asking: "Given everything I know in my KB, what's the safest/best action to take now?" The inference engine processes all the facts to answer this.

INFERRED: Action = Turn

Means: After reasoning about the percepts and current knowledge, the agent concluded that "Turn" is the best action. This wasn't told to the agent - it figured it out through logical reasoning!

Location(Agent, [2, 3], 3)

Means: At time 3, the agent is at position [2, 3] in the grid. This is stored so the agent always knows where it is and can reason about its location.

TELL: Stench([2, 3], 4)

Means: The agent is recording that it detected stench at location [2, 3] at time 4. This helps build a map of the environment and warns of the Wumpus nearby.

TELL: Action(Turn, 3)

Means: The agent is recording that it performed the "Turn" action at time 3. This creates a history of what the agent has done, which can be useful for future reasoning.

Pro Tip: As you step through the demo, click on each new KB entry to understand how the agent represents knowledge in logical form. This will help you master the syntax and semantics of knowledge-based agents!