phago_core/primitives/emerge.rs
1//! EMERGE — Quorum Sensing + Phase Transitions
2//!
3//! Individual bacteria are weak. But when population density exceeds a
4//! threshold, they detect each other's autoinducer molecules and undergo
5//! coordinated behavioral changes: biofilm formation, bioluminescence,
6//! virulence factor production.
7//!
8//! This is a **phase transition** — a qualitative change triggered by a
9//! quantitative threshold. The collective exhibits behaviors that no
10//! individual possesses.
11
12use crate::substrate::Substrate;
13use crate::types::*;
14
15/// Detect quorum and activate collective behaviors.
16///
17/// Emergence is discrete, not gradual. Below the threshold, agents
18/// operate individually. Above it, collective behaviors unlock that
19/// no single agent can perform.
20pub trait Emerge {
21 /// The collective behavior that emerges at quorum.
22 type EmergentBehavior;
23
24 /// Measure signal density in the local region.
25 ///
26 /// This is the agent counting autoinducer concentration —
27 /// how many nearby agents are emitting presence signals.
28 fn signal_density(&self, substrate: &dyn Substrate) -> f64;
29
30 /// The threshold for phase transition.
31 ///
32 /// This can be fixed or adaptive (shifting based on environment).
33 fn quorum_threshold(&self) -> f64;
34
35 /// Whether quorum has been reached.
36 fn quorum_reached(&self, substrate: &dyn Substrate) -> bool {
37 self.signal_density(substrate) >= self.quorum_threshold()
38 }
39
40 /// The emergent behavior that activates at quorum.
41 ///
42 /// Returns `None` if quorum is not reached. The behavior itself
43 /// is a collective computation — it requires contributions from
44 /// multiple agents and cannot be performed by any single one.
45 fn emergent_behavior(&self) -> Option<Self::EmergentBehavior>;
46
47 /// Contribute to a collective computation.
48 ///
49 /// Each agent contributes its local perspective. The collective
50 /// synthesizes these into something none of them could produce alone.
51 fn contribute(&self) -> Contribution;
52}