← Back to Catalog

The Colony as Inference

Each ant minimises expected free energy — inspired by Active InferAnts (Friedman et al. 2021).

Layers

Precision Controls

Πindividual 2.00
exploratorytrail-locked
How sharply each ant follows pheromone
Parr et al. (2022) Ch.4
Trail persistence 0.50
volatile trailspersistent memory
Pheromone evaporation = belief decay rate
Stigmergic generative model
Epistemic drive 0.40
exploit onlyexplore widely
Information gain vs pragmatic value
Ch.7 Eq.7.4

Environment

Food sources 3
scarceabundant
Colony size 60
smallswarm

Colony Statistics

Food collected0
Active foragers0
Returning0
Exploring0
Soldiers0
Colony F0.00
Trail entropy0.00
Click any ant to inspect
its generative model
The Colony as Inference
Stigmergy, Markov Blankets & Collective Intelligence

What You Are Seeing

An ant colony where each ant is an active inference agent — it minimises variational free energy through perception (sensing pheromone gradients via its antennae) and action (moving through the environment and depositing pheromones).

The ants do not follow pre-programmed foraging rules. Their coordinated behaviour emerges from each individual minimising its own expected free energy — balancing epistemic value (exploring unknown terrain) against pragmatic value (following established trails toward food).

"The fact that utility and the value of information emerge as two components of expected free energy means we do not need to worry about balancing exploration and exploitation. Both are in service of optimizing the same function." — Parr, Pezzulo & Friston (2022), Active Inference, Ch.7 p.131

Three Levels of Markov Blanket

Level 1 — Individual blanket. Each ant maintains a statistical boundary between its internal states (beliefs about food locations) and the external world (the actual pheromone field). The dashed circle around each ant represents this boundary. Its sensory states are antennae sampling pheromone; its active states are movement and pheromone deposition.

Level 2 — Trail blanket. When multiple ants reinforce the same path, a trail-level Markov blanket emerges — shown as a green envelope around strong pheromone corridors. The trail is a stigmergic generative model: a shared belief structure written into the environment itself.

Level 3 — Colony blanket. The nest, all trails, and all foraging zones form a colony-level boundary. Toggle the colony blanket layer to see this macro-scale agent — a superorganism that maintains homeostasis through collective free energy minimisation.

"We could have multiple Markov blankets, nested within one another (e.g., brains, organisms, communities)." — Parr, Pezzulo & Friston (2022), Active Inference, Ch.6 p.109

Stigmergy as Niche Construction

Pheromone trails are a form of niche construction — the ants modify their environment, and the modified environment then shapes future behaviour. The pheromone field is the colony's generative model, externalised into the world.

The trail persistence slider controls how quickly this shared belief structure decays. Fast evaporation forces continuous re-exploration. Slow evaporation creates rigid, habitual pathways — the colony equivalent of high precision.

Try This

1. Set Πindividual to maximum. Watch each ant lock rigidly onto the nearest trail.

2. Now set epistemic drive to maximum. Ants begin exploring broadly, seeking information rather than reward.

3. Click "Remove a food source" while trails are established. Watch the colony's belief update propagate through pheromone decay.

4. Toggle the colony blanket layer to see the macro-scale boundary emerge.

5. Toggle sensory fields — the heatmap shows the colony's collective perception. Amber regions contain pheromone (information!); teal regions are sensed but empty. Notice how the heatmap is densest along trails — that's where shared sensory niches form.

6. Toggle collaboration network — amber links appear between ants that share the same trail, heading the same direction. This is generalised synchrony: the network shows where group-level Markov blankets are forming in real time.

7. Watch the soldiers (darker, larger ants) patrolling the nest perimeter. They use the same free energy minimisation — but their prior preferences encode "safety" instead of "food."

8. Check the nest webcam (bottom-right). The queen, larvae, food stores — these are the colony's internal states that all external foraging behaviour ultimately serves.

Same Algorithm, Different Priors

The soldiers demonstrate one of Active Inference's most powerful insights: the same inference algorithm produces completely different behaviour when the prior preferences change.

A forager's C-vector encodes "I prefer to observe food at the nest." A soldier's C-vector encodes "I prefer to observe safety at the nest perimeter." Both minimise expected free energy — but the resulting policies are utterly different. One explores the world; the other guards the boundary.

This is how biological role differentiation works under the FEP: not by switching algorithms, but by switching generative models.

The Queen as Deepest Prior

The queen embodies the slowest timescale in the colony's hierarchical generative model. She doesn't forage or patrol — she represents the colony's deepest belief about its own continuity. Her presence in the queen's chamber is the attractor state that all other behaviour serves.

In hierarchical terms: fast legs (milliseconds) → medium trails (minutes) → slow colony strategy (hours) → the queen's reproductive cycle (weeks). Each level contextualises the one below.

"Free-energy minimization in joint agent-environment systems: a niche construction perspective." — Bruineberg, Rietveld, Parr, van Maanen & Friston (2018), J. Theoretical Biology
Core Concepts
The Mathematics Behind the Colony

Expected Free Energy

Each ant selects its movement policy by minimising expected free energy G(π):

G(π) = −Epistemic value − Pragmatic value
Ch.7 Eq.7.4 — the exploration-exploitation decomposition

Epistemic value measures how much information a policy will yield. Pragmatic value measures how likely a policy leads to preferred outcomes.

Precision-Weighted Prediction Error

Precision Π = 1/σ²
High Π → rigid trail-following | Low Π → exploratory wandering

Precision weights prediction errors: high-precision errors drive stronger belief updates. An ant with high precision that encounters unexpected pheromone absence will make a dramatic course correction.

Hierarchical Generative Models

Level 1 (fast): Individual ant movement — step-by-step direction changes.
Level 2 (medium): Trail formation and dissolution — emerges over many ant-trips.
Level 3 (slow): Colony-level foraging strategy — the macro-pattern of which food sources are exploited.

"In hierarchical or deep models, the dynamics at higher levels generally encode things that change more slowly and contextualise things that change faster." — Parr, Pezzulo & Friston (2022), Active Inference, Ch.6 p.112

The Exploration-Exploitation Balance

Under Active Inference, there is no exploration-exploitation dilemma — both drives emerge from the same objective function. The epistemic drive slider modulates the relative weight of information gain.

Sensory Fields — The Colony's Collective Perception

Toggle Sensory fields to see a heatmap of the colony's collective sensory coverage. Each ant contributes a forward-biased sensory radius — the region its antennae can sample. Where multiple ants' fields overlap, the heatmap brightens, showing shared sensory niches.

The colour encodes what the ants sense: amber regions contain pheromone (information flowing inward through the Markov blanket), while teal regions are sensed but empty (no prediction error signal). This directly visualises the Active InferAnts principle that agents have only local sensory access to their immediate surroundings.

ε = o − g(μ)
Prediction error = observation − prediction from generative model

Dense sensory overlap on trails shows why group-level Markov blankets emerge there: multiple agents sharing the same sensory niche become mutually predictive.

"Ants only have sensory access to their immediate surroundings and do not know where the food resource is located on the map." — Friedman, Tschantz, Ramstead, Friston & Constant (2021), Active InferAnts, Fig.1

Collaboration Network — Generalised Synchrony

Toggle Collaboration network to see which ants have become mutually predictive. A link appears when two agents share three properties simultaneously: spatial proximity, co-occupation of the same pheromone trail, and aligned heading direction.

This implements generalised synchrony — when agents share similar generative models and sense each other (here, indirectly via pheromone), their internal states converge. The link strength is the product of these factors, which is equivalent to precision-weighted coupling.

When enough links form, the connected ants constitute a group-level agent with its own emergent Markov blanket — the same mechanism that produces trail-level blankets, operating at the agent-interaction scale.

"If agents adopt the same generative model of communicative behaviour, a simple form of communication emerges through generalised synchrony." — Friston & Frith (2015), Consciousness and Cognition
Glossary
Key terms in accessible language
Active Inference
The framework in which both perception and action serve the same objective: minimising variational free energy. Each ant senses pheromone (perception) and moves/deposits pheromone (action). (Parr et al. 2022, Ch.2)
Variational Free Energy (F)
The quantity Active Inference agents minimise. It bounds surprise from above: F ≥ −ln P(o). An ant on a strong trail with food ahead has low F. An ant lost in unknown terrain has high F. (Parr et al. 2022, Ch.2)
Expected Free Energy (G)
The quantity that evaluates future policies. G decomposes into epistemic value (will I learn?) and pragmatic value (will I get food?). (Parr et al. 2022, Ch.4 & Ch.7)
Markov Blanket
A statistical boundary separating internal from external states. The world can only affect the ant through its sensory states (antennae); the ant can only affect the world through its active states (legs, pheromone glands). (Parr et al. 2022, Ch.3)
Precision (Π)
Inverse variance (1/σ²). High precision = sharp, confident predictions. Low precision = broad, uncertain predictions. In the colony: high Π means rigid trail-following; low Π means free wandering. (Parr et al. 2022, Ch.4)
Stigmergy
Indirect coordination through environmental modification. Ants write pheromone into the world; other ants read it. Under Active Inference, this is niche construction: externalising the generative model into shared structure.
Epistemic Value
How much information a policy provides. Heading into unmapped terrain has high epistemic value — the ant will reduce its uncertainty about hidden states. (Parr et al. 2022, Ch.2 & Ch.7)
Pragmatic Value
How likely a policy leads to preferred outcomes. Following a strong trail toward food has high pragmatic value. (Parr et al. 2022, Ch.2 & Ch.7)
Niche Construction
Organisms modify their environment, and the modified environment shapes future behaviour. Pheromone trails are the active component of free energy minimisation — changing the world to match the model's predictions. (Bruineberg et al. 2018)
Sensory States
Blanket states that mediate the influence of the external world on internal states. For each ant: the chemoreceptors on the antennae that sample pheromone concentration at three points (left, right, forward). The gradient across these samples is the prediction error signal that drives belief updating. Toggle "Sensory fields" to visualise these. (Parr et al. 2022, Ch.3)
Active States
Blanket states that mediate the influence of internal states on the external world. For each ant: leg movements (locomotion) and pheromone gland secretion (trail deposition). Through these states, the ant's beliefs become actions that change the environment. (Parr et al. 2022, Ch.3)
Generalised Synchrony
When two dynamical systems are coupled, their internal states can converge onto a synchronisation manifold. In the colony: ants sharing the same trail and heading the same direction become mutually predictive — each ant's state is informative about the other's. Toggle "Collaboration network" to see this emerge. (Friston & Frith 2015)
Prior Preferences (C-vector)
Beliefs about desired observations, encoded in the generative model. Foragers prefer "food at nest." Soldiers prefer "safety at perimeter." The same free energy minimisation produces completely different behaviour depending on C — this is how biological role differentiation works under Active Inference. (Parr et al. 2022, Ch.7)
Hierarchical Timescales
The colony operates across nested timescales: fast (individual leg steps, milliseconds), medium (trail formation, minutes), slow (colony foraging strategy, hours), and slowest (queen's reproductive cycle, weeks). Higher levels change slowly and contextualise faster dynamics below. The queen is the deepest prior. (Parr et al. 2022, Ch.6)
References
Primary sources & further reading

Core Textbook

Parr, T., Pezzulo, G., & Friston, K. J. (2022). Active Inference: The Free Energy Principle in Mind, Brain, and Behavior. MIT Press.

Active InferAnts

Friedman, D. A., Tschantz, A., Ramstead, M. J. D., Friston, K., & Constant, A. (2021). Active InferAnts: An Active Inference Framework for Ant Colony Behavior. Frontiers in Behavioral Neuroscience, 15, 647732.

Saund, E., & Friedman, D. A. (2023). A single-pheromone model accounts for empirical patterns of ant colony foraging previously modeled using two pheromones. Cognitive Systems Research, 79, 1–18.

Niche Construction & Stigmergy

Bruineberg, J., Rietveld, E., Parr, T., van Maanen, L., & Friston, K. J. (2018). Free-energy minimization in joint agent-environment systems: a niche construction perspective. J. Theoretical Biology, 455, 161–178.

Hierarchical Markov Blankets

Palacios, E. R., Razi, A., Parr, T., Kirchhoff, M. D., & Friston, K. J. (2020). On Markov blankets and hierarchical self-organisation. J. Theoretical Biology, 486, 110089.

Collective Active Inference

Thestrup Waade, P. et al. (2025). As One and Many: Relating Individual and Emergent Group-Level Generative Models in Active Inference. Entropy, 27(2), 143.

Simulation Framework

Developed by Alexander Sabine (Active Inference Institute, Board of Directors). Interactive demonstrations at temporalgrammar.ai.

Contact: Alexander@activeinference.institute

Ant #0
State:Foraging
Epistemic:0.00
Pragmatic:0.00
Free energy:0.00
Food carried:No
Daniel Friedman · Active Inference Institute
Nest Interior
LIVE
Food: 0Eggs: 0Guards: 0