# Cutting Multi-Agent Costs by 54.6%: Adaptive Routing + Filesystem Bypass (N=3)

> 💡 **AI Labo Benchmark Series — Experiment `E52` (Complexity-Adaptive Orchestrator & Filesystem Bypass)**
>
> Part of our controlled benchmark series testing AI coding agent harnesses inside network-isolated Proxmox VMs (`N=3` counterbalanced `AB`/`BA`/`AB` trials, `temperature=0.7`, 3-UID grading, 90% prefix-cache cost accounting).
> * 🚀 **[Master Benchmark Hub & All Pattern Rankings](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)**

Anthropic's multi-agent engineering post highlighted two costly traps: spawning subagents for simple tasks explodes token spend by `4x`–`15x`, and funneling worker outputs back through a Lead agent's chat creates a massive "Re-Emission Tax" where the parent re-reads and re-writes every line of code.

We decomposed and benchmarked both fixes together—**Complexity-Adaptive Topology Routing (`Effort Scaling`)** plus **Filesystem Artifact Bypass**—against a fixed `Hub-and-Spoke Chat Relay` on `models/gemini-4-carbon` (`thinkingLevel="MEDIUM"`, `N=3`).

---

## TL;DR — Key Empirical Findings

* **1. `-54.61%` Effective Cost (`2.20x` Cheaper) at `32.0 / 32` Parity:** Both `Baseline (Fixed Hub-and-Spoke Chat)` and `Candidate (Adaptive + Filesystem Bypass)` scored **`32.0 ± 0.0 / 32` (`100.0%`)** on first verification with `0` decoy reads. `Candidate` cut effective cached cost from `` `$1.3526 ± $0.0887` `` to `` `$0.6140 ± $0.0359` `` (**`-54.61%`**, cost SD **`-59.5%`**), LLM calls from `21.67` to **`15.00 ± 0.00`**, and Lead chat relay text by **`-98.45%`** (`69,804.3` ➔ `1,084.7` chars).
* **2. Effort Scaling (Ticket 1 — Simple 1-File Fix, `8` Tests):** `Candidate` chose `direct_single_agent` (`0` workers) in `3/3` trials, cutting Ticket 1 cost by **`-82.91%`** (`` `$0.3301` `` ➔ `` `$0.0564` ``). `Baseline`'s fixed 3-worker swarm cost **`5.85x` more** for the exact same `8/8` score.
* **3. Filesystem Artifact Bypass (Ticket 2 — Complex 4-Module Pipeline, `24` Tests):** Even when **both** modes spawned `3` workers (`11.0` calls each), letting workers write `owned_files` directly to disk and return `1,084.7`-char JSON pointers instead of `49,455.0`-char chat code dumps cut Ticket 2 cost by **`-45.46%`** (`` `$1.0225` `` ➔ `` `$0.5577` ``), Lead re-emission output by **`-54.43%`**, and Lead final context by **`-33.20%`**.

| Metric (`N=3` Trials, `Mean ± SD`) | Baseline: `Hub-and-Spoke Chat Relay` | Candidate: `Adaptive + FS Bypass` | Delta / Effect |
| :--- | :---: | :---: | :--- |
| **Hidden Grading Suite (`32` Cases)** | **`32.0 ± 0.0`** (`100.0%`) | **`32.0 ± 0.0`** (`100.0%`) | `100%` parity (`T1:8 + T2:24`) |
| **Total LLM Calls (`model_calls`)** | `21.67 ± 0.58` (`[21–22]`) | **`15.00 ± 0.00`** (`[15–15]`) | **`-30.77%`** (`-6.67` calls) |
| **Subagents Spawned (`T1 + T2`)** | `6.0 ± 0.0` (`3 + 3`) | **`3.0 ± 0.0` (`0 + 3`)** | **`-50.0%`** (direct on T1 `3/3`) |
| **Lead Chat Aggregation Chars** | `69,804.3 ± 3,144.3` | **`1,084.7 ± 0.6`** | **`-98.45%`** (`64.4x` smaller) |
| **Thinking Tokens (`thoughts`)** | `59,700.0 ± 6,181.5` | **`22,131.3 ± 2,375.7`** | **`-62.93%`** (`-37,568.7`) |
| **Visible Output (`candidates`)** | `32,067.7 ± 973.6` | **`14,572.0 ± 300.1`** | **`-54.56%`** (Re-Emission Tax removed) |
| **Total Tokens (`total_tokens`)** | `279,635.7 ± 14,330.0` | **`184,758.0 ± 17,612.1`** | **`-33.93%`** (`-94,877.7`) |
| **Elapsed Time (Serial Harness)** | `1,308.96s ± 368.33s` | **`1,302.44s ± 670.39s`** | `-0.50%` (`3.20x` faster in T2 `BA`) |
| **Effective Cached Cost (90% OFF)** | `` `$1.3526 ± $0.0887` `` | **`` `$0.6140 ± $0.0359` ``** | **`-54.61%` (`2.20x` cheaper**, SD `-59.5%`) |
| **List-Price Upper Bound (No Cache)** | `` `$1.4769 ± $0.0999` `` | **`` `$0.7365 ± $0.0561` ``** | **`-50.13%`** (`` `-$0.7404` ``) |
| **Output Cap Hits (`capped_termination`)** | `0 / 3` | `0 / 3` | Zero truncation |

---

## 1. Experiment Design & Architecture

```text
+-----------------------------------------------------------------------+
| Proxmox VM256 (0 NICs, gemini-4-carbon MEDIUM, temp=0.7, N=3 AB/BA)   |
| Tasks: Ticket 1 (1-file hotfix, 8 tests) + Ticket 2 (4-mod, 24 tests) |
|                                                                       |
| Baseline (Fixed Hub-and-Spoke Chat Relay):                            |
|   T1 & T2 Lead -> dispatch_fixed_workers(3) [read-only]               |
|     -> return_findings_to_lead (69,804 chars of code & prose)         |
|     -> Lead re-emits all 5 .py files -> $1.3526 eff. | 279,636 tok    |
|                                                                       |
| Candidate (Complexity-Adaptive + Filesystem Artifact Bypass):         |
|   T1 (1 file) -> select_execution_topology("direct_single_agent", 0)  |
|     -> Lead edits directly (4 calls, $0.0564 eff., -82.91% vs Base)   |
|   T2 (4 files)-> select_execution_topology("parallel_fs_workers", 3)  |
|     -> Workers write owned .py + return 1,085-char JSON pointers      |
|     -> Lead writes manifest_synthesizer.py only ($0.5577 eff. -45.5%) |
+-----------------------------------------------------------------------+
```

Because Ticket 2 spawned `3` workers in both arms, comparing `T2` isolated the **Filesystem Artifact Bypass** effect (`Lead` output `-54.43%`, `Lead` final prompt `-33.20%`) separately from `T1`'s **Effort Scaling** gain (`-82.91%`).

---

## 2. Drop-In Implementation Recipe: `AdaptiveTopologyOrchestrator`

Gate subagent spawning on file/boundary count and force workers to persist artifacts directly to disk while returning a `<400`-char pointer summary:

```python
import hashlib
import json
from pathlib import Path


def select_execution_topology(editable_files: list[str], coupled_boundaries: int) -> dict:
    """Prevents 5.85x multi-agent overspend on single-file or trivial tasks."""
    if len(editable_files) <= 1 or coupled_boundaries <= 1:
        return {"mode": "direct_single_agent", "workers": 0}
    return {"mode": "parallel_filesystem_workers", "workers": min(len(editable_files), 3)}


def write_filesystem_artifact(
    workdir: Path,
    worker_id: str,
    owned_files: set[str],
    rel_path: str,
    code: str,
    exported_symbols: list[str],
) -> str:
    """Writes worker code directly to disk and returns a compact pointer JSON."""
    if rel_path not in owned_files:
        raise PermissionError(f"OWNERSHIP_VIOLATION: {worker_id} cannot write {rel_path}")
    target = workdir / rel_path
    target.write_text(code, encoding="utf-8")
    digest = hashlib.sha256(code.encode("utf-8")).hexdigest()[:12]
    pointer = {
        "worker": worker_id,
        "path": rel_path,
        "sha256": digest,
        "symbols": exported_symbols,
        "status": "WRITTEN_TO_DISK",
    }
    (workdir / "artifacts" / f"{worker_id}.json").write_text(json.dumps(pointer))
    return json.dumps(pointer)
```

* **Why this works:** Disjoint `owned_files` eliminates merge conflicts, and returning a ~`150`-byte pointer JSON removes the Re-Emission Tax where the Lead model regenerates worker code inside its own completion.

---

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

1. **Ticket 2 Worker Initial-Seed Confounder:** In Ticket 2, `Baseline` workers were read-only (`inspect_files` + chat return, `7.0` worker calls), whereas `Candidate` workers received their `owned_files` starter seeds in initial context (`6.0` worker calls), contributing part of the worker-side savings (`` `$0.6939` `` ➔ `` `$0.3291` ``). However, `T1`'s `-82.91%` routing win and `T2`'s `-97.81%` Lead chat reduction / `-54.43%` Lead re-emission drop are pure structural effects.
2. **Ceiling Effect & Serial Relay Harness:** `gemini-4-carbon (MEDIUM)` maintained `32/32` even under `73,435` relayed chars; smaller models or `10+`-worker tasks may see accuracy drops as well. Workers also ran serially through one relay (`1,302s` vs. `1,309s`); async HTTP dispatch would shorten Candidate wall-clock latency further.
3. **When to Adjust Ownership:** If a task requires tightly coupled cross-file refactoring where two modules share volatile interfaces, folded single-loop execution (`E05`) or an upfront architectural memo (`E18`) beats split workers.

<details>
<summary>📋 Experiment Metadata & Reproducibility</summary>

* **Experiment ID:** `E52` (`C048` / Anthropic Multi-Agent Research System / Benchmark v2.1)
* **Run ID:** `e52-20261118-vm256-01` (`N=3` trials: `AB` ➔ `BA` ➔ `AB`, `temperature=0.7`)
* **Sandbox Environment:** Proxmox Isolated VM `VM256` (0 NICs, `PrivateNetwork=yes`, 3-UID isolation: `labexp52` / `labrunner52` / `labjudge52`)
* **Model & Thinking Level:** `models/gemini-4-carbon` (`thinkingLevel="MEDIUM"`)
* **Cost Accounting:** Google 90% implicit prefix-cache discount (`effective_cached_micro_usd`) as primary metric; list-price upper bound reported alongside.

</details>

---

**Discussion:** Do your subagents still paste full file contents back into the coordinator's chat history, or have you switched to disk writes plus compact pointer JSONs?

### 🔗 Continue Reading the Series
* 🚀 **Master Benchmark Hub:** [AI Agent Harness Patterns Benchmark](https://tappers.hashnode.dev/ai-agent-harness-patterns-benchmark)
* 🛡️ **Methodology & Sandbox Architecture:** [How to Benchmark AI Agents Without Eval Cheating or API Key Leaks: Designing a Proxmox & systemd Sandbox](https://tappers.hashnode.dev/air-gapped-proxmox-systemd-agent-sandbox)
* ⬅️ **Previous Post (`E51`):** [Zero Secret Exposure and -3% Cost: Capability Attenuation + Blind Proxy (N=3)](https://tappers.hashnode.dev/e51-capability-attenuated-security-harness)
* ➡️ **Next Post (`E53`):** [Test Your Agent Harness: Self-Evals Cut Guardrail Build Cost by 36.5% (N=3)](https://tappers.hashnode.dev/e53-executable-harness-self-testing)
* 🪆 **Related Subagent Folding (`E05`):** [Why Role-Based Subagents Slow Down Coding Agents: Subagent Folding + Progressive Skill Disclosure (2.66x Faster)](https://tappers.hashnode.dev/e05-subagent-folding)
