Source-linked AI summary

MARS: Multi-Specialist LLM Relay System for Competitive Programming

Andrei Mikhailov, Mikhail Burtsev, Alsu Sagirova

arXiv:2608.23918v1cs.AIcs.MAcs.PL

TL;DR

Competitive programming exposes a gap in generic multi-agent code-generation systems, which do not explicitly supply algorithmic expertise. MARS addresses this with RAG-grounded topic specialists in a relay using public-test feedback, reaching 0.624 ± 0.006 pass rate at 2.3 recorded pipeline stages per task and improving over direct prompting by +14.4 percentage points. The method narrows the gap to CodeSIM at lower wall-clock cost, but transfer beyond C++17 and Python remains untested.

  • Problem

    Generic multi-agent pipelines use stage-based roles and leave algorithmic expertise to the underlying LLM, despite competitive programming requiring theoretical algorithmic knowledge.

  • Method

    MARS routes problems to a small team of single-domain specialists grounded by RAG over an algorithmic theory corpus and applies public-test execution during relay handoffs.

  • Results

    0.624 ± 0.006 pass rate at 2.3 recorded pipeline stages per task improves over Direct by +0.144, while MARS narrows the gap to CodeSIM at 3.3× lower wall-clock cost.

  • Takeaways & Limitations

    MARS beats single-agent and ensemble baselines by 6–14 percentage points across three backbones and two languages, although heavier-search systems still lead on pass rate.

  • Takeaways & Limitations

    Transfer beyond C++17 and Python remains untested, and the local gate misses hidden tests and comparisons between specialists.

Abstract

from arXiv · show

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 addresses the lack of algorithmic expertise in generic multi-agent code-generation pipelines by using RAG-grounded, topic-specialized agents. Its relay combines task-matched team selection with public-test feedback and achieves higher pass rates than direct prompting on CodeContests.

  • MARS assigns each agent a single algorithmic topic and grounds its expertise through retrieval-augmented generation over an algorithmic theory corpus.
  • Generic planner, coder, and debugger pipelines provide no mechanism to supply the algorithmic expertise needed for correct competitive-programming solutions.
  • A task-matched team is selected by specialist assessments of topical fit and ability to initialize the relay.
  • Each relay turn uses public-test execution to let the active specialist keep, repair, or hand off the current solution.
  • 0.624 ± 0.006 pass rate is achieved at 2.3 recorded pipeline stages per task, improving over direct prompting by +14.4 percentage points.

2 Related Work

Prior work explores heterogeneous agents, retrieval, dynamic team formation, execution feedback, and role-based code-generation pipelines. MARS differs by coupling each specialist to an algorithmic topic corpus and organizing relay teams through topical competence.

  • Heterogeneous multi-agent systems vary backbones, coordination, team formation, personas, professional roles, and graph structure, but do not couple specialization to task topics and topical corpora.
  • Existing code-generation retrieval systems retrieve code, API documentation, or repositories, whereas MARS retrieves distinct algorithmic-theory topics for separate specialists.
  • Dynamic-team methods recruit or optimize agents using task descriptions, importance scores, or graph operations; MARS instead uses specialists’ self-reported topical competence.
  • Single-model outer loops improve code through search, verification, repair, or feedback, while MARS remains prompt-only and uses deterministic public-test execution feedback.
  • Prior competitive-programming multi-agent systems decompose work into generic roles such as retrieval, planning, coding, debugging, testing, and execution.

3 Method

MARS routes problems to a small team of topic specialists, relays a single C++17 program through execution-grounded handoffs, and applies bounded stopping and final boilerplate repair.

  • A pool of eleven topic-specialized agents self-assesses against a shared retrieval corpus, and up to three relevant specialists are shortlisted.
  • The starter is selected with a separate can-start probe after specialists report scope, relevance, and confidence.
  • Each turn drafts code, executes it on public examples, and uses a second call to choose keep-code, repair-code, or no-change with structured handoff fields.
  • A repair is accepted only when it compiles and does not reduce that turn’s passing public tests; otherwise the original draft is restored.
  • The relay allows at most three unique specialists and eight steps, then sanitizes code and invokes an infrastructure-fixer only for detected boilerplate failures.
  • Evaluation uses 165 CodeContests test tasks with instruction-tuned Gemma 4, the cp-algorithms corpus, and Jina Embeddings v2.

4 Results

MARS improves pass rates over prompt-only baselines across difficulty tiers and backbones, while using a compact relay and lower-cost protocol than heavier-search competitors.

  • 0.624 ± 0.006 pass rate at 2.3 recorded pipeline stages per task improves over Direct by 0.144 and narrows the gap to CodeSIM’s 0.731.MARS uses execution feedback at every specialist turn.
  • 0.40 versus 0.18 on Hard shows MARS widening its advantage over Direct as difficulty increases.On Medium, MARS scores 0.72 versus Direct’s 0.59; Easy scores remain near ceiling.
  • MARS beats Single-RAG on every tested backbone, with gains of 9.5, 3.3, and 13.9 points on Gemma 4, Qwen3.5-27B, and GPT-5.4-mini.The ordering Direct < Single-RAG < MARS persists across backbones.
  • 0.705 ± 0.009 gives PairCoder an 8.3-point advantage over MARS at 1.4× the wall-clock cost, making it a stronger but heavier-search competitor.PairCoder uses multi-plan search and proprietary embedding-based plan clustering.
  • Removing RAG costs 2.0 points, while broader Base relay and Parallel manager variants trail MARS by 7.2 and 6.0 points.The generalist variant also disables RAG, so it does not isolate specialization.
  • 82.4% of task-runs use three-agent teams, while the reported 2.3 stages include the final sanitizer or fixer record.The stage metric measures pipeline-history depth rather than specialist turns.
  • MARS scores 0.612 ± 0.010 on multi-topic tasks and 0.719 ± 0.030 on single-topic tasks, with the boilerplate-only fixer changing one task.Multi-topic tasks comprise 88% of the evaluated tasks.

5 Conclusion

MARS is a prompt-only, topic-aligned multi-agent system that improves over single-agent and ensemble baselines while retaining an advantage across backbones and languages. Heavier-search systems still achieve higher pass rates.

  • MARS beats single-agent and ensemble baselines by 6–14 percentage points.
  • Public-test feedback is used at every specialist step.
  • MARS holds its advantage across three backbones and two languages.
  • CodeSIM and PairCoder in Python still lead MARS on pass rate.

Limitations

The evaluation and comparison protocol impose scope boundaries, while the relay gate uses limited public-test evidence and requires sandboxed execution. Several implementation details are specific to the evaluated languages and infrastructure.

  • Transfer beyond C++17 and Python remains untested.The evaluation covers 165 CodeContests tasks, three backbones, two languages, one corpus, and Codeforces tags.
  • The local gate rejects only same-turn public-test regressions and misses hidden tests and comparisons between specialists.
  • All generated code requires sandboxed execution.
  • CodeSIM is the only stage-aligned comparison, while PairCoder remains Python-only.Other baselines require method-specific ports.

B Example Run

A successful MARS trace routes one rectangle-area problem through three topic specialists. Public-test feedback triggers a repair, after which later specialists simplify the geometry and complete implementation details before hidden-test success.

  • Three specialists—MathematicsAgent, GeometryAgent, and ConstructiveAlgorithmsAgent—are selected for the task.
  • The mathematics specialist derives the area formula and repairs a draft after a public-sample failure caused by swapped dimensions.
  • The geometry specialist reduces each side to an endpoint subtraction and clarifies the opposite-dimension height.
  • The constructive-algorithms specialist completes the multi-test scaffold, fast I/O, and 64-bit arithmetic before the final program passes hidden tests.

C Method Pseudocode

MARS sequentially edits a shared draft through task-relevant specialists, using public-test execution for intra-step refinement and handoff decisions. The baselines differ in whether they use single-agent generation, parallel candidate merging, or simulation-driven revision.

  • MARS: MARS combines sequential shared-draft editing with an intra-step refinement loop and a post-relay infrastructure check.
  • MARS: MARS retrieves topic-matched context, self-assesses specialists, selects up to three, and chooses a starter before initializing shared relay state.
  • MARS: Each relay step generates or repairs a shared draft, executes it on public examples, and permits a next specialist or stopping decision.
  • Single-agent baselines: Single-RAG elects one specialist to solve directly, whereas Direct uses one agent prompted only with the task description.
  • Parallel ensemble: Parallel ensemble has selected specialists produce independent candidates that a manager LLM combines into one final program.
  • CodeSIM: CodeSIM repeatedly plans, simulates, revises, generates, and debugs against public tests.

D Relay Decision Statistics

MARS recorded 697 self-check decisions, most of which kept drafts unchanged or accepted repairs. Repair acceptance was protected by non-regression on the same-turn public tests, but this guarantee did not extend to drafts from the next specialist.

  • 697 self-check decisions were recorded across the reported MARS runs.
  • 55.4 ± 1.4% of decisions kept the draft unchanged, while 38.4 ± 1.0% accepted a repair.
  • 4.4 ± 0.9% of proposed repairs were rejected and reverted, and 1.7 ± 0.8% were unrepaired compile failures.
  • Repair acceptance required compilation and no reduction in public-test passes relative to the same-turn draft.
  • The non-regression guarantee did not extend to a new draft written by the next specialist.

E Infrastructure-Fixer Statistics

The infrastructure-fixer was narrowly reserved for boilerplate-level failures, while deterministic sanitization ran on every candidate. Substantive fixer edits were rare in reported MARS runs.

  • The infrastructure-fixer addressed template failures such as I/O format, headers, and integer width rather than program logic.
  • A deterministic sanitization pass ran on every candidate to strip code fences and ensure a compilable shell.
  • The infrastructure-fixer made a substantive edit in approximately 0.2% of reported task-runs.
  • Without RAG, substantive infrastructure-fixer edits occurred in approximately 1.2% of task-runs.

F Baseline Selection

The baseline comparison used a common 165-task evaluation protocol where possible, while accounting for systems whose implementations or task settings could not be faithfully ported. An example trace illustrates MARS’s relay behavior rather than serving as a baseline.

  • Comparisons used the full 165-task split and the same final ExecEval evaluation within each language block.
  • Generator backbones were fixed within table blocks, while decoding and intermediate execution followed each model’s logged requirements.
  • Published comparison numbers were not transferred directly because they used different backbones, splits, or task formulations.
  • PairCoder was integrated through an adapter because its Python-specific Navigator/Driver implementation could be run without redesign.
  • An example MARS trace shows a first draft repaired after failing a public sample before handoff to later specialists.
Loading 2608.23918v1…