Learning How Much to Collaborate: Difficulty-Aware Topology Selection for Multi-Agent Code Generation
Organizations: School of Computer Science, The University of Sydney, Sydney, NSW 2006, Australia
Abstract
Multi-agent systems for code generation are deployed with a single communication topology, chosen once for every problem. This is the wrong granularity. Evaluating five topologies on 614 problems from APPS, HumanEval+ and LiveCodeBench, we find that the advantage of hierarchical collaboration over a single agent grows from 2.4 points of pass@1 on the easiest third of problems to 21.1 points on the hardest third, while its token cost stays about ten times higher. We propose the Difficulty-Aware Topology Selector (DATS), which predicts each topology's probability of solving a problem and selects the one maximising predicted success minus cost. Its predictor is a graph network that treats the five topologies as nodes of a connectivity order rather than independent labels, worth 1.7 points over a flat multi-label head. Because the cost penalty is a single scalar recalibrable without retraining, routers compare at equal spend: under this budget-matched protocol six cost-aware methods span 21.6 percentage points, and two baselines leading DATS fall behind once calibrated to it. Fixed at 40% of the always-hierarchical cost, DATS reaches 77.7% pass@1 against 73.6% (always-hierarchical) and 74.3% (strongest learned competitor), all eleven pairwise McNemar comparisons surviving Holm-Bonferroni correction. The 4.1-point gain holds across four backbones spanning fourteen points of capability, and replacing the 39 interpretable features with a graph network or a pretrained encoder shifts accuracy by at most 1.3 points, never significantly. A cross-domain study on 400 mathematical reasoning problems reproduces the effect, the gap widening from 2.5 to 20.9 points.
Figures & tables
| Suite | Difficulty | Words | Tests | |
|---|---|---|---|---|
| APPS-Introductory | 100 | 0.25 | 178 | 12.4 |
| APPS-Interview | 100 | 0.50 | 296 | 18.7 |
| APPS-Competition | 100 | 0.75 | 412 | 21.3 |
| HumanEval+ | 164 | 0.20 | 67 | 24.6 |
| LiveCodeBench | 150 | 0.59 | 341 | 16.2 |
| Total | 614 | 0.44 | 232 | 19.0 |
| Topology | Calls | Tokens | Ratio | USD | Lat. (s) |
|---|---|---|---|---|---|
| Single | 1 | 2,632 | 1.00 | 0.095 | 8.4 |
| Chain | 3 | 13,425 | 5.10 | 0.483 | 26.1 |
| Star | 4 | 14,083 | 5.35 | 0.507 | 21.7 |
| FullMesh | 6 | 23,004 | 8.74 | 0.828 | 44.3 |
| HRM | 5–8 | 26,189 | 9.95 | 0.943 | 38.6 |
| Dats | 2.6 | 10,476 | 3.98 | 0.377 | 17.1 |
| Suite | Single | Chain | Star | FullMesh | HRM |
|---|---|---|---|---|---|
| APPS-Introductory | 88.0 | 91.0 | 89.0 | 90.0 | 92.0 |
| APPS-Interview | 57.0 | 66.0 | 63.0 | 67.0 | 71.0 |
| APPS-Competition | 19.0 | 32.0 | 27.0 | 35.0 | 41.0 |
| HumanEval+ | 90.9 | 93.3 | 92.1 | 94.5 | 95.1 |
| LiveCodeBench | 46.0 | 56.0 | 52.7 | 57.3 | 61.3 |
| Overall | 62.21 | 69.38 | 66.61 | 70.52 | 73.62 |
| Method | Solved | pass@1 (%) | 95% CI | USD/problem | % of HRM cost | |
| fixed | Always-Single | 382 | 62.21 | [58.3, 66.0] | 0.095 | 10.1 |
| Always-Chain | 426 | 69.38 | [65.6, 72.9] | 0.483 | 51.3 | |
| Always-Star | 409 | 66.61 | [62.8, 70.2] | 0.507 | 53.8 | |
| Always-FullMesh | 433 | 70.52 | [66.8, 74.0] | 0.828 | 87.8 | |
| Always-HRM | 452 | 73.62 | [70.0, 77.0] | 0.943 | 100.0 | |
| budget-matched | Random | 421 | 68.57 | [64.8, 72.1] | 0.571 | 60.6 |
| shared | budget-matched at 40% | |||||||
| Method | pass@1 (%) | USD | % of HRM | rank | pass@1 (%) | USD | % of HRM | rank |
| RandomForest-Router | 76.55 | 0.489 | 51.9 | 1 | 74.27 | 0.374 | 39.6 | 2 |
| RouterR1-lite | 75.90 | 0.442 | 46.9 | 2 | 73.45 | 0.376 | 39.9 | 3 |
| Dats | 75.41 | 0.324 | 34.4 | 3 | 77.69 | 0.377 | 40.0 | 1 |
| MasRouter-lite | 71.99 | 0.286 | 30.3 | 4 | 72.64 | 0.375 | 39.8 | 4 |
| Dats -E2E | 70.85 | 0.312 | 33.1 | 5 | 71.66 | 0.361 | 38.3 | 5 |
| Alternative | ||||||
|---|---|---|---|---|---|---|
| Always-Single | 15.47 | 107 | 12 | 74.25 | 6.9e–18 | 7.6e–17 |
| Always-Star | 11.07 | 106 | 38 | 31.17 | 2.4e–8 | 2.4e–7 |
| Always-Chain | 8.31 | 79 | 28 | 23.36 | 1.3e–6 | 1.2e–5 |
| Random | 9.12 | 108 | 52 | 18.91 | 1.4e–5 | 1.1e–4 |
| Difficulty-Threshold | 7.33 | 79 | 34 | 17.13 | 3.5e–5 | 2.4e–4 |
| Dats -E2E | 6.03 | 64 | 27 | 14.24 | 1.6e–4 | 9.6e–4 |
| Suite | Single | Chain | Star | FullMesh | HRM | Dats (%) | Always-HRM (%) | Oracle (%) |
|---|---|---|---|---|---|---|---|---|
| APPS-Introductory | 71 | 21 | 3 | 2 | 3 | 92.0 | 92.0 | 98.0 |
| APPS-Interview | 39 | 33 | 6 | 8 | 14 | 74.0 | 71.0 | 88.0 |
| APPS-Competition | 6 | 22 | 7 | 18 | 47 | 50.0 | 41.0 | 66.0 |
| HumanEval+ | 131 | 23 | 3 | 3 | 4 | 96.3 | 95.1 | 98.2 |
| LiveCodeBench | 54 | 64 | 9 | 11 | 12 | 68.7 | 61.3 | 88.7 |
| Total | 301 | 163 | 28 | 42 | 80 | 77.69 | 73.62 | 88.93 |
| Backbone | Single | Chain | Star | FullMesh | HRM | Dats | Oracle | ||
|---|---|---|---|---|---|---|---|---|---|
| Claude Opus 4 | 62.21 | 69.38 | 66.61 | 70.52 | 73.62 | 77.69 | 88.93 | +4.07 | 0.0138 |
| DeepSeek-V3 | 57.33 | 64.50 | 61.73 | 65.47 | 68.40 | 72.48 | 85.02 | +4.08 | 0.027 |
| GPT-4o-mini | 51.47 | 59.12 | 56.35 | 60.42 | 63.36 | 67.59 | 80.94 | +4.23 | 0.017 |
| Qwen2.5-Coder-32B | 48.37 | 55.21 | 53.09 | 57.17 | 60.10 | 64.17 | 78.01 | +4.07 | 0.025 |
| Method | GSM8K | MATH | All | USD | % HRM |
|---|---|---|---|---|---|
| Single | 93.5 | 62.0 | 77.75 | 0.041 | 10.3 |
| Chain | 95.0 | 68.5 | 81.75 | 0.209 | 52.5 |
| Star | 94.0 | 66.0 | 80.00 | 0.221 | 55.5 |
| FullMesh | 95.5 | 70.0 | 82.75 | 0.357 | 89.7 |
| HRM | 96.0 | 73.0 | 84.50 | 0.398 | 100.0 |
| Dats | 96.5 | 79.5 | 88.00 | 0.160 | 40.3 |
| Variant | pass@1 (%) | USD | |
| feature groups removed | |||
| Difficulty | 73.45 | 0.377 | |
| Algorithmic | 74.59 | 0.376 | |
| Complexity | 75.08 | 0.377 | |
| Semantic | 75.24 | 0.375 | |
| Structural | 76.38 | 0.377 | |
| Encoder | Trainable | Fit time | pass@1 (%) | / | ||
|---|---|---|---|---|---|---|
| Dats : 39 interpretable features | 13.7K | 28 s CPU | 77.69 | — | — | — |
| Text-GNN: 2-layer GCN over the statement graph | 0.21M | 4 min GPU | 76.55 | 31/38 | 0.47 | |
| CodeBERT, frozen, plus the same head | 0.11M | 3 min GPU | 76.87 | 29/34 | 0.61 | |
| GraphCodeBERT, frozen, plus the same head | 0.11M | 3 min GPU | 77.36 | 27/29 | 0.89 | |
| GraphCodeBERT, fine-tuned end to end | 125M | 36 min GPU | 78.18 | 33/30 | 0.80 | |
| Dats -Hybrid: 39 features and frozen GraphCodeBERT | 0.13M | 6 min GPU | 78.99 | 36/28 | 0.38 |
Appendix figures & tables1 asset
Supplementary material from the paper’s appendix.
Appendix
| Pair | |||||
|---|---|---|---|---|---|
| Single–HRM | 29 | 99 | 37.20 | 1.1e–8 | |
| Single–FullMesh | 68 | 119 | 13.37 | 2.3e–3 | |
| Single–Chain | 61 | 105 | 11.14 | 6.8e–3 | |
| Star–HRM | 60 | 103 | 10.82 | 7.0e–3 | |
| Single–Star | 69 | 96 | 4.10 | 0.215 | |
| Chain–HRM | 58 | 84 | 4.40 | 0.215 |
Multi-Agent Coding
Multi-agent coding studies how AI agents can collaborate to generate, test, debug, and maintain software.
See all 82 papers