Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 36 ยท Rule-based Expert Systems

The Architecture of an Expert System

Learn the parts of an expert system: knowledge base, working memory, inference engine, explanation facility and user interface, plus who builds it, with a runnable Python skeleton.

An expert system is a program that captures the knowledge of a human specialist in a narrow field and uses it to give advice, make a diagnosis or choose an action. Famous early examples are DENDRAL (identifying chemical structures from spectra) and MYCIN (recommending antibiotics for blood infections). Modern descendants are hidden inside tax software, product configurators, equipment troubleshooters and loan-approval engines.

What makes an expert system different from an ordinary program is its structure: the knowledge sits in its own box, separate from the code that uses it. This lesson shows each component and builds a working skeleton.

The components

flowchart LR
  U["User"] <--> UI["User interface"]
  UI <--> IE["Inference engine"]
  IE <--> KB["Knowledge base<br/>(rules)"]
  IE <--> WM["Working memory<br/>(current facts)"]
  IE --> EX["Explanation facility"]
  EX --> UI
  KA["Knowledge acquisition<br/>tool"] --> KB
  DE["Domain expert<br/>+ knowledge engineer"] --> KA

Knowledge lives in the knowledge base; the engine is general and can run a different knowledge base without being rewritten.

Component Job
Knowledge base The rules (and facts) of the domain, written by experts. Long-lived.
Working memory The facts of the current case: user answers, sensor readings, conclusions so far. Short-lived.
Inference engine Chooses which rules to apply and in what order; the same engine works for any knowledge base.
User interface Asks questions, shows advice. Often a dialog or a form.
Explanation facility Answers "why are you asking this?" and "how did you reach that conclusion?"
Knowledge acquisition tool Helps experts enter and test rules.

Parts of an expert system

Knowledge base Rules from experts
Working memory Facts of this case
Inference engine Picks and fires rules
Explanation Why and how

Knowledge is separate from control

1 / 2

The people involved

Three roles appear in every project. The domain expert has the skill. The knowledge engineer interviews the expert, observes how decisions are made and writes the rules. The end user consults the finished system. Getting knowledge out of an expert's head, called knowledge acquisition, is usually the slowest and most important part of the project, because experts often cannot state their rules directly and are better at describing cases.

Expert system shells

A shell is an expert system with the knowledge removed: you get the inference engine, the interface and the explanation facility, and you only supply the rules. CLIPS and Drools are well-known shells; later lessons build a miniature shell of our own.

A first skeleton in Python

The code below shows the architecture in about forty lines. The knowledge base is a plain list of rules, the working memory is a set, and the engine is a loop. Notice that nothing about animals or medicine appears inside the engine class.

Python Skeleton with knowledge base, working memory and engine

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

To switch domains you would only replace car_rules. The engine does not change. That is the central architectural idea of the field.

The dialog with the user

A real system rarely gets all facts up front. It asks. Below, the engine asks for a missing fact only when a rule needs it, and each question carries a why explanation: the rule that triggered it. Answers are scripted here so the example is deterministic.

Python Asking questions only when needed (scripted answers)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The question list is short because the rules only ask what they need. The following lessons show how engines do this automatically: forward chaining starts from data, and backward chaining starts from a goal and asks only for what is required.

When expert systems fit

  • The domain is narrow and well bounded, and experts agree on most answers.
  • Decisions follow identifiable rules and benefit from consistency.
  • The knowledge changes slowly enough that rules can be maintained.
  • An explanation of the reasoning matters (medicine, finance, compliance).

They fit poorly when knowledge is huge and fuzzy, when answers come from patterns in data rather than rules (use machine learning), or when no expert is available. Combining the two, rule-based systems for explainable logic and learned models for pattern recognition, is common in practice.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main architectural idea of an expert system?

    Separating the knowledge base from the engine lets you change or reuse either without rewriting the other.
  2. 2. What is stored in working memory?

    Working memory holds the case facts; the knowledge base holds the permanent rules.
  3. 3. Who writes the rules in a typical project?

    Experts know the field, knowledge engineers turn that knowledge into rules.
  4. 4. What is an expert system shell?

    A shell gives you everything except the domain knowledge.

Summary

  • An expert system = knowledge base + working memory + inference engine + interface + explanation facility.
  • Domain experts, knowledge engineers and users each have a role; knowledge acquisition is the bottleneck.
  • A shell is an expert system without its knowledge; swapping the rules changes the domain.
  • Good fits are narrow, rule-like domains where explanation matters.

Next: Forward Chaining