# Dynamic Sub-Agent Tuples Cut Worker Context 76%—Watch the Turn-Cap Trap (N=3)

> 💡 **AI Labo Benchmark Series — Experiment `E55` (AOrchestra Dynamic Sub-Agent Synthesis)**
>
> 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)**

Most multi-agent setups hardcode static expert roles (`billing_expert`, `math_expert`, `integrator`) and hand every sub-agent the entire repo, all tool schemas, and the most expensive frontier model.

AOrchestra (`arXiv:2602.03786`) replaces static roles with on-demand **4-tuple sub-agent synthesis `⟨I, C, T, M⟩`** (Instruction, minimal Context, attenuated Tools/write-paths, and task-matched Model). We benchmarked this head-to-head on a 14-file FinOps chargeback & carbon-SLO engine (`N=3`), uncovering huge worker savings—and a sneaky **turn-cap spillback trap**.

---

## TL;DR — Key Empirical Findings

* **1. `32.00 ± 0.00 / 32` Parity Even With `28.6%` Flash Delegation:** Both `Baseline (3 Static Experts on Carbon MEDIUM)` and `Candidate (Dynamic ⟨I, C, T, M⟩ Synthesis)` scored **`32/32` (`100.0%`)** across all 3 trials (`12` leaf + `20` cross-contract invariants) with `0` decoy reads and `0` scope violations. Candidate's Lead (`gemini-4-carbon MEDIUM`) autonomously split the repo into `4` scoped tuples, routing leaf modules (`tag_normalizer`, `usage_meter`) to `gemini-3.8-flash` (`-83.6%` leaf worker cost in T1), math/placement to `4-carbon:LOW`, and ledger integration to `4-carbon:MEDIUM`.
* **2. `-76.40%` Worker Context & `-30.95%` Worker Cost:** Scoping `⟨I, C, T, M⟩` shrank average worker context from `34,707.0` to **`8,189.3` chars (`-76.40%`)**, exposed tools from `5.00` to **`3.17` (`-36.67%`)**, worker tokens by **`-47.03%`**, and worker effective cost from `` `$0.3134` `` to **`` `$0.2164` `` (`-30.95%`)**—cutting total tokens `-24.09%` and list-price cost **`-15.96%`** (`` `$0.8699` `` ➔ `` `$0.7311` ``).
* **3. Turn-Cap Spillback & 90% Caching Softened Net Savings to `-4.99%`:** Net effective cached cost dipped from `` `$0.5813 ± $0.0465` `` to `` `$0.5523 ± $0.0772` `` (`-4.99%`; Trial 1 won **`-24.3%`**, while Trial 3 lost `+9.7%`). Why? Under `MAX_WORKER_TURNS=4`, the 2-file `3.8-flash` leaf worker spent 2 turns diagnosing starter bugs and timed out, forcing the expensive `4-carbon:MEDIUM` Lead to patch `usage_meter.py` (`lead_effective_cached_usd` `+25.30%`), while 90% prefix caching cushioned Baseline's `160,334` repeated tokens.

| Metric (`N=3` Trials, `Mean ± SD`) | Baseline: `Static Experts` (`3` Roles) | Candidate: `Dynamic ⟨I, C, T, M⟩` (`4` Tuples) | Delta / Effect |
| :--- | :---: | :---: | :--- |
| **Hidden Grading Suite (`32` Cases)** | **`32.00 ± 0.00`** (`100.0%`) | **`32.00 ± 0.00`** (`100.0%`) | `100%` parity (`12` leaf + `20` cross) |
| **Avg Worker Context Size** | `34,707.0 ± 721.8` chars | **`8,189.3 ± 91.3` chars** | **`-76.40%` (`4.24x` smaller)** |
| **Avg Tools Exposed per Worker** | `5.00 ± 0.00` tools | **`3.17 ± 0.14` tools** | **`-36.67%` capability attenuation** |
| **Flash Model Share (`worker calls`)** | `0.00%` (`0/17` calls) | **`28.57%` (`4/14` calls)** | Leaf tasks auto-routed to Flash |
| **Worker Tokens / Effective Cost** | `170,375.3` / `` `$0.3134` `` | **`90,248.3` / `` `$0.2164` ``** | **`-47.03%` tokens / `-30.95%` cost** |
| **Lead Effective Cost (`4-carbon MED`)** | **`` `$0.2680 ± $0.0476` ``** | `` `$0.3358 ± $0.0437` `` | `+25.30%` (synthesis + T2/3 patch) |
| **Total Tokens (`total_tokens`)** | `302,000.3 ± 12,926.2` | **`229,254.7 ± 19,934.9`** | **`-24.09%` (`-72,745.7` tokens)** |
| **Standalone Incremental Time** | **`507.76s`** (raw `698.66s`) | `577.29s` (raw `901.12s`) | `+13.69%` standalone |
| **Effective Cached Cost (90% OFF)** | `` `$0.5813 ± $0.0465` `` | **`` `$0.5523 ± $0.0772` ``** | **`-$0.0290` (`-4.99%`, T1 `-24.3%`)** |
| **List-Price Upper Bound (No Cache)** | `` `$0.8699 ± $0.0497` `` | **`` `$0.7311 ± $0.0924` ``** | **`-15.96%` (`` `-$0.1388` ``)** |
| **Output Cap Hits (`MAX_TOKENS`)** | `0 / 3` | `0 / 3` | Zero output truncation |

---

## 1. Experiment Design & Architecture

```text
+-----------------------------------------------------------------------+
| Proxmox VM259 (0 NICs, 3-UID Grading, N=3 AB/BA, temp=0.7)            |
| Task: 14-File FinOps Chargeback & Carbon-SLO Engine (32 Unseen Tests) |
|                                                                       |
| Baseline (Static Expert Roles, Carbon MEDIUM Lead & Workers):         |
|   3 Fixed Roles -> full 14 files (34,707c) + all 5 tools + 5 writes   |
|   --> 17.0 calls | 302,000 tok | $0.5813 eff. ($0.8699 list) | 32/32  |
|                                                                       |
| Candidate (Dynamic Tuple Synthesis ⟨I, C, T, M⟩, Carbon MEDIUM Lead): |
|   Lead synthesizes 4 specialized tuples (8,189c avg, 3.17 tools):     |
|     - tags+meter (3.8-flash:LOW/MED) -> ri & placer (4-carbon:LOW)    |
|     - chargeback_ledger (4-carbon:MEDIUM)                             |
|   --> 19.3 calls | 229,255 tok | $0.5523 eff. ($0.7311 list) | 32/32  |
+-----------------------------------------------------------------------+
```

Notice the anti-strawman fairness: `Baseline`'s Lead (`gemini-4-carbon MEDIUM`) was allowed to attach custom `focus_note` instructions to its 3 experts and run a symmetric 12-check suite (`run_full_suite`).

---

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

Keep `⟨I, C, T, M⟩` savings from leaking back to the expensive Lead by enforcing **1 editable file per lightweight Flash worker** (or scaling turn budget with file count):

```python
MODEL_TIERS = {
    "leaf": ("gemini-3.8-flash", "LOW"),
    "math": ("gemini-4-carbon", "LOW"),
    "integration": ("gemini-4-carbon", "MEDIUM"),
}


def synthesize_tuple_subagents(tasks: list[dict], max_turns_per_worker: int = 4) -> list[dict]:
    """Builds ⟨I, C, T, M⟩ tuples with 1-file-per-Flash guard against turn-cap spillback."""
    tuples = []
    for t in tasks:
        model, thinking = MODEL_TIERS[t["tier"]]
        writable = list(t["writable_files"])
        # Prevent Flash workers from burning half their turns on multi-file diagnostics
        if model == "gemini-3.8-flash" and len(writable) > 1 and max_turns_per_worker <= 4:
            for single_file in writable:
                tuples.append({
                    "id": f"{t['id']}_{single_file.removesuffix('.py')}",
                    "I": f"Patch {single_file} directly; skip pre-edit baseline checks.",
                    "C": t["shared_contracts"] + [single_file],
                    "T": {"tools": ["write_module", "run_module_check"], "rw": [single_file]},
                    "M": {"model": model, "thinking": thinking},
                })
            continue
        tuples.append({
            "id": t["id"],
            "I": t["instruction"],
            "C": t["shared_contracts"] + writable,
            "T": {"tools": ["inspect_files", "write_module", "run_module_check"], "rw": writable},
            "M": {"model": model, "thinking": thinking},
        })
    return tuples
```

* **Why this works:** In Trial 1—when no worker timed out—`Candidate` beat `Baseline` by **`-24.3%`** (`` `$0.4771` `` vs. `` `$0.6305` ``). Matching `writable_files` to `1` file per Flash worker prevents diagnostic turn exhaustion and Lead proxy rewrites.

---

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

1. **`MAX_WORKER_TURNS=4` Spillback & Elapsed Timer Note:** Assigning `2` files to one `3.8-flash` worker under a `4`-turn cap caused Trials 2 & 3 timeouts (`+25.3%` Lead cost). Also, `run_guest.py` initialized `started_monotonic` before both arms ran, inflating raw `elapsed_seconds` for the second mode—so the table reports exact **standalone incremental times** (`507.76s` vs. `577.29s`) isolated via `AB`/`BA` counterbalancing.
2. **Explicit-Spec Ceiling Effect (`32/32` Tie):** Both modes scored `32/32` on a 5-editable-file FinOps task with complete `TICKET.md` specs; accuracy gains from stripping noisy files (`-76.4%`) need testing in noisier, ambiguous monorepos.
3. **When Baseline/Single-Loop Is Enough:** In long-cache sessions with `<= 3` simple files, a folded single loop (`E05`) or `direct_single_agent` (`E52`) avoids Lead synthesis overhead altogether.

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

* **Experiment ID:** `E55` (`C051` / AOrchestra `arXiv:2602.03786` / Benchmark v2.1)
* **Run ID:** `e55-20261119-vm259-01` (`N=3` trials: `AB` ➔ `BA` ➔ `AB`, `temperature=0.7`)
* **Sandbox Environment:** Proxmox Isolated VM `VM259` (0 NICs, `PrivateNetwork=yes`, 3-UID isolation: `labexp55` / `labrunner55` / `labjudge55`)
* **Models:** Lead `models/gemini-4-carbon` (`MEDIUM`); Baseline workers `4-carbon` (`MEDIUM`); Candidate workers dynamically routed across `{3.8-flash:LOW/MED, 4-carbon:LOW/MED}`
* **Cost Accounting:** Google 90% implicit prefix-cache discount (`effective_cached_micro_usd`) as primary metric; list-price upper bound reported alongside.

</details>

---

**Discussion:** When delegating subtasks to cheaper models like `Flash`, how do you keep them from running out of turns and spilling half-finished edits back onto the parent orchestrator?

### 🔗 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 (`E54`):** [Runtime Code Contracts Cut Agent Thinking by 14.4% at 32/32 Parity (N=3)](https://tappers.hashnode.dev/e54-design-by-contract-runtime)
* ➡️ **Next Post (`E56`):** [Shepherd Branch Swarms Beat Public-Test Overfitting: 100% vs. 93.3% (N=3)](https://tappers.hashnode.dev/e56-shepherd-search-branch-swarm)
* 🧭 **Related Adaptive Routing (`E52`):** [Cutting Multi-Agent Costs by 54.6%: Adaptive Routing + Filesystem Bypass (N=3)](https://tappers.hashnode.dev/e52-complexity-adaptive-orchestrator-filesystem)
