SOMA

The Mathematics of Self-Organizing Multi-Agent Architecture

Interactive lessons for the mathematically inclined. We assume familiarity with linear algebra, basic real analysis, and ODEs. We'll reactivate your intuitions, not insult them.

Lesson 1The Graph Laplacian — Diffusion's Discrete Twin

You know $\nabla^2 f$. On a regular grid, a scaled sum of neighbor differences approximates it. The combinatorial graph Laplacian $L=D-A$ has the opposite sign: it is the negative neighbor-difference operator, corresponding to $-\nabla^2$ up to grid scaling.

Given a graph $G = (V, E)$, define:

$$L = D - A$$ The graph Laplacian. Positive semi-definite. Null space = connected components.

The quadratic form tells you everything: $x^T L x = \sum_{(i,j) \in E} (x_i - x_j)^2$. This measures total variation across edges. Smooth signals (constant on components) have zero energy. Spiky signals (large differences across edges) have high energy.

Play with it

Click any node to deposit heat. Watch it diffuse along edges via $dp/dt = -\alpha L p$. The sidebar shows the Laplacian matrix and the current state vector in real time.

INTERACTIVE: GRAPH LAPLACIAN & DIFFUSION click nodes to deposit heat
Laplacian L
State vector p
Diagnostics
Key insight: The Laplacian action $(Lp)_v = \deg(v) \cdot p_v - \sum_{u \sim v} p_u$ is the discrete analog of $-\nabla^2$. The neighbor-difference operator used by the heat equation is its negative: $-Lp$, the discrete analog of $\nabla^2 p$. Heat flows from high to low, proportional to the difference. The eigenvectors of $L$ are the graph's "Fourier modes" — the Fiedler vector (smallest nonzero eigenvalue) captures the fundamental cut.

Notice what happens: total heat is conserved under pure diffusion (no decay). The constant eigenmode $\lambda_0 = 0$ is never damped. Heat spreads but never disappears. This changes in Lesson 2.

Lesson 2The SOMA Equation — Diffusion, Decay, Stability

SOMA's Medium evolves by three forces:

$$\frac{dp}{dt} = -\alpha L p - \gamma p + S(t)$$ diffusion (spreading) + decay (fading) + source (injection)

The decay term $-\gamma p$ breaks conservation. Without persistent sources, all traces fade to zero — this is biologically necessary. Pheromone trails that lasted forever would make the system rigid. The source term $S(t)$ represents agents depositing traces as they work.

Equilibrium

At steady state, $dp/dt = 0$:

$$p^* = (\alpha L + \gamma I)^{-1} S$$ Unique equilibrium. The matrix is positive definite when gamma > 0.

The equilibrium exists and is unique because $\alpha L + \gamma I$ has all eigenvalues $\alpha \lambda_i + \gamma > 0$. The system is globally attracting.

Numerical stability

The full equation has Jacobian $J = -(\alpha L + \gamma I)$, with eigenvalues $-(\alpha \lambda_i + \gamma)$. A forward Euler step for the full equation is stable when $|1 - \Delta t(\alpha\lambda_i + \gamma)| < 1$ for every mode. This demo uses a split update: it injects sources using the requested $\Delta t$, applies exact exponential decay over $\Delta t_{\rm eff}$, then applies forward Euler diffusion over $\Delta t_{\rm eff}$. Its clamp bounds diffusion with $\Delta t_{\rm eff}=\min(\Delta t,0.9/(\alpha d_{\max}))$; that bound omits $\gamma$ because decay is handled separately.

For forward Euler on the full equation, Gershgorin gives $\lambda_{\max}(L) \leq 2d_{\max}$, so a sufficient bound is:

$$\Delta t < \frac{2}{\alpha \cdot 2 d_{\max} + \gamma} \approx \frac{1}{\alpha \cdot d_{\max}}$$ Sufficient full-equation Euler bound. The approximation requires $\gamma \ll \alpha d_{\max}$; the demo clamps diffusion separately.

Play with it

Click to deposit. Adjust $\alpha$, $\gamma$, and $\Delta t$. The "destabilize" button cranks $\Delta t$ past the stability bound — watch what happens. Toggle the stability clamp to see SOMA's fix.

INTERACTIVE: DIFFUSION + DECAY + STABILITY stable
State vector p
Sources S
click to add...
Try it: Click "destabilize" to crank $\Delta t$ past the CFL bound. With the clamp off, the demo uses the requested interval for Euler diffusion, which can oscillate and produce negative values. Turn the clamp on to bound the diffusion step. Decay still uses an exponential update, and source injection still uses the requested interval.

Lesson 3Stigmergic Agents — Coordination Without Communication

Termites build cathedrals without architects. The mechanism: indirect coordination through environmental modification. An agent modifies the shared medium; other agents respond to the modification, not to each other.

In SOMA, each agent computes the pheromone gradient at its current position:

$$\partial p(v) = \{ p(u) - p(v) : u \sim v \}$$ The discrete exterior derivative of the pheromone 0-cochain, restricted to star(v).

Movement follows an $\varepsilon$-greedy policy: with probability $\varepsilon$, move randomly (explore). Otherwise, select a neighbor proportional to $\max(0, \partial p(v, u))$ (exploit).

A graph-dependent baseline

On a fixed graph, random-walk discovery time depends on topology, starting positions, and bug locations. It is a hitting-time and coverage problem, not the ordinary coupon collector: that formula assumes independent, equally likely draws from the full set. We therefore compare the two policies on the same seeded graphs, bug locations, and starting positions, and report empirical outcomes rather than a universal closed-form expectation.

Play with it

Run Random Walk (no pheromone, no gradient) and Stigmergic (agents deposit pheromone on discovery, follow gradients) side by side. The counter shows steps to find all bugs. The benchmark uses 30 fixed paired seeds and a 5,000-step cap per policy. It reports completion counts, median steps among completions, and paired wins, losses, and ties. These results describe this simulation setup, not a general performance guarantee.

RANDOM WALK (no pheromone)
found: 0/4    steps: 0
running
STIGMERGIC (gradient-following)
found: 0/4    steps: 0
running
Paired benchmark: No results yet. Run the fixed-seed benchmark to compare 30 matched trials (5,000-step cap per policy).
What this policy tests: Stigmergic agents deposit pheromone on a discovered bug and follow positive pheromone gradients. Since pheromone originates at discovered bugs, this can draw agents back toward known locations; it does not inherently guide them to undiscovered bugs. The paired benchmark measures whether the complete policy helps under these parameters. The shared medium coordinates agents in this model; they do not send direct messages.

Lesson 4Resolution & Homeostasis — The Anti-Inflammatory

Here's a problem: stigmergic agents pile on. Once a bug is found, its pheromone attracts more agents. They arrive, confirm the finding, deposit more pheromone, attracting even more agents. In immunology, this is a cytokine storm — an inflammatory cascade that damages the host.

SOMA's fix: resolution traces. After discovery, agents deposit an anti-inflammatory signal:

$$p_{\text{eff}}(v) = p(v) \cdot \max\!\big(0,\; 1 - \delta \cdot r(v)\big)$$ Effective pheromone is dampened by resolution. delta = 0.5 means resolution=2 zeroes out the signal.

Agents sense $p_{\text{eff}}$, not raw $p$. Resolved areas become invisible even if they still have pheromone. Agents move on to unexplored territory.

Play with it

Toggle resolution on and off. Without it, agents cluster at the first discovery. With it, they spread out and find everything.

INTERACTIVE: RESOLUTION DAMPING resolution ON
Discovery log
The biological parallel is exact. In the immune system, anti-inflammatory cytokines (IL-10, TGF-beta) are released after pathogen clearance. They suppress further immune cell recruitment to prevent tissue damage. Without them, the immune response itself becomes the disease. SOMA's resolution traces are computational IL-10.

Lesson 5From Scalars to Sheaves — and the Road Ahead

Everything so far used a constant sheaf: each node carries a scalar (pheromone level), and the restriction maps are the identity. The full SOMA framework assigns each node a typed stalk:

$$\mathcal{F}(\sigma) = P(\sigma) \oplus B(\sigma) \oplus \Pi(\sigma) \oplus A(\sigma)$$ Pheromone + Belief + Preference + Antibody. Four channels, one sheaf.

The sheaf Laplacian $L_{\mathcal{F}}$ generalizes the graph Laplacian. Where $L$ compares scalar values across edges, $L_{\mathcal{F}}$ compares stalks through restriction maps and measures disagreement via the coboundary operator. The spectral gap of $L_{\mathcal{F}}$ governs convergence speed — Hansen & Ghrist (2021) proved exponential convergence to global sections.

Think of it this way: the constant sheaf says "every node speaks the same language." The full sheaf says "every node has its own dialect, and the restriction maps are the translation dictionaries." Sheaf cohomology $H^1(K, \mathcal{F})$ describes cohomology classes of cocycles modulo coboundaries. A nonzero $H^1$ signals a global obstruction for the chosen sheaf, but does not diagnose a current SOMA state, establish local agreement, or locate a structural inconsistency. Turning it into a debugging tool would require a defined mapping from observed agent data to cochains and a validated way to interpret or localize the resulting obstruction.

The Roadmap

What follows is the mathematical territory ahead. Each item becomes a future interactive lesson.

Week 2 — PROTOTYPE

Belief-Weighted Exploration: An Active-Inference Heuristic

The current prototype maintains a Beta belief for each node and labels this score Expected Free Energy. It combines expected bug probability, resolution damping, belief variance, and inverse-visit novelty, then samples neighboring actions with a softmax over the negative score:

$$G_{\rm proxy}(n) = w_{\rm prag}\big[-\mathbb{E}[p_n]\,\max(0,1-\delta r_n)\big] + w_{\rm epist}\big[-\operatorname{Var}(p_n)/(1+v_n)\big]$$

This is a hand-designed proxy. Variance times novelty is not expected information gain: the implementation does not predict possible observations and average their posterior uncertainty reduction. It also does not minimize variational free energy $F$ to infer a posterior or derive an action score from expected future free energy.

For comparison, variational free energy for approximate posterior $q$ is:

$$F = \mathbb{E}_q[\log q(s) - \log p(o, s)] = D_{\text{KL}}(q(s) \| p(s|o)) - \log p(o)$$

Minimizing $F$ with respect to $q$ is an inference objective. Expected free energy scores candidate policies using predicted future outcomes; formulations can include both pragmatic and epistemic terms. These quantities are related in active-inference methods, but they are distinct and neither is computed by this prototype's node score.

Interactive lesson concept: Compare the current variance-and-novelty heuristic with $\varepsilon$-greedy exploration. A later model could test whether predicted information gain improves coverage of isolated nodes, with its assumptions and results shown explicitly.

Week 3 — PLANNED

Belief Markets: Truth via Price Discovery

Agents deposit belief traces with confidence stakes. Conflicting beliefs trigger a tatonnement auction:

$$p_g^{t+1} = p_g^t \cdot (1 + \eta \cdot z_g(p^t)), \quad z_g = \text{excess demand for good } g$$

Cole & Fleischer (2008) proved polynomial convergence for weak gross substitutes. Market prices converge to collective credence — a 10% accuracy gain over single-shot baselines (Gho et al., 2025).

Interactive lesson concept: A market simulator. Multiple agents submit beliefs with stakes. Watch the tatonnement iterate. See prices converge. Compare market consensus to individual agent accuracy.

Week 4 — PLANNED

Immune Selection: Evolving the Agent Population

Successful agents clone with mutation. Failed agents are culled. The population evolves toward problem-solving fitness:

$$\text{fitness}(a) = \frac{\text{successes} + 1}{\text{total} + 2} \quad \text{(Laplace smoothing)}$$

This is CLONALG (de Castro, 2000) applied to agent configurations. Affinity maturation = accelerated mutation near solutions. Negative selection = kill agents that react to "self" (the system's normal operating state). Memory cells = dormant solution templates.

Interactive lesson concept: A population dynamics visualization. Watch agent parameter distributions shift over generations. Successful exploration rates and deposit intensities propagate. Failed configurations die out. See the population converge.

The Full Sheaf

Cohomological Diagnostics

The full SOMA Medium is a cellular sheaf $(K, \mathcal{F}, L_{\mathcal{F}})$ where $K$ is a dynamic simplicial complex and $\mathcal{F}$ assigns typed stalks. The master equation becomes:

$$\frac{dp}{dt} = -\alpha\, L_{\mathcal{F}}\, p - \gamma\, p + S(t) + u(t)$$

Where $L_{\mathcal{F}}$ is the sheaf Laplacian and $u(t)$ is urgency amplification from deadline-aware traces. The urgency function is exponential: $u(t) = \alpha \cdot e^{\beta(t - t_{\text{deadline}})}$.

Sheaf cohomology can describe global obstructions to gluing compatible local data. A nonzero $H^1$ means a nontrivial cohomology class exists; it does not by itself identify particular edges or prove that agents locally agree while globally contradicting one another. A diagnostic would need a specified sheaf, observed cochains, and a method that maps a computed obstruction back to interpretable evidence.

Interactive lesson concept: A graph where each node has a vector-valued stalk (not just a scalar). Restriction maps enforce consistency across edges. Visualize the cohomology: highlight edges where local agreement breaks down. Watch the sheaf Laplacian drive the system toward consistency.

The vision: Week 1 gives you ants. Week 2 gives them curiosity. Week 3 teaches them to trade. Week 4 lets them evolve. The result is not an agent framework — it's a computational ecosystem. The Medium is not a data structure. It's a habitat.