# agentbridge_mas `agentbridge_mas` (`agntcy-agentbridge-mas`) is the coordination runtime for AgentBridge multi-agent systems. It owns group semantics: epochs, event discipline, finalization, and the engines that apply a class update. The site page is [AgentBridge MAS](../../docs/content/mas.md). The two group phases are [ASSEMBLY and CONVERGE](../../docs/content/assembly-converge.md). This crate does not own transport, identity, sandboxing, or the `agentbridge` CLI. ## Role ```text agentbridge coordinate │ ▼ MasRuntime │ ▼ CoordinationEngine development | preference | cascade | resource │ ▼ MessagingAdapter / TaskAdapter / ToolAdapter ``` A `ToolAdapter` may call MCP or an Agent Skill. Engines see `SemanticEvent` values only. ## Event loop ```rust pub trait CoordinationEngine: Send + Sync { fn pattern(&self) -> PatternKind; fn apply(&mut self, event: SemanticEvent) -> EventOutcome; fn counters(&self) -> RuntimeCounters; } ``` `MasRuntime` forwards `apply()` and records every `AppliedTransition` on `history()`. Outcomes are `Applied`, `Deferred`, `Finalized`, or `Rejected` (duplicate, stale epoch, wrong pattern or payload, unknown participant). ## ASSEMBLY and CONVERGE - **ASSEMBLY** — `AssemblySession` infers a class from `CLASS ` or keywords, and each agent gives an `UPDATE ` over the class's named quantities. An unimplemented token is `PatternKind::Unmapped`. - **CONVERGE** — each agent applies its own rule and announces the result; the engine applies the announced values after a full epoch. `update_rule` scores a rule against the class reference by probing. The protocol is not limited to numbers. `DevelopmentEngine` is CONVERGE for a code artifact. The paper examples use `ConvergeController`. `Unmapped` must not start a solver. Do not claim an LLM proved a theorem (`proves_llm_mas` is not a runtime flag). ## Engines | Engine | Announced | Finalization | |--------|-----------|--------------| | `DevelopmentEngine` | `ExternalBytes` artifact | Quorum of `ToolResult` endorsements | | `PreferenceEngine` | next `z_i` (`ScalarProposal`) | Applies the announced values | | `CascadeEngine` | next order | Places the announced orders, advances the chain | | `ResourceEngine` | next extraction | Takes the announced extractions, advances price and stock | `PreferenceEngine` is not a median vote. Its reference rule, which a team's rule is scored against, is ```text z_i ← (c_i + 2β Σ_{j∈N_i} z_j) / (1 + 2β d_i) ``` The unique fixed point is `z* = (I + 2β L)⁻¹ c`. `agentbridge coordinate --pattern development` (default) uses `DevelopmentEngine`. `--pattern preference|cascade|resource` uses the scalar CONVERGE driver. `--assembly` infers the class first. To add a class: implement `CoordinationEngine` under `src/engines/`, export it from `engines/mod.rs`, and add a `PatternKind` variant. ```rust let config = DevelopmentEngineConfig::new( ["claude", "copilot", "codex"].map(AgentId::from), /* quorum */ 2, /* max_rounds */ 10, ); let mut runtime = MasRuntime::new(DevelopmentEngine::new(Epoch(0), config)); runtime.apply(dev_event("claude", b"fn parse(input: &str) -> Ast { ... }")); runtime.apply(dev_event("copilot", b"fn parse(s: &str) -> Result { ... }")); runtime.apply(dev_event("codex", b"fn parse(s: &str) -> Option { ... }")); runtime.apply(vote_event("claude", "copilot")); runtime.apply(vote_event("copilot", "copilot")); runtime.apply(vote_event("codex", "claude")); // The last ballot closes the round, and copilot has quorum (2) // → EventOutcome::Finalized(summary) let winner = runtime.engine().selected_artifact(Epoch(0)).unwrap(); ``` ## Adapters Traits in `adapters.rs`: `MessagingAdapter`, `TaskAdapter`, `ToolAdapter`. `agentbridge_mas::experiments` provides `RecordingMessagingAdapter`, `RecordingTaskAdapter`, and `LiveA2ATaskAdapter` (A2A over SLIMRPC or official unicast, DID-proof envelopes, `AUTH_REQUIRED` handling). AgentBridge supplies `CliToolAdapter`. `LiveA2ATaskAdapter` uses TLS 1.3 and SLIM client certificates from `SLIM_TLS_CERT` / `SLIM_TLS_KEY` / `SLIM_TLS_CA` or `$AGENTBRIDGE_TMP_DIR/shadi-slim-mtls/`, or a bearer token from `SLIM_AUTH_TOKEN_FILE`. Verify those files (`openssl x509 -text -noout -in `): not expired; RSA ≥ 2048 or P-256+; SHA-2 signatures; self-signed only for lab. Do not hardcode certificates or keys. ## Tests ```bash cargo test -p agntcy-agentbridge-mas --lib ```