A knowledge-based agent stores what it knows in a knowledge base and reasons from it to decide what to do.
Knowledge Base and Inference
A knowledge-based agent has a knowledge base (KB): a set of sentences expressed in a knowledge representation language. Sentences that are taken as given are axioms. The agent can TELL the KB new facts (percepts) and ASK it queries; the answer must follow from what has been told. The process of deriving new sentences from old ones is inference, done by an inference engine that uses the rules of logic. Because the KB is separate from the inference engine, this is the declarative approach: we tell the agent what it needs to know rather than programming every behaviour.
Definition: Knowledge base. A set of sentences in a formal language representing what an agent knows about the world, to which new sentences can be added (TELL) and from which conclusions can be drawn (ASK).
The Agent Cycle
At each step a generic knowledge-based agent does three things: TELLs the KB what it perceived; ASKs the KB what action to take; and then TELLs the KB that it performed that action. Representation (what the sentences say) and reasoning (how conclusions are drawn) are two separate issues; the representation language must be expressive enough for the facts and the reasoning sound.
Levels of a Knowledge-Based Agent
At the knowledge level we specify what the agent knows and its goals, regardless of implementation: for example, the taxi knows that the Golden Gate Bridge links two places. At the implementation level we choose data structures and algorithms. Logic gives a precise semantics: a sentence is true in a model if it holds in the possible world that the model describes; entailment KB ⊨ α means α is true in every model in which the KB is true. An inference procedure is sound if it derives only entailed sentences, and complete if it can derive every entailed sentence.
Strengths and Uses
Knowledge-based agents are flexible, can be given new goals and facts at run time, and can adapt to changes. They are the basis of expert systems, semantic web reasoners and rule engines. Their weakness is the cost of building the KB and the efficiency of inference.
Table 1.5: Knowledge-based agent vocabulary
| Term | Meaning | Example |
|---|---|---|
| Sentence | Statement in the language | Breeze at [2,1] |
| TELL | Add a fact to the KB | TELL(KB, percept) |
| ASK | Query the KB | ASK(KB, safe[2,2]?) |
| Entailment | KB ⊨ α | α true whenever KB true |
| Sound | Derives only entailed sentences | No false conclusions |
| Complete | Derives all entailed sentences | No missed conclusions |
Example 1.5: A tiny knowledge base
Problem: KB: (1) If it rains, the ground is wet. (2) It rains. Show how the agent answers "is the ground wet?".
Solution:
- TELL(KB, "rain → wet"). TELL(KB, "rain").
- ASK(KB, "wet")?
- Inference by modus ponens: from rain and rain → wet, derive wet.
- The answer is yes, because wet is entailed by the KB.
Result: The KB entails "wet"; the agent answers yes.
kb = {"rain"}
rules = [("rain", "wet"), ("wet", "slippery")]
def ask(q):
changed = True
while changed:
changed = False
for p, c in rules:
if p in kb and c not in kb:
kb.add(c)
changed = True
return q in kb
print("wet?", ask("wet"))
print("slippery?", ask("slippery"))
print("snow?", ask("snow"))
Output
wet? True
slippery? True
snow? False
Common mistakes
- Confusing the knowledge base (data) with the inference engine (procedure).
- Assuming an unsound inference procedure is acceptable because it is fast.
- Forgetting to TELL the KB about the actions the agent took.
- Treating "KB does not entail α" as "KB entails not α".
Key takeaways
- A KB holds sentences; TELL adds, ASK queries, inference derives conclusions.
- Entailment KB ⊨ α: α true in every model where the KB is true.
- Sound = only correct conclusions; complete = all correct conclusions.
- The declarative approach separates knowledge from reasoning.
Practice questions
- What do TELL and ASK do?
- What is entailment?
- What is a sound inference procedure?
Answers to the practice questions
- TELL adds sentences to the knowledge base; ASK queries it.
- KB ⊨ α means α is true in every model in which the KB is true.
- One that derives only sentences that are entailed by the KB.
Sources
- Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit I
