Files
2nd/10_Wiki/Topics/AI_and_ML/Rule-based-Systems.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

6.8 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-rule-based-systems Rule-based Systems 10_Wiki/Topics verified self
Rule-based AI
Expert Systems
Production Systems
none A 0.9 applied
rule-based
expert-systems
symbolic-ai
neuro-symbolic
knowledge
2026-05-10 pending
language framework
Python CLIPS / Drools / experta

Rule-based Systems

매 한 줄

"매 IF condition THEN action 의 deterministic, auditable knowledge encoding". 매 1970s expert systems (MYCIN, DENDRAL, R1/XCON) 의 황금기 → 매 ML winter 후 무대 후퇴 → 매 2024+ neuro-symbolic 부활 (LLM + symbolic constraints, 매 hallucination 통제). 매 finance, healthcare, compliance, fraud 등 매 explainability 가 비협상 의 도메인 의 backbone.

매 핵심

매 Architecture

  • Working Memory: facts (current state).
  • Rule Base: production rules (LHS → RHS).
  • Inference Engine: forward chaining (data-driven) / backward chaining (goal-driven).
  • Conflict resolution: salience, recency, specificity.
  • Rete algorithm: efficient pattern matching (Forgy, 1982).

매 Forms

  • Production rules: CLIPS, Drools, Jess.
  • Decision tables: tabular form, easy SME edit.
  • Decision trees: hierarchical, ML-extractable.
  • Logic programming: Prolog, Datalog, ASP.
  • Business Rule Engines: Camunda DMN, IBM ODM.

매 응용

  1. Insurance underwriting / claims adjudication.
  2. Loan approval, AML/KYC, sanctions screening.
  3. Clinical decision support (drug interactions).
  4. Tax/compliance engines.
  5. Game AI (NPCs, behavior trees as rule variants).

💻 패턴

CLIPS-style rule (experta)

from experta import KnowledgeEngine, Rule, Fact, Field

class Patient(Fact):
    fever = Field(bool, mandatory=True)
    cough = Field(bool, mandatory=True)
    duration_days = Field(int)

class TriageEngine(KnowledgeEngine):
    @Rule(Patient(fever=True, cough=True, duration_days=lambda d: d >= 7))
    def likely_pneumonia(self):
        self.declare(Fact(diagnosis="pneumonia_suspect", urgent=True))

    @Rule(Patient(fever=True, duration_days=lambda d: d < 3))
    def viral(self):
        self.declare(Fact(diagnosis="viral_likely"))

eng = TriageEngine()
eng.reset()
eng.declare(Patient(fever=True, cough=True, duration_days=8))
eng.run()

Drools rule (DRL syntax)

rule "High value claim escalate"
    when
        $c: Claim(amount > 50000, status == "submitted")
        $p: Policy(id == $c.policyId, riskTier == "HIGH")
    then
        $c.setStatus("escalated_review");
        update($c);
        insert(new Alert("manual_review", $c.getId()));
end

DMN decision table (Camunda)

<decision id="discount" name="Customer Discount">
  <decisionTable hitPolicy="UNIQUE">
    <input label="Years"><inputExpression typeRef="number">years</inputExpression></input>
    <input label="Tier"><inputExpression typeRef="string">tier</inputExpression></input>
    <output label="Discount" typeRef="number"/>
    <rule><inputEntry>&lt;1</inputEntry><inputEntry>"BRONZE"</inputEntry><outputEntry>0</outputEntry></rule>
    <rule><inputEntry>[1..5]</inputEntry><inputEntry>"SILVER"</inputEntry><outputEntry>0.05</outputEntry></rule>
    <rule><inputEntry>&gt;5</inputEntry><inputEntry>"GOLD"</inputEntry><outputEntry>0.15</outputEntry></rule>
  </decisionTable>
</decision>

Prolog (backward chaining)

ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).

parent(tom, bob).
parent(bob, alice).
% ?- ancestor(tom, alice).  → true

Neuro-symbolic — LLM proposes, rules verify (2026)

import anthropic, json
from rule_engine import compile_rules, evaluate

client = anthropic.Anthropic()
COMPLIANCE_RULES = compile_rules([
    "transaction.amount < 10000 OR transaction.kyc_verified == True",
    "transaction.country NOT IN sanctions_list",
])

resp = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=512,
    messages=[{"role": "user", "content": f"Extract transaction: {raw_text}"}],
)
tx = json.loads(resp.content[0].text)
violations = evaluate(COMPLIANCE_RULES, tx)
if violations:
    block(tx, reasons=violations)  # rules give auditable why

Forward-chaining engine in plain Python

def forward_chain(rules, facts, max_iter=100):
    facts = set(facts)
    for _ in range(max_iter):
        new = set()
        for premises, conclusion in rules:
            if all(p in facts for p in premises) and conclusion not in facts:
                new.add(conclusion)
        if not new:
            break
        facts |= new
    return facts

rules = [
    ({"has_wings", "lays_eggs"}, "is_bird"),
    ({"is_bird", "swims"}, "is_penguin"),
]
print(forward_chain(rules, {"has_wings", "lays_eggs", "swims"}))
# {'has_wings', 'lays_eggs', 'swims', 'is_bird', 'is_penguin'}

Behavior tree (game AI rule variant)

from py_trees import behaviours, composites, common

root = composites.Selector("Root", memory=False)
attack = composites.Sequence("Attack", memory=True, children=[
    behaviours.Condition("EnemyVisible", "EnemyVisible", common.Status.SUCCESS),
    behaviours.Dummy("FireWeapon"),
])
patrol = behaviours.Dummy("Patrol")
root.add_children([attack, patrol])

매 결정 기준

상황 Approach
Auditable, regulated Rule engine (Drools, DMN)
Pattern recognition ML / DL
Hybrid (extract + decide) LLM + rule verifier (neuro-symbolic)
Few thousand cases, frequent change Decision table
Complex ontology Prolog / Datalog / ASP

기본값: Drools/DMN for business rules, LLM-extract + rule-verify for unstructured input.

🔗 Graph

🤖 LLM 활용

언제: rule extraction from policy docs, NL-to-DRL translation, rule conflict detection, explanation generation. 언제 X: as the rule engine itself in regulated domains — use deterministic engine, let LLM only structure the input.

안티패턴

  • Rule explosion: 5000+ rules without modules → unmaintainable; refactor to decision tables.
  • Conflicting rules silent: no conflict detection → undefined behavior.
  • No version control: rules edited live in production BRMS UI without git.
  • LLM as judge for compliance: hallucination in regulated path; LLM must propose, rules must verify.

🧪 검증 / 중복

  • Verified (Russell & Norvig AIMA, CLIPS docs, Drools manual, OMG DMN spec).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — production rules, Rete, neuro-symbolic 2026