Mark Proctor
Distinguished Engineer II
Chief Architect - Rules, BPM and Optimisation
Red Hat
Modernising Production Rule Systems

Rule Modularity and Execution Control
OPS5 (It Begins)
OPS
OPS5 1981
•Language
•Rete
•LEX/MEA
(p mb17
(goal ^status active ^type on ^object <o>)
(object ^name <o> ^at <p>)
(monkey ^at <p> ^holds nil)
-->
(write (crlf) "climb onto" <o>)
(modify 3 ^on <o>)
(modify 1 ^status satisfied))
OPS
•Official Production System.
•pre OPS5 linear Search.
•Conflict Resolution <McDermott, Forgy 1976>.
Working
Memory
Rules
Inference Engine
Pattern
Matching
Agenda
CLIPS
CLIPS 1993
•Lisp (ish)
•exists/forall
•Subnetworks
•Modules
•Simple TMS
(defrule climb-directly ""
?goal <- (goal-is-to (action on) (arguments ?obj))
(thing (name ?obj) (location ?place) (on-top-of ?on))
?monkey <- (monkey (location ?place) (on-top-of ?on) (holding blank))
=>
(printout t "Monkey climbs onto the " ?obj "." crlf)
(modify ?monkey (on-top-of ?obj))
(retract ?goal))
CLIPS
•Syntax based on ART (Haley Systems)
•Modules based on GoldWorks
•PIE Clips Modules
Working
Memory
Modules
Inference Engine
Pattern
Matching
Agenda
Jess
Jess7 2006
•Accumulate
•Slot Specific
•Backward Chaining (ish)
(deftemplate employee (slot salary) (slot name))
(defrule count-highly-paid-employees
?c <- (accumulate (bind ?count 0) ;; initializer
(bind ?count (+ ?count 1)) ;; action
?count ;; result
(employee (salary ?s&:(> ?s 100000)))) ;; CE
=>
(printout t ?c " employees make more than $100000/year." crlf))
Jess
•Java implementation of Clips syntax
Working
Memory
Modules
Inference Engine
Pattern
Matching
Agenda
Drools
Drools 6.x/7.x 2018
•Accumulate
•Temporal Operators
•Property Reactive
•Prolog(ish) Backward Chaining
•OOPath Graph Reasoning
Drools
•Clips/Jess derivative with Java-like language
Working
Memory
Modules
Inference Engine
Pattern
Matching
Agenda
Slow Progress
Is Still Progress
Still Here
Working
Memory
Modules
Inference Engine
Pattern Matching
Agenda
Still Here Working
Memory
Modules
Inference Engine
Pattern
Matching
Agenda
“Today, I want to make clear that the future prospects for
production rule technology are diminishing..…

production rule technology is inadequate ” 

(Paul Haley 2013)

http://haleyai.com/wordpress/2013/06/22/confessions-of-a-production-rule-vendor-part-1/
Still Here Working
Memory
Modules
Inference Engine
Pattern
Matching
Agenda
“Today, I want to make clear that the future prospects for
production rule technology are diminishing..…

production rule technology is inadequate” 

(Paul Haley 2013)

http://haleyai.com/wordpress/2013/06/22/confessions-of-a-production-rule-vendor-part-1/
Still Here Working
Memory
Modules
Inference Engine
Pattern
Matching
Agenda
“It’s time to trade rule technology dating back to the 80’s for
state of the art AI.” 

(Paul Haley 2018)

• http://haleyai.com/wordpress/2018/04/02/confessions-of-a-production-rule-vendor-part-2/
Still Here
Working MemoryModules
Inference Engine
Pattern Matching
Agenda
Still Here
Rule Modularity and
Execution Control
• Production system conflict resolution strategies (McDermott, Forgy 1976)
• Conflict Resolution + Control Token (Signals, GOTO)
• Mixes Control and Domain Logic in single rule
• This Pollution may be undesirable for readability and maintainability
• Does not guarantee rules for one token have fired before processing another token
• OPS MEA (Forgy 1981)
• Compares recency for the first pattern to find the dominant rule.
• Typically matches against a fact called a Context, Phase or Goal.
• Allows for goal-directed controlling of production systems which also introduces a
type of rule subroutine.
• Compares recency for the remaining elements
• LEX falls back on specificity and arbitrary.
Stylistic
• ROSIE (D. A. Waterman, 1979)
• Multiple data sets and rule sets.
• Only one ruleset and one data set can be active at a time.
• Eclips (NASA, 1991) PIE (NASA, 1988)
• Goal directed.
• Each goal has a context.
• Subroutine like.
• Clips Modules (NASA 1993)
• Push/Pop Stack
• No Context
• External Orchestration
• Rule Flow
Syntactic
Venus
• Rules and data are decoupled.
• Venus full hybrid C++ language.
• Single Root Module.
• Guard does not directly invoke Rule.

Instead it makes it legible for evaluation.
• Current consequence finishes, 

before potential next module is entered.
• Module may have 1..n Support. Will 

continue to evaluate, while it has support.
• If support is removed, module continues until it reaches fixed point (then it’s removed).
• Is single threaded a fair deterministic policy is used to help with selection,

which is controlled by the priority of the rule against its peers.
• Submitted module is identified by the combination of module name plus the passed
arguments.
Venus Rule Language
Venus Rule Language
Rule Works
• ENTRY-BLOCK
• C-callable entry block
• Can have their own rules
• Implicitly activate
• May activate one or more rule Rule-Blocks
• RULE-BLOCK
• Allow for rules to be shared across ENTRY-BLOCKs
• May not call other ENTRY-BLOCKs or RULE-BLOCKs.
• External Orchestration
Rule Works
• ON-ENTRY: Before the match step of the first recognize- act cycle. This can be used for
tasks like data initialisation.
• ON-EVERY: After the act step of every cycle except the last one. This can be used for
tasks like printing out the rule count.
• ON-EMPTY: After the select step when the conflict set is empty. This can be used to
detect state and return error information.
• ON-EXIT: After the act step of the last cycle. This can be used for things like cleanup
actions.
Rule Works
Rule Works Life Cycles
ON-ENTRY ON-EVERY
Match Act
Select ON-EMPTY
ON-EXIT
Call to Entry
Block
Operating
System
Caller of Entry
Block
• Neither Venus or RuleWorks made it into industrial or academic mainstream.
• Business Rules have simple requirements.
• Often spreadsheet driven.
• Variations Rule Flow suffices.
• Academia is funding driven, interests change over time.
Recency and Relevance of Works
Units
Units
package org.mypackage.myunit
public class AdultUnit implements RuleUnit {
private int adultAge;
private DataSource<Person> persons;
public AdultUnit( ) { }
public AdultUnit( DataSource<Person> persons, int age
) {
this.persons = persons;
this.age = age;
}
}
Units
package org.mypackage.myunit
public class AdultUnit implements RuleUnit {
private int adultAge;
private DataSource<Person> persons;
public AdultUnit( ) { }
public AdultUnit( DataSource<Person> persons, int age ) {
this.persons = persons;
this.age = age;
}
}
package org.mypackage.myunit
unit AdultUnit
rule Adult when
$p : /persons[age >= adultAge]
then
System.out.println($p.getName() +
" is adult and greater than " + 

adultAge);
end
Units package org.mypackage.myunit
unit AdultUnit
rule Adult when
$p : /persons[age >= adultAge]
then
System.out.println($p.getName() +
" is adult and greater than " + 

adultAge);
end
package org.mypackage.myunit
public class AdultUnit implements RuleUnit {
private int adultAge;
private DataSource<Person> persons;
public AdultUnit( ) { }
public AdultUnit( DataSource<Person> persons, int age ) {
this.persons = persons;
this.age = age;
}
@Override
public boolean onStart(RuleUnitInstance instance) { 

System.out.println(getName() + " started.”);
return true;
}
@Override
public boolean onEnd(RuleUnitInstance instance) {
return true;
}
}
Recommendation and Bidding Example
Recommendation and Bidding Example
Recommendation and Bidding Example
• PENDING: The unit is instantiated, but has not yet been started. 

• RUNNING: The unit is evaluating and executing rules. 

• DORMANT: The unit has either reached a fixed point and has no more work to
evaluate, or it has been requested 

to stop further evaluation. 

• YIELDED: The current executing unit has yielded (while 

still having more work to do) to another unit that has 

earlier scheduling. 

States
Unit Life Cycles
RUNNINGDORMANT YIELDED
start
true
resume
true
yield
true
onSuspend
suspend
true
onResume
onStart
onEnd
onYield
onResume
PENDING
FINISHED
RuleUnitInstance
Created
CANCELLED
start
false
resume
true
resume
false
suspend
false
yeld
false
resume
false
resume
request
resume
request
suspend
request
yield
request
start
request
ON-ENTRY ON-EVERY
Match Act
Select ON-EMPTY
ON-EXIT
Call to Entry
Block
Operating
System
Caller of Entry
Block
• @Yield(<boolean>)
• @TerminateOnEmpty
Additional Control via Annotations
• Depth first LIFO.
• Where the two guards exist for the same unit, the one that comes earlier in the rule
order has priority. 

• Where the two guards are not from the same unit, but the path of one subsumes the
path of the other, the deepest unit has priority. 

• Where the two guards are not from the same unit and one path does not subsume the
other, it will iterate the parent chain until it reaches the unit that is shared by both
Fairness
• Units as generic abstractions for runtimes
• Execution guards
• On every
• Inheritance
• Alternative orchestrations
• Refinements in rule execution
• @DataDriven / @Existence Driven
• @Incremental(<boolean>)
• @Sequential
Future Works
Conclusion
Mark Proctor
Distinguished Engineer II
Chief Architect - Rules, BPM and Optimisation
Red Hat
Modernising Production Rule Systems

Rule Modularity and Execution Control

Rule Modularity and Execution Control

  • 1.
    Mark Proctor Distinguished EngineerII Chief Architect - Rules, BPM and Optimisation Red Hat Modernising Production Rule Systems
 Rule Modularity and Execution Control
  • 2.
  • 3.
    OPS OPS5 1981 •Language •Rete •LEX/MEA (p mb17 (goal^status active ^type on ^object <o>) (object ^name <o> ^at <p>) (monkey ^at <p> ^holds nil) --> (write (crlf) "climb onto" <o>) (modify 3 ^on <o>) (modify 1 ^status satisfied)) OPS •Official Production System. •pre OPS5 linear Search. •Conflict Resolution <McDermott, Forgy 1976>. Working Memory Rules Inference Engine Pattern Matching Agenda
  • 4.
    CLIPS CLIPS 1993 •Lisp (ish) •exists/forall •Subnetworks •Modules •SimpleTMS (defrule climb-directly "" ?goal <- (goal-is-to (action on) (arguments ?obj)) (thing (name ?obj) (location ?place) (on-top-of ?on)) ?monkey <- (monkey (location ?place) (on-top-of ?on) (holding blank)) => (printout t "Monkey climbs onto the " ?obj "." crlf) (modify ?monkey (on-top-of ?obj)) (retract ?goal)) CLIPS •Syntax based on ART (Haley Systems) •Modules based on GoldWorks •PIE Clips Modules Working Memory Modules Inference Engine Pattern Matching Agenda
  • 5.
    Jess Jess7 2006 •Accumulate •Slot Specific •BackwardChaining (ish) (deftemplate employee (slot salary) (slot name)) (defrule count-highly-paid-employees ?c <- (accumulate (bind ?count 0) ;; initializer (bind ?count (+ ?count 1)) ;; action ?count ;; result (employee (salary ?s&:(> ?s 100000)))) ;; CE => (printout t ?c " employees make more than $100000/year." crlf)) Jess •Java implementation of Clips syntax Working Memory Modules Inference Engine Pattern Matching Agenda
  • 6.
    Drools Drools 6.x/7.x 2018 •Accumulate •TemporalOperators •Property Reactive •Prolog(ish) Backward Chaining •OOPath Graph Reasoning Drools •Clips/Jess derivative with Java-like language Working Memory Modules Inference Engine Pattern Matching Agenda
  • 7.
  • 8.
  • 9.
    Still Here Working Memory Modules InferenceEngine Pattern Matching Agenda “Today, I want to make clear that the future prospects for production rule technology are diminishing..…
 production rule technology is inadequate ” 
 (Paul Haley 2013)
 http://haleyai.com/wordpress/2013/06/22/confessions-of-a-production-rule-vendor-part-1/
  • 10.
    Still Here Working Memory Modules InferenceEngine Pattern Matching Agenda “Today, I want to make clear that the future prospects for production rule technology are diminishing..…
 production rule technology is inadequate” 
 (Paul Haley 2013)
 http://haleyai.com/wordpress/2013/06/22/confessions-of-a-production-rule-vendor-part-1/
  • 11.
    Still Here Working Memory Modules InferenceEngine Pattern Matching Agenda “It’s time to trade rule technology dating back to the 80’s for state of the art AI.” 
 (Paul Haley 2018)
 • http://haleyai.com/wordpress/2018/04/02/confessions-of-a-production-rule-vendor-part-2/
  • 12.
    Still Here Working MemoryModules InferenceEngine Pattern Matching Agenda
  • 13.
  • 14.
  • 15.
    • Production systemconflict resolution strategies (McDermott, Forgy 1976) • Conflict Resolution + Control Token (Signals, GOTO) • Mixes Control and Domain Logic in single rule • This Pollution may be undesirable for readability and maintainability • Does not guarantee rules for one token have fired before processing another token • OPS MEA (Forgy 1981) • Compares recency for the first pattern to find the dominant rule. • Typically matches against a fact called a Context, Phase or Goal. • Allows for goal-directed controlling of production systems which also introduces a type of rule subroutine. • Compares recency for the remaining elements • LEX falls back on specificity and arbitrary. Stylistic
  • 16.
    • ROSIE (D.A. Waterman, 1979) • Multiple data sets and rule sets. • Only one ruleset and one data set can be active at a time. • Eclips (NASA, 1991) PIE (NASA, 1988) • Goal directed. • Each goal has a context. • Subroutine like. • Clips Modules (NASA 1993) • Push/Pop Stack • No Context • External Orchestration • Rule Flow Syntactic
  • 17.
  • 18.
    • Rules anddata are decoupled. • Venus full hybrid C++ language. • Single Root Module. • Guard does not directly invoke Rule.
 Instead it makes it legible for evaluation. • Current consequence finishes, 
 before potential next module is entered. • Module may have 1..n Support. Will 
 continue to evaluate, while it has support. • If support is removed, module continues until it reaches fixed point (then it’s removed). • Is single threaded a fair deterministic policy is used to help with selection,
 which is controlled by the priority of the rule against its peers. • Submitted module is identified by the combination of module name plus the passed arguments. Venus Rule Language
  • 19.
  • 20.
  • 21.
    • ENTRY-BLOCK • C-callableentry block • Can have their own rules • Implicitly activate • May activate one or more rule Rule-Blocks • RULE-BLOCK • Allow for rules to be shared across ENTRY-BLOCKs • May not call other ENTRY-BLOCKs or RULE-BLOCKs. • External Orchestration Rule Works
  • 22.
    • ON-ENTRY: Beforethe match step of the first recognize- act cycle. This can be used for tasks like data initialisation. • ON-EVERY: After the act step of every cycle except the last one. This can be used for tasks like printing out the rule count. • ON-EMPTY: After the select step when the conflict set is empty. This can be used to detect state and return error information. • ON-EXIT: After the act step of the last cycle. This can be used for things like cleanup actions. Rule Works
  • 23.
    Rule Works LifeCycles ON-ENTRY ON-EVERY Match Act Select ON-EMPTY ON-EXIT Call to Entry Block Operating System Caller of Entry Block
  • 24.
    • Neither Venusor RuleWorks made it into industrial or academic mainstream. • Business Rules have simple requirements. • Often spreadsheet driven. • Variations Rule Flow suffices. • Academia is funding driven, interests change over time. Recency and Relevance of Works
  • 25.
  • 26.
    Units package org.mypackage.myunit public classAdultUnit implements RuleUnit { private int adultAge; private DataSource<Person> persons; public AdultUnit( ) { } public AdultUnit( DataSource<Person> persons, int age ) { this.persons = persons; this.age = age; } }
  • 27.
    Units package org.mypackage.myunit public classAdultUnit implements RuleUnit { private int adultAge; private DataSource<Person> persons; public AdultUnit( ) { } public AdultUnit( DataSource<Person> persons, int age ) { this.persons = persons; this.age = age; } } package org.mypackage.myunit unit AdultUnit rule Adult when $p : /persons[age >= adultAge] then System.out.println($p.getName() + " is adult and greater than " + 
 adultAge); end
  • 28.
    Units package org.mypackage.myunit unitAdultUnit rule Adult when $p : /persons[age >= adultAge] then System.out.println($p.getName() + " is adult and greater than " + 
 adultAge); end package org.mypackage.myunit public class AdultUnit implements RuleUnit { private int adultAge; private DataSource<Person> persons; public AdultUnit( ) { } public AdultUnit( DataSource<Person> persons, int age ) { this.persons = persons; this.age = age; } @Override public boolean onStart(RuleUnitInstance instance) { 
 System.out.println(getName() + " started.”); return true; } @Override public boolean onEnd(RuleUnitInstance instance) { return true; } }
  • 29.
  • 30.
  • 31.
  • 32.
    • PENDING: Theunit is instantiated, but has not yet been started. 
 • RUNNING: The unit is evaluating and executing rules. 
 • DORMANT: The unit has either reached a fixed point and has no more work to evaluate, or it has been requested 
 to stop further evaluation. 
 • YIELDED: The current executing unit has yielded (while 
 still having more work to do) to another unit that has 
 earlier scheduling. 
 States
  • 33.
    Unit Life Cycles RUNNINGDORMANTYIELDED start true resume true yield true onSuspend suspend true onResume onStart onEnd onYield onResume PENDING FINISHED RuleUnitInstance Created CANCELLED start false resume true resume false suspend false yeld false resume false resume request resume request suspend request yield request start request ON-ENTRY ON-EVERY Match Act Select ON-EMPTY ON-EXIT Call to Entry Block Operating System Caller of Entry Block
  • 34.
  • 35.
    • Depth firstLIFO. • Where the two guards exist for the same unit, the one that comes earlier in the rule order has priority. 
 • Where the two guards are not from the same unit, but the path of one subsumes the path of the other, the deepest unit has priority. 
 • Where the two guards are not from the same unit and one path does not subsume the other, it will iterate the parent chain until it reaches the unit that is shared by both Fairness
  • 36.
    • Units asgeneric abstractions for runtimes • Execution guards • On every • Inheritance • Alternative orchestrations • Refinements in rule execution • @DataDriven / @Existence Driven • @Incremental(<boolean>) • @Sequential Future Works
  • 37.
  • 38.
    Mark Proctor Distinguished EngineerII Chief Architect - Rules, BPM and Optimisation Red Hat Modernising Production Rule Systems
 Rule Modularity and Execution Control