Theory layers let AGISystem2 maintain multiple, potentially contradictory views of the world simultaneously. Each layer can override or extend the knowledge below it. This enables counterfactual reasoning, context switching, and safe experimentation without corrupting base knowledge.

Theory Stack Layer 3: "what-if" Water IS_A Gas (temp=200) Layer 2: "medical" Aspirin TREATS Headache Layer 1: "user session" User preferences, context Layer 0: Base Knowledge Dog IS_A Animal, Water IS_A Liquid ← top (active) Stack Operations THEORY_PUSH name="experiment" THEORY_POP (discard top) SAVE_THEORY / LOAD_THEORY Query Resolution ASK "Water IS_A ?" 1. Check Layer 3 → Water IS_A Gas ✓ 2. (skip lower layers) Result: Gas (from "what-if" layer) Base says Liquid, but Layer 3 overrides

Theory layers stack like transparent overlays. Queries search from top to bottom, returning the first match. Layer 3 overrides the base knowledge that "Water IS_A Liquid" with "Water IS_A Gas" for hypothetical reasoning. Popping Layer 3 restores the original view.

How Layers Work

Each layer contains facts that can add to or override facts in lower layers. When the Reasoner processes a query, it searches layers from top to bottom. The first matching fact wins. If no layer has a match, the query returns unknown.

Layers support three types of changes:

Use Cases

Use CaseHow Layers Help
Counterfactuals Push a layer, add hypothetical facts, reason, then pop to restore reality
User sessions Each user gets a layer with their preferences and context
Domain switching Load a "medical" or "legal" layer with domain-specific knowledge
Safe experimentation Test changes in a layer before committing to base
Versioning Save layers as snapshots, load to restore previous states

Implementation

The TheoryStack and TheoryLayer components in the Knowledge Layer manage this:

OperationDescription
push(name) Create new layer at top of stack
pop() Remove and discard top layer
peek() Get current top layer
save(filename) Persist current stack to disk
load(filename) Restore stack from disk
merge() Flatten top layer into the one below

Sys2DSL Commands

# Push a new layer
THEORY_PUSH name="experiment"

# Add facts to current layer
ASSERT Water IS_A Gas
ASSERT Water TEMPERATURE_AT Celsius200

# Query (will find Gas, not Liquid)
ASK "Water IS_A ?"

# Pop to discard hypothetical
THEORY_POP

# Now Water IS_A Liquid again

Related Documentation