Stigmergic Diffusion Medium
When to Use
- You need agents to coordinate without direct messaging: no queues, no RPC, no shared
mutable state beyond the medium itself. Agents write traces; other agents sense them.
- Your problem maps naturally onto a graph (import dependency graph, task DAG, knowledge
graph, file system, network topology) and agents need to discover high-value nodes by
following concentration signals rather than being assigned work.
- You want emergent load balancing and exploration: resolution traces dampen overcrowded
nodes; urgency amplification surfaces deadline pressure; antibody traces suppress
already-solved sub-problems — all without a scheduler.
NOT for:
- Hard real-time coordination where sub-millisecond synchronization is required (diffusion
physics introduce lag proportional to graph diameter).
- Problems where agents must exchange structured messages with guaranteed delivery — the
medium is a lossy signal field, not a reliable message bus.
- Flat, unstructured data with no natural graph topology; forcing one creates spurious
gradient artifacts.
Core Concepts
Trace (Trace dataclass): A single stigmergic deposit with fields trace_type,
intensity, depositor, created_at, optional deadline/urgency_alpha/urgency_beta
for temporal pressure, and optional confidence_stake/proposition for belief-market
extension. The fundamental write unit.
TraceType (enum): Five distinct "goods" in the wide-market framework —
PHEROMONE (work-in-progress / distress), BELIEF (probabilistic claims),
PREFERENCE (Active Inference priors, desired future states), ANTIBODY
(known-bad / already-solved patterns, triggers negative selection), RESOLUTION
(anti-inflammatory: suppresses agent activity at a node after a problem is closed).
Scalar diffusion is an attention heuristic: At each synchronous tick, one scalar
field is updated with p' = (I - αhL)p, where L=D-A is the unweighted,
undirected combinatorial Laplacian. It can rank neighborhoods for inspection;
it cannot assign an owner, route a request, prove coverage, prevent duplicate work,
or prove a resolution. Those require a separate authority and evidence protocol.
Pheromone gradient (gradient(node_id)): The discrete exterior derivative of the
pheromone 0-cochain restricted to the star of a vertex:
{neighbor: p_neighbor - p_self}. Positive values attract; agents climb the gradient
toward higher concentrations. This is the only mechanism agents need to follow crowd
wisdom without knowing who deposited what.
Resolution damping: sense() returns effective pheromone =
raw_pheromone * max(0, 1 - resolution_damping * resolution_level). Depositing a
RESOLUTION trace at a node makes it appear less attractive to new agents — the
anti-inflammatory that prevents pile-on after a problem is solved.
Implementation Pattern
# 1. Construct the medium (all randomness seeded for determinism)
medium = Medium(
decay_rate=0.01, # γ: exponential decay per tick
diffusion_rate=0.005, # α: Laplacian diffusion coefficient
resolution_damping=0.5, # how strongly RESOLUTION traces suppress activity
rng_seed=42,
)
# 2. Build topology (or import from repo_parser.py for code-review domains)
medium.add_node("auth/login.py")
medium.add_node("utils/crypto.py")
medium.add_edge("auth/login.py", "utils/crypto.py")
# 3. Agent deposits a trace after visiting a node
medium.deposit(
node_id="auth/login.py",
agent_id="agent-0",
intensity=1.0,
trace_type=TraceType.PHEROMONE,
deadline=medium.time + 10, # optional temporal urgency
)
# 4. Agent senses neighborhood before choosing next move
signals = medium.sense("auth/login.py", radius=1)
# → {"auth/login.py": 0.9, "utils/crypto.py": 0.1} (resolution-damped)
grad = medium.gradient("auth/login.py")
# → {"utils/crypto.py": -0.8} # climb toward higher concentration
# 5. Advance physics each simulation step
diagnostics = medium.tick(dt=1.0)
# Returns: {time, total_pheromone, distress_nodes, max_pheromone}
# tick() handles: decay → diffusion (stability-clamped) → urgency boost → prune epsilon
# 6. After solving a node, deposit RESOLUTION to prevent pile-on
medium.deposit("auth/login.py", "agent-0", intensity=2.0,
trace_type=TraceType.RESOLUTION)
# 7. Antibody negative selection: skip if already solved
if not medium.check_antibody(pattern_signature=hash_of_problem):
do_work()
medium.deposit(node_id, agent_id, 1.0, TraceType.ANTIBODY,
pattern_signature=hash_of_problem)
# 8. Observability
medium.hotspots(n=5) # top-5 nodes by pheromone
medium.snapshot() # full state dict for visualization
medium.global_uncertainty_map() # {node: uncertainty_proxy} for Active Inference seeding
medium.preference_field() # {node: total PREFERENCE intensity} for implicit coordination
medium.freeze_baseline() # capture normal operating state
medium.deviation_from_baseline(node_id) # novelty signal above baseline
Physics tick order (from Medium.tick()):
- Exponential decay:
p *= exp(-γ dt)
- Resolution decay (faster):
r *= exp(-2γ dt)
- Laplacian diffusion with clamped
dt_eff
- Urgency amplification for traces with
deadline set
- Prune values below
1e-8
Numerical contract. For the stated update, spectral stability is
αh λ_max(L) ≤ 2; since λ_max(L) ≤ 2d_max, h ≤ 1/(αd_max) is a sufficient
condition when d_max>0. The same bound makes the update a non-negative convex
combination at each node. 0.9/(αd_max) is merely a safety factor for that exact
operator, not proof for weighted, directed, normalized, asynchronous, saturated, or
concurrently-mutated graphs. Treat d_max=0 as a no-diffusion case. Decay and deposits
change total mass; only pure synchronous undirected diffusion conserves it. Record
whether a deposit occurs before or after a tick, and never infer delivery from a value.
Worked operational trace
Use a dependency graph auth -> crypto -> audit, with a disconnected billing audit
obligation. An investigator deposits 1.0 at auth; another deposits 0.5 at
crypto. The next tick can make crypto look worth inspecting. A tested repair writes
an authoritative receipt outside the field; only then may a RESOLUTION trace reduce
attention. The disconnected billing obligation receives no influence, and two workers
can still inspect crypto. This is the intended limitation: field values suggest where to
look, while an owner/evidence ledger decides whether work happened.
Failure diagnosis
- A raw
gradient() bypasses resolution damping in the imported implementation. Either
navigate from the same damped values returned by sense() or state explicitly that
resolution is ignored; do not call it pile-on prevention.
ANTIBODY is a signature lookup, not a negative concentration. A matching signature
can suppress a duplicate candidate only if its scope and freshness are appropriate.
- Do not reuse the unweighted bound for weighted/directed edges. Define the operator and
establish its own positivity/stability bound first.
Key References
Hansen & Ghrist (2021). "Opinion Dynamics on Discourse Sheaves." SIAM Journal on
Applied Mathematics. Proves convergence of sheaf Laplacian dynamics; the scalar
pheromone diffusion here is the constant-sheaf special case.
Do not treat recent sheaf-diffusion preprints as validation of this scalar medium.
Its explicit tick order, graph model, and concurrency semantics require direct local
specification and testing.
Friston (2010). "The free-energy principle: a unified brain theory?" Nature Reviews
Neuroscience 11, 127–138. Foundation for Active Inference agents that consume the
medium's global_uncertainty_map() and preference_field() outputs.
Howkins (2026). soma/medium.py — SOMA Week 1 reference implementation. All function
signatures, parameter defaults, and physics are canonical from this file.
/Users/erichowens/coding/soma/soma/medium.py
1---2name: stigmergic-diffusion-medium3description: >4 A graph-based shared blackboard where agents coordinate indirectly by depositing5 typed pheromone traces (PHEROMONE, BELIEF, PREFERENCE, ANTIBODY, RESOLUTION) onto6 graph nodes, then sensing and following concentration gradients. Traces spread via7 Euler-stable Laplacian diffusion and decay exponentially, creating a self-organizing8 lossy attention field. It can help agents inspect a graph neighborhood; it does not9 replace reliable messages, assignment, delivery, or completion evidence. NOT for10 reliable messaging, assignment, coverage, or completion certification.11license: Apache-2.012allowed-tools: Read,Write,Edit,Glob,Grep13metadata:14 version: 0.1.015 author: soma-jury_rig-graft16 tags: [stigmergy, multi-agent, coordination, diffusion, graph, blackboard, active-inference, pheromone]17 pairs-with: [active-inference-agent, belief-market-tateonnement, immune-selection-pressure]18 provenance:19 kind: imported20 source: https://skillmd.com/skills/curiositech/stigmergic-diffusion-medium21 upstream: workgroup-ai / jury_rig skill library (rehomed 2026-07-04)22---2324# Stigmergic Diffusion Medium2526## When to Use2728- You need agents to coordinate without direct messaging: no queues, no RPC, no shared29 mutable state beyond the medium itself. Agents write traces; other agents sense them.30- Your problem maps naturally onto a graph (import dependency graph, task DAG, knowledge31 graph, file system, network topology) and agents need to discover high-value nodes by32 following concentration signals rather than being assigned work.33- You want emergent load balancing and exploration: resolution traces dampen overcrowded34 nodes; urgency amplification surfaces deadline pressure; antibody traces suppress35 already-solved sub-problems — all without a scheduler.3637NOT for:38- Hard real-time coordination where sub-millisecond synchronization is required (diffusion39 physics introduce lag proportional to graph diameter).40- Problems where agents must exchange structured messages with guaranteed delivery — the41 medium is a lossy signal field, not a reliable message bus.42- Flat, unstructured data with no natural graph topology; forcing one creates spurious43 gradient artifacts.444546## Core Concepts4748**Trace** (`Trace` dataclass): A single stigmergic deposit with fields `trace_type`,49`intensity`, `depositor`, `created_at`, optional `deadline`/`urgency_alpha`/`urgency_beta`50for temporal pressure, and optional `confidence_stake`/`proposition` for belief-market51extension. The fundamental write unit.5253**TraceType** (enum): Five distinct "goods" in the wide-market framework —54`PHEROMONE` (work-in-progress / distress), `BELIEF` (probabilistic claims),55`PREFERENCE` (Active Inference priors, desired future states), `ANTIBODY`56(known-bad / already-solved patterns, triggers negative selection), `RESOLUTION`57(anti-inflammatory: suppresses agent activity at a node after a problem is closed).5859**Scalar diffusion is an attention heuristic**: At each synchronous tick, one scalar60field is updated with `p' = (I - αhL)p`, where `L=D-A` is the *unweighted,61undirected* combinatorial Laplacian. It can rank neighborhoods for inspection;62it cannot assign an owner, route a request, prove coverage, prevent duplicate work,63or prove a resolution. Those require a separate authority and evidence protocol.6465**Pheromone gradient** (`gradient(node_id)`): The discrete exterior derivative of the66pheromone 0-cochain restricted to the star of a vertex:67`{neighbor: p_neighbor - p_self}`. Positive values attract; agents climb the gradient68toward higher concentrations. This is the only mechanism agents need to follow crowd69wisdom without knowing who deposited what.7071**Resolution damping**: `sense()` returns *effective* pheromone =72`raw_pheromone * max(0, 1 - resolution_damping * resolution_level)`. Depositing a73`RESOLUTION` trace at a node makes it appear less attractive to new agents — the74anti-inflammatory that prevents pile-on after a problem is solved.757677## Implementation Pattern7879```python80# 1. Construct the medium (all randomness seeded for determinism)81medium = Medium(82 decay_rate=0.01, # γ: exponential decay per tick83 diffusion_rate=0.005, # α: Laplacian diffusion coefficient84 resolution_damping=0.5, # how strongly RESOLUTION traces suppress activity85 rng_seed=42,86)8788# 2. Build topology (or import from repo_parser.py for code-review domains)89medium.add_node("auth/login.py")90medium.add_node("utils/crypto.py")91medium.add_edge("auth/login.py", "utils/crypto.py")9293# 3. Agent deposits a trace after visiting a node94medium.deposit(95 node_id="auth/login.py",96 agent_id="agent-0",97 intensity=1.0,98 trace_type=TraceType.PHEROMONE,99 deadline=medium.time + 10, # optional temporal urgency100)101102# 4. Agent senses neighborhood before choosing next move103signals = medium.sense("auth/login.py", radius=1)104# → {"auth/login.py": 0.9, "utils/crypto.py": 0.1} (resolution-damped)105106grad = medium.gradient("auth/login.py")107# → {"utils/crypto.py": -0.8} # climb toward higher concentration108109# 5. Advance physics each simulation step110diagnostics = medium.tick(dt=1.0)111# Returns: {time, total_pheromone, distress_nodes, max_pheromone}112# tick() handles: decay → diffusion (stability-clamped) → urgency boost → prune epsilon113114# 6. After solving a node, deposit RESOLUTION to prevent pile-on115medium.deposit("auth/login.py", "agent-0", intensity=2.0,116 trace_type=TraceType.RESOLUTION)117118# 7. Antibody negative selection: skip if already solved119if not medium.check_antibody(pattern_signature=hash_of_problem):120 do_work()121 medium.deposit(node_id, agent_id, 1.0, TraceType.ANTIBODY,122 pattern_signature=hash_of_problem)123124# 8. Observability125medium.hotspots(n=5) # top-5 nodes by pheromone126medium.snapshot() # full state dict for visualization127medium.global_uncertainty_map() # {node: uncertainty_proxy} for Active Inference seeding128medium.preference_field() # {node: total PREFERENCE intensity} for implicit coordination129medium.freeze_baseline() # capture normal operating state130medium.deviation_from_baseline(node_id) # novelty signal above baseline131```132133**Physics tick order** (from `Medium.tick()`):1341. Exponential decay: `p *= exp(-γ dt)`1352. Resolution decay (faster): `r *= exp(-2γ dt)`1363. Laplacian diffusion with clamped `dt_eff`1374. Urgency amplification for traces with `deadline` set1385. Prune values below `1e-8`139140**Numerical contract.** For the stated update, spectral stability is141`αh λ_max(L) ≤ 2`; since `λ_max(L) ≤ 2d_max`, `h ≤ 1/(αd_max)` is a sufficient142condition when `d_max>0`. The same bound makes the update a non-negative convex143combination at each node. `0.9/(αd_max)` is merely a safety factor for that exact144operator, not proof for weighted, directed, normalized, asynchronous, saturated, or145concurrently-mutated graphs. Treat `d_max=0` as a no-diffusion case. Decay and deposits146change total mass; only pure synchronous undirected diffusion conserves it. Record147whether a deposit occurs before or after a tick, and never infer delivery from a value.148149## Worked operational trace150151Use a dependency graph `auth -> crypto -> audit`, with a disconnected `billing` audit152obligation. An investigator deposits `1.0` at `auth`; another deposits `0.5` at153`crypto`. The next tick can make `crypto` look worth inspecting. A tested repair writes154an authoritative receipt outside the field; only then may a `RESOLUTION` trace reduce155attention. The disconnected billing obligation receives no influence, and two workers156can still inspect crypto. This is the intended limitation: field values suggest where to157look, while an owner/evidence ledger decides whether work happened.158159## Failure diagnosis160161- A raw `gradient()` bypasses resolution damping in the imported implementation. Either162 navigate from the same damped values returned by `sense()` or state explicitly that163 resolution is ignored; do not call it pile-on prevention.164- `ANTIBODY` is a signature lookup, not a negative concentration. A matching signature165 can suppress a duplicate candidate only if its scope and freshness are appropriate.166- Do not reuse the unweighted bound for weighted/directed edges. Define the operator and167 establish its own positivity/stability bound first.168169170## Key References171172- Hansen & Ghrist (2021). "Opinion Dynamics on Discourse Sheaves." *SIAM Journal on173 Applied Mathematics.* Proves convergence of sheaf Laplacian dynamics; the scalar174 pheromone diffusion here is the constant-sheaf special case.175176- Do not treat recent sheaf-diffusion preprints as validation of this scalar medium.177 Its explicit tick order, graph model, and concurrency semantics require direct local178 specification and testing.179180- Friston (2010). "The free-energy principle: a unified brain theory?" *Nature Reviews181 Neuroscience* 11, 127–138. Foundation for Active Inference agents that consume the182 medium's `global_uncertainty_map()` and `preference_field()` outputs.183184- Howkins (2026). `soma/medium.py` — SOMA Week 1 reference implementation. All function185 signatures, parameter defaults, and physics are canonical from this file.186 `/Users/erichowens/coding/soma/soma/medium.py`