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 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.
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 Case | How 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 |
The TheoryStack and TheoryLayer components in the Knowledge Layer manage this:
| Operation | Description |
|---|---|
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 |
# 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