Counterfactual reasoning in AGISystem2 uses theory layers to explore "what if" scenarios. A temporary layer holds hypothetical facts that override base knowledge. After reasoning in this altered world, the layer is discarded and reality is restored.
Counterfactual workflow: Push a hypothetical layer, add overriding facts, reason in the altered world, then pop to restore reality. The base knowledge is never modified—only temporarily shadowed by the hypothetical layer.
Counterfactuals use the TheoryStack mechanism:
The key insight is that the base knowledge is never modified. The hypothetical layer simply intercepts queries and returns overriding answers.
| Use Case | Example |
|---|---|
| What-if analysis | "If water were a gas at room temperature, could fish survive?" |
| Policy simulation | "If the tax rate were 20%, what would be the budget impact?" |
| Debugging scenarios | "If this config value were true, would the bug still occur?" |
| Alternative history | "If Rome had not fallen, what technologies might exist?" |
| Safe experimentation | Test knowledge changes before committing them |
For simple counterfactuals, use the CF command:
# Shorthand (push, assert, query, pop in one command) CF "Water IS_A Gas?" | Water TEMPERATURE_AT Celsius200 # Temporarily assumes Water IS_A Gas and queries implications # Expanded equivalent THEORY_PUSH name="cf_temp" ASSERT Water IS_A Gas ASSERT Water TEMPERATURE_AT Celsius200 ASK "Can fish survive in Water?" THEORY_POP
Multiple layers can be stacked for nested hypotheticals:
THEORY_PUSH name="layer1" ASSERT A IS_A B THEORY_PUSH name="layer2" ASSERT A IS_A C # Overrides layer1's A IS_A B ASK "A IS_A ?" # → C THEORY_POP ASK "A IS_A ?" # → B (layer1 still active) THEORY_POP ASK "A IS_A ?" # → (original value)