# Multi-Agent Coding Without Merge Chaos: Contract Locks & Adaptive Teams (9 Benchmarks)

> 💡 **AI Labo Benchmark Cluster Synthesis — Experiments `E64, E67, E69, E74, E75, E77, E79, E81, E90` (Multi-Agent Coordination)**
>
> Synthesizing 9 controlled A/B experiments (`N=3` counterbalanced `AB/BA` trials per study, `temperature=0.7`, 3-UID isolation) executed inside zero-NIC Debian Proxmox sandboxes with 90% implicit prefix-cache cost accounting.
> * 🚀 **[Master Benchmark Hub & Pattern Index](https://tappers.hashnode.dev/ai-agent-harness-patterns-benchmark)**
> * 🛡️ **[Anti-Cheating Proxmox & systemd Sandbox Architecture](https://tappers.hashnode.dev/air-gapped-proxmox-systemd-agent-sandbox)**

Teams spin up multi-agent coding swarms expecting linear speedups, only to hit a wall of overwrite collisions, handoff "telephone game" bugs, and `2x–4x` surprise model bills. Yet collapsing everything unconditionally into one context loses the genuine upside of parallel search and cross-model review on release-critical interfaces.

Across **9 isolated Proxmox multi-agent benchmarks (`E64`, `E67`, `E69`, `E74`, `E75`, `E77`, `E79`, `E81`, `E90`)**, we mapped out **when to collapse a team to 1 agent, when to coordinate peers with frozen interface contracts, and exactly what cross-model or external contract gates cost in real cached dollars**.

---

## TL;DR — Key Empirical Findings Across 9 Benchmarks

* **1. Collapse Tightly Coupled Teams (`E90`) or Lock Peer Contracts (`E64`):** Letting Supervisor-Restructured Evolving Agent Teams (`EAT`, `E90`) detect tight module coupling via `<1.5ms` `O(n)` AST graphs and merge a 2-role team down to 1 agent eliminated handoff taxes: calls dropped `10.67 -> 6.00` (`-43.8%`), tokens `-38.3%`, median latency `-31.4%`, and effective cached cost **`-34.5%` (`$0.0280` ➔ `$0.0183`, SD `-88.9%`)**. When work *does* parallelize cleanly (`E64`), Contract-Locked Peer Coordination wiped out **`4.0 -> 0.0` (`-100%`)** file overwrite conflicts, sped execution from `257.3s -> 153.0s` (`-40.6%`), and cut effective spend **`-27.2%` (`$0.0976` ➔ `$0.0710`)**.
* **2. Reuse Proven Workflows Without Re-Planning (`E67`, `E79`):** Skipping per-query LLM workflow planning via LinUCB contextual-bandit reuse (`E79`) dropped planner calls `4 -> 0`, cut latency `-40.8%`, and slashed effective spend **`-37.7%` (`$0.0418` ➔ `$0.0261`)**. Replacing static single-axis harnesses with zero-LLM 3-axis predictive search (`SHIFT`, `E67`) cut tokens `-63.6%` (`74,236 -> 27,040`) and cost **`-20.7%` (`$0.0404` ➔ `$0.0321`)**.
* **3. Know the Exact Price of Cross-Model & External Verification Gates (`E69`, `E74`, `E75`, `E77`, `E81`):** A `Carbon LOW` Markov Reviewer catching subtle post-test bugs on `Flash LOW` output (`E69`) caught real Round-1 boundary defects in `3/4` runs—but spiked cost **`+256.3%` (`3.56x`, `$0.0372` ➔ `$0.1324`)**. Reserve frontier escalation (`E69` Reviewer, `E75` 1-call `Carbon` Architect `+$0.0268`) strictly for high-stakes release gates, while cheap external contract gates (`BOBA` in `E77` at `+$0.0004` / `+0.48s` and `POrchestra` in `E74` at `-92.5%` token SD) give low-cost variance insurance.

| Exp | Harness Contrast (Mode A vs. Mode B, `N=3`) | Hidden Suite | Coordination / Reliability Impact | Effective Cached Cost (A ➔ B) |
| :--- | :--- | :---: | :--- | :---: |
| **`E64`** | Shared Chat vs. Contract-Locked Peers (`VM269`) | `32/32` parity | Overwrites `4.0 -> 0.0`, time `257s -> 153s` (`-40.6%`) | `` `$0.0976` `` ➔ **`` `$0.0710` `` (`-27.2%`)** |
| **`E67`** | Static 1-Axis vs. Zero-LLM 3-Axis `SHIFT` (`VM272`) | `32/32` parity | Total tokens `-63.6%` (`74.2k -> 27.0k`), list `-50.7%` | `` `$0.0404` `` ➔ **`` `$0.0321` `` (`-20.7%`)** |
| **`E69`** | Self-Check vs. `Carbon` Reviewer Gate (`VM274`) | `32/32` final | Caught Round-1 boundary bugs in `3/4` runs; `2.15x` time | `` `$0.0372` `` ➔ `` `$0.1324` `` (`+256.3%` tax) |
| **`E74`** | Static Subagent vs. `POrchestra` Revision (`VM279`) | `31.00/32` tie | Eliminated cold restarts (`1.00 -> 0.00`), SD `-92.5%` | `` `$0.0257` `` ➔ `` `$0.0268` `` (`+4.5%`) |
| **`E75`** | All-`Flash` vs. 1x `Carbon` Arch + `Flash` (`VM280`) | `32/32` parity | Capped frontier call count to `1`, cost SD `-42.9%` | `` `$0.0499` `` ➔ `` `$0.0767` `` (`+$0.0268`) |
| **`E77`** | Self-Test 4-Ticket vs. `BOBA` External Gate (`VM282`) | `32/32` parity | Clean-run insurance overhead just `+0.48s` | `` `$0.0415` `` ➔ `` `$0.0419` `` (`+1.0%`) |
| **`E79`** | Per-Query Planner vs. LinUCB Reuse (`VM284`) | `32/32` parity | Planner calls `4 -> 0`, total calls `-34.5%`, time `-40.8%` | `` `$0.0418` `` ➔ **`` `$0.0261` `` (`-37.7%`)** |
| **`E81`** | 8-Ticket Chain vs. `BOBA` Cross-Mod Gate (`VM286`) | `32/32` parity | Output `-1.6%`, cost SD halved (`$0.0108 -> $0.0054`) | `` `$0.1142` `` ➔ `` `$0.1215` `` (`+6.4%`) |
| **`E90`** | Static 2-Role vs. `EAT` Adaptive Collapse (`VM295`) | `32/32` parity | Calls `10.67 -> 6.00` (`-43.8%`), SD `-88.9%`, `<1.5ms` | `` `$0.0280` `` ➔ **`` `$0.0183` `` (`-34.5%`)** |

---

## 1. Decision Matrix: Collapse, Lock Contracts, or Escalate?

```text
+-------------------------------------------------------------------------+
| Topology & Gate Decision Tree (E64..E90 + E05/E48/E52)                  |
|                                                                         |
|  1. Inspect AST Cross-Module Coupling (<1.5ms static scan, E90)         |
|     |-- High Coupling (shared state / frequent cross-calls)             |
|     |     ==> COLLAPSE to 1 Agent ("EAT", -34.5% cost, -43.8% calls)    |
|     '-- Disjoint / Weakly Coupled Modules                               |
|           ==> Freeze Interface Contract + Exclusive Write Locks (E64)   |
|               (0 overwrite conflicts, -27.2% cost, -40.6% runtime)      |
|                                                                         |
|  2. Verification Tier Selection                                         |
|     |-- Everyday commits -> BOBA deterministic external checks (+1.0%)  |
|     '-- Release / High-risk boundary -> Cross-Model Reviewer (E69 3.5x) |
+-------------------------------------------------------------------------+
```

These 9 experiments close the loop on our earlier multi-agent studies ([`E05`](https://tappers.hashnode.dev/e05-subagent-folding), [`E48`](https://tappers.hashnode.dev/e48-swarm-shared-board-blind-verifier), [`E52`](https://tappers.hashnode.dev/e52-complexity-adaptive-orchestrator-filesystem)):

* **Why Static Multi-Agent Teams Lose (`E90`, `E64`):** Fixed "Architect + Coder" or "Module A + Module B" splits pay heavy handoff serialization costs whenever files share imports or schema changes. In `E90`, collapsing a 2-role team *dynamically when AST coupling is high* saved `-34.5%` effective cached cost at `<1.5ms` routing overhead. When files *are* disjoint (`E64`), replacing free-form chat coordination with frozen type contracts and per-agent write ownership stopped all `4.0` overwrite collisions per run.
* **Stop Paying Frontier & Planner Taxes on Repeat Tasks (`E67`, `E79`, `E75`, `E69`):** Re-planning every ticket (`E79`) or running a frontier `Carbon` reviewer on routine commits (`E69`) dominates your monthly bill. Use zero-LLM predictors/bandits (`E67`, `E79`) for routine routing, cap frontier architecture memos to 1 Turn-0 call (`E75`) only when cross-cutting invariants demand it, and gate cross-model reviewers (`E69`) to pre-release merges.

---

## 2. Drop-In Implementation Recipe: AST Coupling Collapse & Disjoint Contract Lock (`E64` + `E90`)

```python
import ast
from collections import defaultdict
from dataclasses import dataclass
from pathlib import Path


@dataclass(frozen=True)
class TeamPlan:
    topology: str  # "SINGLE_COLLAPSED" [E90] or "CONTRACT_LOCKED_PEERS" [E64]
    owners: dict[str, set[str]]  # worker_id -> exclusive editable paths


def measure_import_coupling(repo_root: Path, target_files: list[str]) -> float:
    """Compute <1.5ms internal import edge density across candidate files [E90]."""
    stems = {Path(f).stem: f for f in target_files}
    edges = 0
    for rel in target_files:
        tree = ast.parse((repo_root / rel).read_text(encoding="utf-8"))
        for node in ast.walk(tree):
            if isinstance(node, ast.ImportFrom) and node.module:
                mod = node.module.split(".")[0]
                if mod in stems and stems[mod] != rel:
                    edges += 1
            elif isinstance(node, ast.Import):
                for alias in node.names:
                    mod = alias.name.split(".")[0]
                    if mod in stems and stems[mod] != rel:
                        edges += 1
    max_edges = max(1, len(target_files) * (len(target_files) - 1))
    return edges / max_edges


def route_team_topology(repo_root: Path, target_files: list[str], coupling_cutoff: float = 0.25) -> TeamPlan:
    """Collapse coupled work to 1 agent [E90], else assign disjoint write locks [E64]."""
    if len(target_files) <= 1 or measure_import_coupling(repo_root, target_files) >= coupling_cutoff:
        return TeamPlan(topology="SINGLE_COLLAPSED", owners={"solo_agent": set(target_files)})

    owners: dict[str, set[str]] = defaultdict(set)
    for idx, rel in enumerate(sorted(target_files)):
        owners[f"peer_{(idx % 2) + 1}"].add(rel)
    return TeamPlan(topology="CONTRACT_LOCKED_PEERS", owners=dict(owners))
```

**Why this dual policy outperforms fixed topologies:**
* **Eliminates unnecessary handoffs (`E90`):** Whenever AST coupling exceeds `0.25`, `route_team_topology` collapses workers into `"solo_agent"`, preserving a single warm KV prefix ([Cluster 1](https://tappers.hashnode.dev/e62-e95-prefix-cache-economics-cluster)) and cutting calls `-43.8%`.
* **Eliminates overwrite conflicts (`E64`):** When modules are cleanly separable, `owners` assigns strictly disjoint file write sets under a frozen interface contract, cutting runtime `-40.6%` with zero merge races.

---

## 3. Threats to Validity & When NOT to Use This

1. **Disjoint-File Assumption vs. Coupled Shared Contracts:** `E64`'s `-27.2%` cost reduction requires that cross-module signatures stabilize early. If requirements frequently alter shared schemas mid-stream, collapsing via `E90` (`SINGLE_COLLAPSED`) avoids parallel peers drifting against an outdated interface contract.
2. **LinUCB Cold-Start Requirements (`E79`):** Contextual-bandit workflow reuse reduced planner calls `4 -> 0` (`-37.7%` cost) after feature representations matched recurring ticket archetypes; on brand-new architectures with zero historical trajectories, an initial Turn-1 design memo (`E75`) prevents multi-turn rework.
3. **Why Integration Testing Matters Next:** Each individual harness guard above behaves cleanly in isolation, yet combining too many active agents, hooks, and summaries can still create cross-layer interference—a phenomenon we measure at the system level across **[Cluster 1: Prefix-Cache Economics](https://tappers.hashnode.dev/e62-e95-prefix-cache-economics-cluster)** and **[Cluster 3: Freshness-Gated Memory](https://tappers.hashnode.dev/e65-e88-freshness-gated-memory-evolution-cluster)**.

<details>
<summary>📋 Experiment Metadata & Reproducibility (E64, E67, E69, E74, E75, E77, E79, E81, E90)</summary>

* **Experiment Cluster:** `E64` (`VM269`), `E67` (`VM272`), `E69` (`VM274`), `E74` (`VM279`), `E75` (`VM280`), `E77` (`VM282`), `E79` (`VM284`), `E81` (`VM286`), `E90` (`VM295`)
* **Protocol:** Benchmark v2.1 (`N=3` counterbalanced `AB/BA` trials per study, `temperature=0.7`)
* **Sandbox:** Zero-NIC Debian Proxmox VMs (`PrivateNetwork=yes`, 3-UID isolation)
* **Models & Pricing:** `gemini-3.8-flash` (`LOW`) for baseline/peer runs; `gemini-4-carbon` (`LOW`) paired with `Flash` in cross-model `E69` and `E75`, evaluated on 90% prefix-cached effective cost (`effective_cached_usd`).

</details>

---

**Discussion:** Where is your team's breaking point between keeping a single context window vs. spawning parallel peer agents with file ownership locks?

<!-- PUBLIC_DATASET_LINKS_START -->
### 📦 Raw Benchmark Telemetry & Interactive Trial Explorer

* 🔍 **[Interactive Trial Explorer (CLUSTER4)](https://tappers-labo.github.io/ai-labo-benchmark-data/#cluster=CLUSTER4)** — Filter all 104 benchmarks and inspect per-trial `effective_cached_usd`, token breakdowns, and hidden-test outcomes.
* 💾 **[Sanitized Open Dataset Repo](https://github.com/tappers-labo/ai-labo-benchmark-data)** — Download `experiments_master.csv/.jsonl`, Block 5 Bill of Design, plus sanitized `usage.json`, `independent-tests.json`, and `actions.json` traces.
* 🎥 **[YouTube Channel (Tappers AI Labo)](https://www.youtube.com/@tappers-labo-en)** — Plain-English Lv.1 video walkthroughs of our isolated AI benchmark lab & key findings.
<!-- PUBLIC_DATASET_LINKS_END -->

### 🔗 Continue Reading the Series
* 🚀 **Master Benchmark Hub:** [AI Agent Harness Patterns Benchmark](https://tappers.hashnode.dev/ai-agent-harness-patterns-benchmark)
* ⚡ **Cluster 1 (`E62`–`E95`):** [The 90% Prefix-Cache Trap: Why Context Pruning Often Raises Agent Costs](https://tappers.hashnode.dev/e62-e95-prefix-cache-economics-cluster)
* 🛡️ **Cluster 2 (`E68`–`E94`):** [Zero-Cost Brownfield Agent Guards: Full-Dir Locks, AST Hooks & Early Stop](https://tappers.hashnode.dev/e68-e94-brownfield-zero-cost-defense-cluster)
* 🧠 **Cluster 3 (`E65`–`E88`):** [When Agent MEMORY.md Goes Stale: Freshness Gates, Skeletons & Evolution](https://tappers.hashnode.dev/e65-e88-freshness-gated-memory-evolution-cluster)
* 🔗 **Foundational Folding Study (`E05`):** [Subagent Folding + Progressive Skill Disclosure](https://tappers.hashnode.dev/e05-subagent-folding)
* 🔗 **Blind Swarm Study (`E48`):** [Swarm Shared Board & Blind Verifier](https://tappers.hashnode.dev/e48-swarm-shared-board-blind-verifier)
* 🔗 **Adaptive Filesystem Study (`E52`):** [Adaptive Routing + Filesystem Bypass](https://tappers.hashnode.dev/e52-complexity-adaptive-orchestrator-filesystem)
