Source-linked AI summary
MARS: Multi-Specialist LLM Relay System for Competitive Programming
Andrei Mikhailov, Mikhail Burtsev, Alsu Sagirova
TL;DR
Competitive-programming multi-agent systems commonly use generic roles rather than agents grounded in algorithmic expertise. MARS uses retrieval-grounded topic specialists in a relay and, on CodeContests with Gemma 4, reaches 0.624 ± 0.006 pass rate at 2.3 recorded pipeline stages per task.
Problem
Existing competitive-programming multi-agent systems use generic planner, coder, and debugger roles and rely on pretrained LLMs for topic expertise, despite problems blending multiple theoretical areas.
Source: §1 · p. 1Method
Results
Across three backbones and two languages, MARS beats single-agent and ensemble baselines by 6–14 percentage points; on CodeContests with Gemma 4, it reaches 0.624 ± 0.006 pass rate at 2.3 recorded pipeline stages per task.
Source: §4.1 · p. 4, §5 · p. 5Takeaways & Limitations
MARS narrows but does not eliminate CodeSIM’s pass-rate lead while using 3.3× lower wall-clock cost.
Source: §1 · p. 2, §5 · p. 5The evaluation covers 165 CodeContests tasks, three backbones, two languages, one corpus, and Codeforces tags; transfer beyond C++17 and Python remains untested.
Source: Limitations · p. 5
Abstract
from arXiv · showhide
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.
1 Introduction
MARS replaces generic planner-coder-debugger roles with topic-specialized agents grounded by retrieval over algorithmic theory. Its relay uses public-test results to guide successive specialists, and the introduction reports improved CodeContests performance over direct prompting.
1 Introduction
- Existing competitive-programming pipelines use generic planner, coder, and debugger roles, leaving algorithmic expertise to emerge from the underlying LLMs (Islam et al., 2024, 2025; Li et al., 2026).The introduction identifies the lack of a mechanism for supplying algorithmic expertise as a gap in content-agnostic pipelines.Source: §1 · p. 1
- MARS forms a small team of RAG-grounded, single-topic specialists; each relay step uses public-test execution results to guide a specialist's choice to keep, repair, or hand off the draft.The initial agent generates the candidate, selects the next contributing agent, and the relay ends when an agent judges the solution complete.Source: §1 · pp. 1–2
- 0.624 ± 0.006 pass rate at 2.3 recorded pipeline stages per task, +14.4 percentage points over direct prompting, with 3.3× lower wall-clock cost than CodeSIM.MARS closes most of the gap to CodeSIM (0.731) and has ∼7× smaller standard deviation in per-task token spend.Source: §1 · p. 2
2 Related Work
Related work spans heterogeneous agents, retrieval-augmented code generation, inference-time team formation, and execution-based refinement. MARS combines topical specialist matching with algorithmic-theory retrieval and public-test feedback.
- Prior heterogeneous LLM systems vary backbones, coordination, agent pools, personas, and graph structure, but do not couple task-topic specialization with topical knowledge corpora.Source: §2 · p. 2
- Code-generation retrieval systems use code, API documentation, repositories, or evolving codebases, whereas MARS retrieves algorithmic-theory topics with one corpus slice per agent.Source: §2 · p. 2
- Prior inference-time teams recruit task-described experts (Chen et al., 2023b), generate agents and plans (Chen et al., 2024), rank candidates (Liu et al., 2023), or optimize graph prompts; MARS matches specialists by self-reported topical competence.Source: §2 · p. 2
- Code-generation systems commonly add execution, debugging, self-feedback, or reinforcement loops around one base model; MARS remains prompt-only and uses deterministic public-test execution.Source: §2 · p. 2
- Competitive programming remains difficult because correctness signals are sparse and algorithmic content deep; AlphaCode relied on enormous sampling and filtering, and olympiad benchmarks remain hard.AlphaCode's result is cited as Li et al. (2022); the benchmark findings are cited as Jain et al. (2024) and Shi et al. (2024).Source: §2 · p. 2
- AgentCoder (Huang et al., 2024) uses programmer/tester/executor feedback, while MapCoder (Islam et al., 2024) and CodeSIM (Islam et al., 2025) use staged or simulation-driven competitive-programming pipelines.Solvita (Li et al., 2026) develops a related multi-agent decomposition for the same setting.Source: §2 · p. 2
3 Method
MARS selects a small team from eleven topic specialists using retrieval-grounded self-assessment, then relays a single C++17 program through self-checking handoffs. Its deterministic execution gate controls whether repairs are accepted, while confidence scores are used only for team selection.
3 Method
- MARS relays one C++17 program through a small team selected from eleven topic-specialized agents.Each specialist self-assesses against a shared retrieval corpus, and the system uses a separate can-start probe to choose the starter.Source: §3 · p. 3
- Each specialist uses topic tags to assess scope, relevance, and confidence against its filtered cp-algorithms corpus.The system shortlists up to three matches by those scores and selects the starter with a separate can-start probe.Source: §3 · p. 3
- Each turn uses two LLM calls, with public-example execution gating keep, repair, or no-change decisions.A repair is accepted only if it compiles and does not reduce the number of passing public tests relative to that turn’s draft; confidence scores affect team selection only.Source: §3 · p. 3
- The relay is capped at three unique specialists and eight steps, with stopping and rerouting rules for no progress.After the relay, an infrastructure-fixer runs only when boilerplate-level failures are detected.Source: §3 · p. 3
- Evaluation uses 165 CodeContests test tasks and instruction-tuned Gemma 4 under a 4096-token budget.The comparisons include Direct, Single-RAG, Parallel ensemble, Base relay, and an adapted CodeSIM harness; Direct and Single-RAG use top-p 1.0, while the other Table 1 systems use 0.95.Source: §3 · p. 3
4 Results
MARS improves on prompt-only baselines and retains its advantage across tested backbones; the results also characterize protocol variants and the behavior of its sequential relay.
4.1 Main results
- 0.624 ± 0.006 pass rate at 2.3 recorded pipeline stages per task puts MARS above Direct (+0.144), Single-RAG (+0.095), and Parallel ensemble (+0.060); CodeSIM reaches 0.731 ± 0.009.MARS’s advantage over Direct widens from Medium (0.72 vs. 0.59) to Hard (0.40 vs. 0.18), while CodeSIM leads on every difficulty tier. MARS closes most of the gap to CodeSIM at 3.3× lower wall-clock cost.Source: Table 1 · p. 4, §4.1 · p. 4, Figure 3 · p. 4
4.2 Other backbones and target languages
- 9.5, 3.3, and 13.9 points are MARS’s margins over Single-RAG on Gemma 4, Qwen3.5-27B, and GPT-5.4-mini, respectively.On Python, MARS reaches 0.622 ± 0.015 against Direct’s 0.485 ± 0.000; PairCoder reaches 0.705 ± 0.009, 8.3 points above MARS at 1.4× the wall-clock cost.Source: §4.2 · pp. 4–5, Table 2 · p. 5
4.3 Ablations and protocol variants
- Removing RAG costs 2.0 points; the generalist-without-RAG variant is 0.9 points below MARS within one standard deviation but takes 31% longer and more calls.Base relay and Parallel manager trail MARS by 7.2 and 6.0 points; because retrieval also changes in the generalist variant, this comparison does not isolate specialization.Source: Table 3 · p. 5, §4.3 · p. 5
4.4 Relay behaviour and failure modes
- Teams contain one, two, or three agents on 1.8%, 15.8%, and 82.4% of task-runs, and an average of 1.35 specialists change the code.The reported 2.3 recorded stages include the final sanitizer/fixer record, so they measure pipeline-history depth rather than specialist turns. Each next specialist receives shared code and a compact relay summary, not the raw public-test report; the gate reverted 4.4 ± 0.9% of 697 self-check decisions.Source: §4.4 · p. 5
- Multi-topic tasks make up 88% and need no reconciliation because specialists edit one shared draft sequentially; the boilerplate-only fixer changed one task (≈0.2% of task-runs).Pass rate is 0.612 ± 0.010 on multi-topic tasks and 0.719 ± 0.030 on single-topic tasks; the headline 0.624 is independent of the fixer.Source: §4.4 · p. 5
5 Conclusion
MARS improves on single-agent and ensemble baselines across backbones and languages, but heavier-search systems still lead on pass rate.
5 Conclusion
- MARS beats single-agent and ensemble baselines by 6–14 percentage points across three backbones and two languages, using public-test feedback at every specialist step.It is a prompt-only, topic-aligned multi-agent system.Source: §5 · p. 5
- Heavier-search systems—CodeSIM and PairCoder in Python—still lead on pass rate.Source: §5 · p. 5
Limitations · A Prompt Templates
Evaluation is limited to 165 CodeContests tasks, three backbones, two languages, one corpus, and Codeforces tags, while transfer beyond C++17 and Python is untested. MARS uses four runtime prompt templates to select specialists, choose a starter, and conduct relay turns.
Limitations
- Evaluation covers 165 CodeContests tasks, three backbones, two languages, one corpus, and Codeforces tags; transfer beyond C++17 and Python remains untested.Python reuses the same corpus and index, while further languages need their own prompts, extraction, sandbox, and infrastructure.Source: Limitations · p. 5
- The local gate catches only same-turn public-test regressions, misses hidden tests and specialist comparisons, and all generated code requires sandboxed execution.Source: Limitations · p. 5
- CodeSIM is the only stage-aligned comparison, PairCoder remains Python-only, and other baselines require method-specific ports.The paper points to Appendix F for the ports.Source: Limitations · p. 5
A Prompt Templates
- Four runtime templates handle specialist inclusion, starter selection, code generation, and execution-aware self-check and handoff.The harness fills placeholders from agent metadata, the task, relay state, and retrieved RAG context.Source: A Prompt Templates · p. 7
- A self-assessment prompt gates each specialist's team inclusion, and a first-agent probe selects the starter and defines its initial contribution.The probe asks for one narrow first contribution rather than a full solution.Source: A Prompt Templates · pp. 7–8, Figure 4 · p. 8, Figure 5 · p. 8
- Each relay turn generates code, runs it against public examples in a sandbox, then uses a self-check and handoff call to drive keep, repair, or skip and select the next specialist.The calls include the current draft and public-test report; the generation prompt also carries task, subtask, handoff, relay-state, and RAG context.Source: A Prompt Templates · pp. 8–9, Figure 6 · p. 9, Figure 7 · p. 9
B Example Run
The example traces MARS solving a geometry problem through three topic specialists. After repairing a sample-failing draft and completing the program, the third relay step passes hidden tests.
B Example Run
- MARS selects MathematicsAgent, GeometryAgent, and ConstructiveAlgorithmsAgent for Codeforces problem 1620_B, Triangles on a Rectangle.MathematicsAgent derives the area formula and four-side enumeration; its initial draft fails the public sample because two sides use swapped rectangle dimensions, then it repairs the draft after the test report.Source: B Example Run · pp. 9–10
- The final program passes hidden tests after the third relay step, following a public-sample repair and contributions from three specialists.MathematicsAgent repairs its swapped rectangle dimensions; GeometryAgent simplifies endpoint subtraction, and ConstructiveAlgorithmsAgent adds the multi-test scaffold, fast I/O, and 64-bit arithmetic.Source: B Example Run · pp. 9–10
C Method Pseudocode
The pseudocode compares MARS with systems that vary specialist selection, collaboration, and public-test feedback. MARS relays edits to one shared draft, while its baselines use single-agent generation, independent parallel drafts, relay without execution feedback, or iterative planning and debugging.
C Method Pseudocode
- MARS relays a shared draft among task-relevant specialists, using public-test execution for intra-step refinement and an infrastructure check after the relay.The active specialist can keep, repair, or hand off the draft within the refinement loop.Source: C Method Pseudocode · p. 10, Figure 9 · p. 10
- Direct and Single-RAG use one agent, Parallel ensemble aggregates independent specialist drafts, and Base relay edits a shared draft without execution feedback.Direct uses only the task description; Single-RAG first elects one specialist, while Parallel ensemble uses a manager LLM to combine candidates.Source: C Method Pseudocode · p. 10, Figure 12 · p. 10, Figure 13 · p. 11
- CodeSIM plans, simulates, revises, generates code, and debugs against public tests until they pass or the attempt limit is reached.Its control flow is shown as plan, simulate, revise, generate, then debug against the public tests.Source: C Method Pseudocode · p. 10, Figure 14 · p. 11
D Relay Decision Statistics
Across 697 MARS relay self-check decisions, specialists most often kept drafts unchanged or accepted repairs; fewer proposed repairs were reverted or compile failures went unrepaired. Repair acceptance requires non-regression on same-turn public tests, but that guarantee does not extend to a new draft from the next specialist.
D Relay Decision Statistics
- Across 697 self-check decisions, 38.4 ± 1.0% accepted repairs, 55.4 ± 1.4% kept drafts unchanged, 4.4±0.9% proposed repairs were reverted, and 1.7±0.8% were unrepaired compile failures.Repair acceptance requires non-regression against the same-turn draft on public tests.Source: D Relay Decision Statistics · p. 11
- Repair acceptance requires non-regression on same-turn public tests, but this guarantee does not extend to the next specialist’s draft; over-inclusive selection is bounded by shared-code workflow and the no-progress cutoff.Source: D Relay Decision Statistics · p. 11
E Infrastructure-Fixer Statistics
The infrastructure-fixer intervenes only for template-level failures and rarely makes substantive edits. Its changes target boilerplate rather than logic and did not turn a failing task into a pass.
E Infrastructure-Fixer Statistics
- Substantive fixer edits occurred in ≈0.2% of reported MARS task-runs and ≈1.2% without RAG, addressing I/O, compilation, or non-compiling fragments.The fixer runs only when post-relay code has a template-level failure; deterministic sanitization runs on every candidate. The only failing task it edited remained failing, while one task passed after a legitimate output-format correction.Source: E Infrastructure-Fixer Statistics · p. 11
F Baseline Selection
This section defines the comparison protocol and explains why published results from most candidate baselines cannot be transferred directly to the C++17 evaluation.
- Comparisons use the full 165-task split and the same final ExecEval evaluation within each language block, with the generator backbone fixed within each table block.CodeSIM and PairCoder retain their method flows but use adapters for the dataset, model endpoint, and execution service.Source: F Baseline Selection · p. 11
- LDB (Zhong et al., 2024) requires a C++17 control-flow tracer and runtime-state collector, while LPW (Lei et al., 2025) needs compiler-safe instrumentation and redesigned prompts.LDB debugs externally generated Python programs; LPW uses Python print instrumentation and permits up to twelve iterations in each of two phases.Source: F Baseline Selection · pp. 11–12
- PairCoder’s reported 0.705 counts about 11% of tasks with truncated completions as failures and has no C++17 result.The official Navigator/Driver implementation was adapted to the task loader, model endpoint, and ExecEval sandbox; its Python-specific prompts, extraction, and lint logic prevented a C++17 run.Source: F Baseline Selection · p. 12
- MapCoder (Islam et al., 2024) was not rerun because CodeSIM, its successor, outperforms it in comparable GPT-based settings.MaintainCoder (Wang et al., 2025b) targets changing-requirement maintainability rather than oneshot functional correctness, requiring a different C++17 benchmark to reproduce.Source: F Baseline Selection · p. 12
- Xolver (Hosain et al., 2025) was not rerun because its LiveCodeBench evaluation averages 32 runs and would require 5,280 multi-agent executions for 165 tasks.Its released code is described as preliminary, with hard-coded paths and defaults differing from the paper’s agent count.Source: F Baseline Selection · p. 12