Knowledge-Based Agents
Introduction
Classical reflex agents map percepts directly to actions via hard-coded condition-action rules. They cannot reason about the world, handle novel situations, or explain decisions. A knowledge-based agent separates what the agent knows from how it acts. It maintains an explicit knowledge base (KB) — a set of sentences in a formal language — and uses a general-purpose inference engine to decide what to do.
This separation makes agents: - Flexible: new knowledge added without rewriting decision logic - Explainable: conclusions traceable to specific premises - Updatable: incorrect beliefs retracted and replaced
The KB-Agent Algorithm
Two primitive operations on the KB: - TELL(KB, sentence): Assert a new sentence (update beliefs). - ASK(KB, query): Query the KB — return what is entailed.
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
Step-by-step: 1. Convert the raw percept into a time-indexed logical sentence and assert it. 2. Derive the best action at time t via inference over the full KB. 3. Record the action taken so future reasoning accounts for history. 4. Advance time and return the action.
Declarative vs. Procedural Approaches
| Dimension | Declarative | Procedural |
|---|---|---|
| Knowledge encoding | Explicit sentences in formal language | Hard-coded programs |
| Action selection | Derived by general inference | Direct execution |
| Flexibility | High | Low |
| Transparency | High | Low |
| Speed | Slower (inference cost) | Fast |
Background Knowledge vs. Percept-Derived Knowledge
- Background knowledge (axioms): General domain rules
loaded at initialization.
- “If there is a breeze in a square, at least one adjacent square has a pit.”
- Percept-derived sentences: Specific observations
asserted at runtime.
- “At time 0, in square [1,1], there is no breeze.”
The combination of general rules and specific observations entails conclusions that neither alone supports.
Levels of Knowledge
- Knowledge level: What the agent can derive, independent of encoding.
- Logical level: The actual sentences in the KB and their relationships.
- Implementation level: Data structures and algorithms implementing the KB.
Good design keeps these levels clean. The knowledge engineer works at the logical level; the implementer works at the implementation level.
Why Formal Logic?
Logic provides: - Syntax: well-defined grammar for forming sentences - Semantics: precise truth values relative to possible worlds - Sound inference: derived conclusions are true if premises are true - Completeness (for some logics): every entailed sentence can be derived
No other representation (neural nets, lookup tables) gives all four properties simultaneously.