In Spock AGISystem2, a theory is a named collection of concepts, facts, and verb definitions. Theories create local contexts that can be overlaid, branched, and merged—like Git for knowledge.

The Session-Theory Model

A session is a temporary workspace that stacks theory overlays:

Local Symbols
@declarations from current script
Theory: Physics
Most recently loaded (UseTheory Physics)
Theory: BaseLogic
Earlier loaded theory
Global Symbols
Truth, False, Zero (always available)
Resolution Order (LIFO): When looking up a symbol, Spock searches from top to bottom. Local symbols shadow overlay symbols, which shadow global symbols. The most recent UseTheory takes precedence.

Symbol Resolution

Symbol Lookup: getSymbol("Gravity") Local: {Mass, Force} Physics: {Gravity, Mass} BaseLogic: {Is, Implies} Global: {Truth, False} Not found FOUND! Result Physics.Gravity vector Search stops at first match → Physics theory provides Gravity

Theory Structure

A theory on disk looks like:

.spock/theories/Physics/ ├── theory.spockdsl # DSL statements ├── vectors.bin # Precomputed vectors └── metadata.json # Version info
# theory.spockdsl @Gravity Gravity Identity _ @Mass Mass Identity _ @Force Mass Bind Acceleration @NewtonSecond Force Is MassTimesAcceleration # Define custom verb @ApplyForce verb begin @step1 $subject Add $object @result step1 Normalise _ end

Theory Versioning

Version History Graph v1 BaseLogic v2 Experiment A v3 Experiment B v4 Merged v5 Production Operations: BranchTheory MergeTheory Remember

Theory Verbs

Verb Syntax Effect
UseTheory @load _ UseTheory Physics Load theory as overlay, execute its statements
Remember @save session Remember MyTheory Persist session symbols to theory
BranchTheory @branch Physics BranchTheory experiment Create Physics__experiment from Physics
MergeTheory @merge target MergeTheory source Combine source into target

Merge Strategies

When two theories have the same symbol name, Spock offers geometric merge strategies:

Strategy: target (Default)

Keep the target (base) theory's version. Source is ignored for conflicts.

mergeTheory("Physics", "Experiment", { conflictStrategy: 'target' }); // Physics.Gravity stays as-is, Experiment.Gravity ignored

Strategy: source

Replace with the source (overlay) theory's version.

mergeTheory("Physics", "Experiment", { conflictStrategy: 'source' }); // Physics.Gravity replaced by Experiment.Gravity

Strategy: both

Keep both versions. Source is renamed with _merged suffix.

mergeTheory("Physics", "Experiment", { conflictStrategy: 'both' }); // Physics has both Gravity and Gravity_merged

Strategy: consensus

Geometric merge: The resulting vector is the normalized sum—the "midpoint direction" between both theories.

Target Source Consensus consensus = normalise(target + source)
mergeTheory("Physics", "Experiment", { conflictStrategy: 'consensus' }); // Gravity = normalise(Physics.Gravity + Experiment.Gravity)

Strategy: fail

Throw an error on any conflict. Use when conflicts indicate a problem.

mergeTheory("Physics", "Experiment", { conflictStrategy: 'fail' }); // Throws MergeConflictError if any symbol exists in both

UseTheory with Execution

When you load a theory, its statements can be executed to populate the session:

UseTheory Execution Flow Physics.spockdsl @Gravity ... @Mass ... parse AST [statements] [macros] execute Session.localSymbols Gravity → vector Mass → vector UseTheory parses the theory file and executes statements to create vectors

Remember: Persisting Changes

The Remember verb saves session symbols back to a theory:

# Session work @discovery Force Bind NewParticle @law discovery Is UnifiedTheory # Persist to theory @save session Remember MyPhysics # Now MyPhysics contains discovery and law!

What gets saved:

Child Sessions

Sessions can spawn child sessions with inherited overlays:

Session Hierarchy Parent Session overlays: [Physics, Logic] Child A (scoped) Child B (scoped)

Child sessions:

Why Theory Spaces Matter

Theories enable: