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

A Pair Programming Framework for Code Generation via Multi-Plan Exploration and Feedback-Driven Refinement

Huan Zhang, Wei Cheng, Yuhan Wu, Wei Hu

Abstract

Current Large Language Models (LLMs) often struggle with complex programming tasks due to a "single-path" limitation, where they persist in repairing a fundamentally flawed initial strategy. We present PairCoder, a novel framework that mimics human pair programming by decoupling high-level strategy from low-level implementation. By employing a "Navigator" to explore multiple diverse plans and a "Driver" to implement and refine code based on execution feedback, PairCoder enables agents to pivot away from unproductive strategies. Our evaluation shows that PairCoder significantly outperforms existing refinement methods, achieving up to a 150% relative increase in accuracy on difficult competitive programming benchmarks.

Introduction: The "Single-Path" Pitfall

While LLMs excel at generating short code snippets, they frequently fail on multi-step algorithmic problems. A primary reason is the "single-path" approach: once a model generates a solution plan, it tends to focus on fixing syntax or minor logic errors within that specific plan, even if the underlying strategy is incorrect. This is akin to "polishing a dead horse"—no amount of debugging can fix a fundamentally wrong approach.

Illustration of the multi-plan exploration strategy vs. the single-path repair pitfall.

Human developers avoid this through pair programming. A Navigator maintains the big-picture view and considers alternative strategies, while a Driver handles the immediate implementation. If a strategy fails, the pair brainstorms a new direction rather than getting stuck in a loop of failing repairs.

Methodology: The PairCoder Framework

PairCoder formalizes this collaborative dynamic into two specialized LLM-powered agents:

1. The Navigator (The Architect)

The Navigator's role is strategic. It begins by reflecting on the problem requirements and potential edge cases. Instead of generating one plan, it performs Multi-Plan Exploration, generating a diverse set of solution strategies. To ensure true diversity, PairCoder utilizes text embeddings and k-means clustering to select the most distinct representative plans (e.g., ensuring a choice between Greedy and Dynamic Programming approaches). The Navigator monitors the Driver's progress and triggers a plan switch if the current strategy hits a dead end.

2. The Driver (The Implementer)

The Driver focuses on execution. It writes Python code based on the Navigator’s selected plan and runs it against public test cases. If the code fails, the Driver performs targeted refinement based on the specific error type (Runtime Error, Wrong Answer, or Time Limit Exceeded).

The PairCoder framework architecture, detailing the Navigator and Driver roles.

The entire process is iterative and supported by a long-term memory module that tracks historical attempts to prevent the agents from repeating past mistakes.

Evaluation and Results

We evaluated PairCoder across five benchmarks, ranging from standard function-level tasks (HumanEval, MBPP) to complex competitive programming (CodeContest).

  • Significant Performance Gains: On the challenging CodeContest benchmark, PairCoder improved GPT-3.5-Turbo’s pass@1 rate from 6.06% to 15.15%, a 150% relative improvement.
  • Model Agnostic: The framework consistently yielded top results using both open-source models like DeepSeek-Coder-33B and closed-source models like GPT-4.
  • Efficiency: PairCoder offers a practical balance, outperforming single-shot methods while remaining more token-efficient than heavy multi-agent systems like MetaGPT.

Key Insights and Limitations

A core takeaway is that LLMs are more effective when allowed to "fail fast" and pivot. By prioritizing robust, intuitive solutions (like brute force) initially and ensuring plan diversity through clustering, PairCoder avoids the stagnation common in other self-repair frameworks.

However, the framework's effectiveness is currently tied to the availability of public test cases for feedback. Future work will explore automated test case generation to mitigate this dependency and investigate the integration of human-in-the-loop feedback to further refine the Navigator's strategic decisions.

Summary updated

BibTeX
@inproceedings{zhang2024pair,
  author = {Huan Zhang and Wei Cheng and Yuhan Wu and Wei Hu},
  title = {{A Pair Programming Framework for Code Generation via Multi-Plan Exploration and Feedback-Driven Refinement}},
  booktitle = {ASE},
  year = {2024},
  url = {https://openreview.net/forum?id=ZwiJkkAoxD},
}
Figure