NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

MapCoder: Multi-Agent Code Generation for Competitive Problem Solving

Md. Ashraful Islam, Mohammed Eunus Ali, Md. Rizwan Parvez

Abstract

Competitive programming presents a significant challenge for Large Language Models (LLMs), requiring complex algorithmic reasoning and iterative refinement. MapCoder is a multi-agent prompting framework designed to mimic the human software development lifecycle—incorporating retrieval, planning, coding, and debugging. By utilizing a "Dynamic Traversal" strategy to explore and refine multiple logic plans, MapCoder achieves state-of-the-art results on major benchmarks, including HumanEval (93.9%) and MBPP (83.1%), significantly outperforming existing single-agent and self-reflection methods.

Introduction

While LLMs have become proficient at generating simple code snippets, "competition-level" programming remains a difficult frontier. These tasks demand deep natural language understanding, complex algorithmic reasoning, and the ability to systematically identify and fix logical errors. Current prompting techniques often fail in two key areas: a lack of structured planning and the "feedback trap." The latter occurs when models generate incorrect unit tests during self-reflection, leading them to "fix" functional code into a broken state.

MapCoder addresses these issues by introducing a structured, multi-agent pipeline that replicates the human "recall-plan-code-debug" cycle, ensuring that code generation is grounded in verified logic and strategic backtracking.

The MapCoder Framework

MapCoder utilizes four specialized agents to manage the transition from problem statement to executable solution:

  1. Retrieval Agent: Instead of relying on external databases, this agent uses "analogical prompting" to recall $k$ similar problems and their algorithmic solutions from the LLM’s internal knowledge base.
  2. Planning Agent: For each retrieved example, this agent generates a specific, step-by-step plan for the target problem and assigns it a confidence score.
  3. Coding Agent: This agent translates the highest-confidence plans into executable code.
  4. Debugging Agent: If the generated code fails the provided sample inputs/outputs (I/O), this agent attempts to fix the bugs. Crucially, it uses the original plan as a reference point to ensure logical consistency during the fix.

Dynamic Traversal

A core innovation of MapCoder is its Dynamic Traversal strategy. Rather than committing to a single approach, the system sorts generated plans by confidence and iterates through them. If a plan fails to pass sample tests after a set number of debugging attempts, the system backtracks to the next best plan. This mimics the human programmer's ability to pivot to a different algorithm when an initial approach proves unviable.

Experimental Evaluation

The authors evaluated MapCoder across eight diverse benchmarks categorized into two levels of difficulty:

  • Basic Programming: HumanEval, HumanEval-ET, MBPP, MBPP-ET, and EvalPlus.
  • Competitive Programming: APPS, xCodeEval, and CodeContests.

These datasets span multiple programming languages (including Python, C++, and Java) and range from introductory exercises to complex algorithmic challenges found in professional competitions.

Key Insights and Results

MapCoder established new State-of-the-Art (SOTA) marks for pass@1 accuracy across several benchmarks:

  • SOTA Performance: MapCoder achieved 93.9% on HumanEval and 83.1% on MBPP using GPT-4. On the rigorous CodeContests benchmark, it reached a 28.5% pass@1 rate, a 135% improvement over direct prompting.
  • Plan-Derived Debugging: The Debugging Agent proved most effective when provided with the original plan alongside error messages. This context allows the model to identify logical flaws rather than just syntax errors.
  • The Danger of Hallucinated Tests: MapCoder avoids performance degradation by sticking strictly to provided sample I/O. Unlike frameworks that ask LLMs to generate new test cases—which can be incorrect—MapCoder prevents the "feedback loop of error."
  • Model Agnostic Gains: The framework is not limited to GPT-4; it showed significant performance improvements when applied to ChatGPT (GPT-3.5), Gemini Pro, and open-source models like Mistral-7B.

Discussion and Limitations

Despite its success, MapCoder introduces certain trade-offs:

  • Token Consumption: The multi-agent approach and iterative debugging are "token-heavy," requiring an average of 16.7 API calls per problem compared to a single call for direct prompting.
  • Sample I/O Dependency: The effectiveness of the debugging phase is tied to the quality of provided sample inputs. Weak or missing samples can limit the agent's ability to verify code.
  • Reasoning Ceilings: While MapCoder excels at mid-level problems, gains diminish on extremely difficult tasks (e.g., difficulty scores > 1000 on xCodeEval), suggesting that structural improvements alone cannot yet overcome the fundamental reasoning limits of current LLMs.

Conclusion

MapCoder demonstrates that a structured, multi-agent approach to code generation can significantly enhance the problem-solving capabilities of LLMs. By prioritizing planning and allowing for dynamic backtracking, the framework bridges the gap between simple code generation and complex competitive programming. Future work may focus on optimizing token usage and applying similar multi-agent traversal logic to other complex domains such as mathematics or legal reasoning.

Summary updated

BibTeX
@inproceedings{islam2024mapcoder,
  author = {Md. Ashraful Islam and Mohammed Eunus Ali and Md. Rizwan Parvez},
  title = {{MapCoder: Multi-Agent Code Generation for Competitive Problem Solving}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.acl-long.269},
}
Figure