AI news and explainers at 7 AM weekdays, plus a Sunday weekly at 8Get it in your inbox

METAL LAB

MARS: Multi-Specialist LLM Relay System for Competitive Programming

arXiv:2608.239182026-08-26

For competitive programming, a relay of topic-specialist AIs beats one generalist model handing coding work off in sequence

MARS replaces the generic planner-coder-debugger roles used in existing multi-agent coding pipelines with topic specialists—dynamic programming, graphs, strings, geometry, and more—each grounded by retrieval over an algorithm-theory corpus. A small team of relevant specialists is selected per problem, a starter writes an initial C++17 draft, and each subsequent specialist runs the code against public tests before deciding to keep, repair, or hand it off. On Gemma 4 with the CodeContests test split, MARS reached a 0.624 pass rate, 14.4 points above direct prompting, closing most of the gap to CodeSIM (0.731) at 3.3x lower wall-clock cost.

METAL LAB explanatory visual

MARS Relay Pipeline Structure

Evidence statusMeasured results reported

  1. Specialist Pool & Team SelectionEleven topic-specialist agents self-assess against a shared cp-algorithms retrieval corpus; up to three relevant specialists are shortlisted as the team.
  2. Starter DraftA starter agent selected from the team writes the initial C++17 solution.
  3. Execute-Check-Handoff TurnsEach turn runs the current draft against public test examples in a sandbox, and the active specialist decides to keep, repair, or hand off the code.
  4. Relay TerminationThe relay stops on an explicit stop signal, when specialists run out, at the 8-step budget, or after a no-progress streak.
  5. Infrastructure Fixer & ResultA final boilerplate-only fixer pass normalizes I/O and compilation issues, yielding a 0.624 pass rate on CodeContests with Gemma 4.
An explanatory diagram made by METAL LAB, not a figure supplied by the paper's authors.

What they did

  1. Existing multi-agent coding pipelines split work into generic planner, coder, and debugger roles and leave actual algorithmic technique selection entirely to the underlying LLM, providing no mechanism for real domain expertise.
  2. MARS builds a small team of up to three relevant specialists out of a pool of eleven topic experts using retrieval-based self-assessment; a starter agent writes an initial C++17 solution, and each following turn runs the draft against public test examples in a sandbox before the active specialist decides to keep, repair, or hand off the code.
  3. On 165 CodeContests test tasks with the Gemma 4 backbone, MARS reached 0.624±0.006 pass rate at an average of 2.3 recorded pipeline stages per task, beating direct prompting by 14.4 points, single-specialist Single-RAG by 9.5 points, and the Parallel ensemble baseline by 6.0 points.
  4. MARS still trails the heavier plan-simulate-debug system CodeSIM (0.731) but closes most of that gap while using 3.3x lower wall-clock cost and substantially smaller variance in per-task token spend.
  5. The ordering Direct < Single-RAG < MARS held when swapping in other backbones (Qwen3.5-27B, GPT-5.4-mini) and when switching to Python, and removing the retrieval component cost 2.0 points in pass rate.
Figure 1: MARS relay pipeline. A task is routed from a pool of RAG-grounded topic specialists to a team of at most three agents. Each turn runs code generation, public-test execution, and self-check/handoff; repair code is rerun locally before the current code and relay packet move to the next specialist or final submission.
Figure 1: MARS relay pipeline. A task is routed from a pool of RAG-grounded topic specialists to a team of at most three agents. Each turn runs code generation, public-test execution, and self-check/handoff; repair code is rerun locally before the current code and relay packet move to the next specialist or final submission.
Table 1: Main results. Pass rate is solved-task fraction. Time in sec, tokens in thousands and number of calls are per-task. All values averaged across 3 runs. CodeSIM∗ is our rerun on Gemma4.
MethodPass rateSecTokensCalls
Direct0.48± 0.0234.9± 49.61.8± 1.21.0± 0.0
Single-RAG0.53± 0.0159.8± 21.225.0± 3.212.0± 0.0
Parallel ens.0.56± 0.00360.9± 172.929.8± 5.117.6± 0.8
Base relay0.55± 0.00191.6± 91.534.1± 10.217.1± 1.7
MARS0.62± 0.01244.3± 154.440.3± 8.116.6± 1.3
CodeSIM∗0.73± 0.01817.5± 1358.532.2± 54.810.2± 14.2
Figure 2: Team-selection frequency per specialist. Fraction of tasks on which each specialist joins the team, averaged over runs. Base relay and MARS share a deterministic assessor and coincide; the Parallel ensemble uses an earlier, less selective prompt and spreads selections more widely, which does not translate into accuracy.
Figure 2: Team-selection frequency per specialist. Fraction of tasks on which each specialist joins the team, averaged over runs. Base relay and MARS share a deterministic assessor and coincide; the Parallel ensemble uses an earlier, less selective prompt and spreads selections more widely, which does not translate into accuracy.
Table 2: Backbone and language transfer. The same 165 tasks and final harness as Table 1, using recorded model- and method-specific decoding. Time is in seconds, tokens in thousands, and calls per task; PairCoder includes embedding traffic.
MethodPass rateSecTokensCalls
Qwen3.5-27B, C++17
Direct0.192±0.01827.2±74.61.7±2.21.0±0.0
Single-RAG0.264±0.00471.0±57.126.5±4.012.0±0.0
MARS0.297±0.012109.7±99.740.5±18.715.3±3.3
GPT-5.4-mini, C++17
Direct0.149±0.0193.4±2.31.2±0.51.0±0.0
Single-RAG0.364±0.02449.7±26.324.7±3.212.0±0.1
MARS0.503±0.04392.2±61.136.8±7.415.8±1.8
Gemma 4, Python (PyPy 3)
Direct0.485±0.00070.0±137.81.6±1.01.0±0.0
MARS0.622±0.015307.6±215.742.9±9.117.1±1.4
PairCoder0.705±0.009426.7±451.727.6±20.97.6±5.4
Figure 3: Average pass rate by Codeforces difficulty tier. MARS dominates prompt-only baselines on Medium and more than doubles Direct on Hard; CodeSIM∗ leads on every tier. Tier sizes: Easy n=56, Medium n=39, Hard n=70.
Figure 3: Average pass rate by Codeforces difficulty tier. MARS dominates prompt-only baselines on Medium and more than doubles Direct on Hard; CodeSIM∗ leads on every tier. Tier sizes: Easy n=56, Medium n=39, Hard n=70.
Table 3: Ablations and protocol variants on Gemma 4. The generalist variant also disables RAG; the last two rows are the broader Base relay and Parallel ensemble comparisons from Table 1.
ConfigurationPass rateΔ
MARS (full)0.624±0.006
w/o RAG grounding0.604±0.007−0.020
Generalists, no RAG0.615±0.013−0.009
Earlier Base relay0.552±0.000−0.072
Parallel manager0.564±0.000−0.060
Figure 8: Example MARS trace for Codeforces 1620_B with three contributing specialists. Step 1 includes a within-step self-check repair loop: the first draft fails the public sample, the same specialist consumes the test report and emits a corrected draft before handing off. Later steps show the specialist contribution, public-test outcome, and structured handoff to the next agent.
Figure 8: Example MARS trace for Codeforces 1620_B with three contributing specialists. Step 1 includes a within-step self-check repair loop: the first draft fails the public sample, the same specialist consumes the test report and emits a corrected draft before handing off. Later steps show the specialist contribution, public-test outcome, and structured handoff to the next agent.

Findings

  • On 165 CodeContests test tasks with Gemma 4, MARS reached 0.624±0.006 pass rate at 2.3 recorded pipeline stages per task, beating Direct by 14.4 points, Single-RAG by 9.5 points, and Parallel ensemble by 6.0 points.
  • CodeSIM reached the highest pass rate at 0.731±0.009, but MARS closed most of that gap at 3.3x lower wall-clock cost (about 244.3s per task versus roughly 817s for the CodeSIM rerun).
  • By difficulty tier, Easy stayed near ceiling (0.80-0.93), while MARS's advantage over Direct widened on Medium (0.72 vs. 0.59) and Hard (0.40 vs. 0.18).
  • The ordering Direct < Single-RAG < MARS held across other backbones (Qwen3.5-27B, GPT-5.4-mini) and on Python, where MARS reached 0.622±0.015 versus Direct's 0.485, a 13.7-point gap.
  • Removing RAG cost 2.0 points in pass rate, and Base relay and Parallel manager trailed MARS by 7.2 and 6.0 points respectively.

Where it can be used

  • Designing pipelines for competitive-programming-style or algorithm-heavy coding tasks that assemble a small team of retrieval-grounded topic specialists instead of relying on one generalist model.
  • Building self-checking workflows where an agent runs its own draft against public tests each turn and decides whether to keep, repair, or hand off the work.
  • Building practical code-generation services that need to control wall-clock cost and token-spend variance while still capturing much of the accuracy of heavier iterative-search systems.

Limits and open work

  • Evaluation is limited to 165 CodeContests tasks, three backbones, two languages (C++17 and Python), one algorithm-theory corpus (cp-algorithms), and Codeforces tags, so generalization beyond this setup is untested.
  • The deterministic gate only catches same-turn public-test regressions; it misses hidden tests and cannot compare across specialists, and all generated code still requires sandboxed execution.
  • Only CodeSIM was compared under the same stage-aligned protocol, and PairCoder was only compared in Python; several other baselines (LDB, LPW, MapCoder, MaintainCoder, Xolver) could not be ported due to language or protocol mismatches.
  • The jump from Base relay to MARS (0.552 to 0.624) combines several simultaneous changes (public-test self-check, subtask tracking, infrastructure fixer), so individual contributions are not isolated.
  • The RAG-ablation comparison against a non-RAG generalist also changes retrieval itself, so it does not cleanly isolate the effect of specialization alone.

Why it matters

For tasks like competitive programming, where correctness signal is sparse and deep algorithmic knowledge matters, this shows that grounding specialized agents in real topic knowledge via retrieval can match much of a heavier system's performance at a fraction of the cost. Anyone designing multi-agent coding pipelines gets a concrete alternative to generic role-splitting: a lightweight relay of topic specialists with in-loop execution feedback.

Terms in this paper

  • RAG (검색증강생성, retrieval-augmented generation) · 모델이 응답을 생성할 때 외부 문서를 검색해 그 내용을 참고하도록 하는 기법
  • relay pipeline · 한 에이전트가 작성한 코드를 다음 에이전트가 이어받아 순서대로 수정해 나가는 진행 구조
  • pass rate · 전체 문제 중 정답으로 통과 판정된 비율
  • ExecEval · 생성된 코드를 실제로 공개 테스트 예제에 대해 실행해 통과 여부를 확인하는 샌드박스 환경
  • CodeSIM · 계획 수립, 시뮬레이션, 디버깅을 반복하는 비교 대상 다중 에이전트 코드 생성 시스템

Original abstract (English)

Large Language Models excel at code generation, yet competitive programming exposes a persistent failure mode: existing multi-agent pipelines distribute work over generic planner, coder, and debugger roles and delegate the choice of algorithmic technique to the backbone alone. We present MARS (Multi-Agent Relay of Specialized LLMs), a prompt-only framework in which each agent is a topic specialist---dynamic programming, graphs, strings, geometry, and so on---grounded by retrieval-augmented generation over an algorithm-theory corpus. Given a problem, retrieval selects a small team of relevant specialists; a starter writes an initial C++17 solution, and each subsequent turn runs the candidate against public examples in a sandbox, lets the active specialist keep, repair, or hand off the draft, and forwards a structured packet to the next specialist. A single infrastructure-fixer pass normalizes boilerplate at the end. On the CodeContests test split with Gemma 4, MARS reaches $0.624 \pm 0.006$ pass rate at $2.3$ recorded pipeline stages per task ($+14.4$ percentage points over direct prompting), closing most of the gap to CodeSIM ($0.731$) at $3.3{\times}$ lower wall-clock cost and substantially smaller variance in per-task token spend. The source code is available on GitHub: https://github.com/fckand/mars.

Authors · Andrei Mikhailov, Mikhail Burtsev, Alsu Sagirova

Read on arXiv

Latest papers

All papers →

Latest from METAL LAB

Figures: Andrei Mikhailov et al., arXiv:2608.23918, CC BY 4.0