8: Building a Knowledge-Based Agent
A knowledge-based agent operates by maintaining a knowledge base (KB) and using inference to make decisions. This chapter outlines the architecture, processes, and applications of such agents.

8.1 Architecture of a Knowledge-Based Agent
The architecture of a knowledge-based agent includes:
Knowledge Base (KB): A repository of knowledge in the form of logical sentences.
Inference Engine: A system that derives conclusions or decisions based on the KB.
8.1.1 Knowledge Base (KB)
The KB contains:
Facts: Statements about the world. Example: "The sky is blue."
Rules: Logical relationships between facts. Example: "If it is raining, the ground is wet."
8.1.2 Inference Engine
The inference engine performs reasoning by:
Applying rules of logic (e.g., Modus Ponens).
Deriving new facts from existing ones.
Testing the truth of queries.
8.2 The Agent's Cycle
A knowledge-based agent operates in a continuous loop:
Perceive: Gather information about the environment through sensors.
Update KB: Add new information to the KB.
Reason: Use inference to deduce actions or responses.
Act: Execute actions through actuators.
Example:
Environment: A robot operating in a warehouse.
Perception: "A package is at location A."
KB Update: Add "Package(A)" to the KB.
Reasoning: "If a package is at location A, move to location A."
Action: The robot navigates to location A.
8.3 Knowledge Representation
8.3.1 Declarative Knowledge
Facts and rules explicitly stated in the KB. Example: "All humans are mortal: ∀x Human(x)→Mortal(x)\forall x \, Human(x) \rightarrow Mortal(x)∀xHuman(x)→Mortal(x)."
8.3.2 Procedural Knowledge
Knowledge about how to perform tasks, represented as algorithms or procedures. Example: "To move to location A, navigate along the shortest path."
8.4 Logical Inference
Logical inference is the process of deriving new knowledge from existing facts and rules.
8.4.1 Forward Chaining
Starts with known facts and applies rules to derive new facts. Example:
Fact: "It is raining."
Rule: "If it is raining, the ground is wet."
Conclusion: "The ground is wet."
8.4.2 Backward Chaining
Starts with a goal and works backward to determine if the goal can be satisfied. Example:
Goal: "Is the ground wet?"
Check Rule: "If it is raining, the ground is wet."
Verify Fact: "It is raining."
Conclusion: "Yes, the ground is wet."
8.5 Handling Uncertainty
Not all environments provide complete or reliable information. Knowledge-based agents use probabilistic reasoning to manage uncertainty.
8.5.1 Probabilistic Logic
Incorporates probabilities into logical reasoning. Example: "There is a 70% chance that it will rain tomorrow."
8.5.2 Bayesian Networks
Graphical models that represent probabilistic relationships between variables. Example: Predicting the likelihood of a traffic jam based on weather and time of day.
8.6 Applications of Knowledge-Based Agents
8.6.1 Automated Customer Support
Agents answer queries by reasoning about a knowledge base of FAQs and support documentation.
8.6.2 Diagnostic Systems
Medical systems use knowledge bases to infer diseases based on symptoms. Example: "If the patient has a fever and cough, they may have the flu."
8.6.3 Robotics
Robots use logical reasoning to plan and execute tasks in dynamic environments. Example: A delivery robot navigating a building to deliver packages.
8.7 Building a Knowledge-Based Agent: Example
Problem: Room Cleaning Robot
Environment: A robot operates in a 3x3 grid with dirty and clean tiles.
Objective: Clean all tiles while minimizing energy consumption.
Steps:
Knowledge Base:
Facts: "Tile A1 is dirty."
Rules: "If a tile is dirty, clean it."
Inference:
Forward chaining: "Tile A1 is dirty → Move to A1 → Clean A1."
Action:
The robot navigates to A1 and cleans the tile.
8.8 Summary
In this chapter, we explored:
The architecture and operation of knowledge-based agents.
Techniques for knowledge representation and logical inference.
Applications in areas like customer support, diagnostics, and robotics.
A practical example of building a room-cleaning robot.
Last updated