TL;DR
This paper introduces AdaCoder, a novel adaptive multi-agent framework for function-level code generation that significantly improves generalizability across diverse Large Language Models (LLMs). AdaCoder achieves this by intelligently combining direct LLM code generation with a strategic planning and debugging process, outperforming existing state-of-the-art methods in accuracy while being substantially faster and more efficient.
What Problem Does This Paper Address?
The increasing prevalence of LLMs for code generation has led to the development of sophisticated multi-agent frameworks designed to automate the creation of code functions. While these frameworks have shown promise with powerful proprietary LLMs like ChatGPT, their effectiveness and generalizability across a wider range of open-source LLMs with varying sizes, architectures, and performance levels remain largely unexplored. This lack of systematic evaluation hinders our understanding of what makes these frameworks robust and adaptable. The paper aims to bridge this gap by empirically studying the generalizability of existing frameworks and proposing a more adaptable solution.
Methods
AdaCoder is a two-phase framework. Phase 1 focuses on initial code generation without explicit planning. It leverages an LLM-based "Programming Assistant" for coding and a script-based "Code Evaluator" for testing. This phase aims to harness the LLM's native coding abilities and quickly identify errors that prevent execution. The Code Evaluator uses provided test cases rather than generating its own, reducing computational cost. If Phase 1 fails, Phase 2 is initiated, introducing an LLM-based "Prompt Engineer" for planning and a rule-based "Debug Specialist" for error correction. The Debug Specialist handles superficial errors (like syntax or indentation issues) using efficient, rule-based methods. The Prompt Engineer then generates a step-by-step plan to address deeper logic errors, guiding the Programming Assistant in a second attempt. This adaptive approach only employs planning when necessary, making it more efficient.
Datasets
The primary dataset used for evaluation is HumanEval, a widely adopted benchmark for function-level code generation developed by OpenAI. It comprises 164 Python programming challenges, each with sample test cases. The paper also utilizes the MBPP (Mostly Basic Python Problems) dataset, a collection of 974 Python programming tasks, to further validate the framework's performance.
Key Insights and Ideas
- Generalizability is a Major Hurdle: Existing multi-agent code generation frameworks, while effective on powerful models like ChatGPT, struggle to generalize to smaller, open-source LLMs. Their performance can be unstable and highly dependent on the specific LLM used.
- Iterative Refinement is Costly and Ineffective: The common practice of iterative refinement (repeatedly trying to fix code based on error feedback) offers minimal performance gains but significantly increases computational cost (time and tokens). Many refinement attempts result in "abnormal behaviors" like code invariance or the introduction of new errors.
- Planning and Non-Planning Complement Each Other: Combining direct LLM code generation (non-planning) with a strategic planning mechanism (like AdaCoder's) offers a better balance of performance and resource efficiency than relying solely on planning.
- Rule-Based Debugging is Efficient: For common, superficial errors, rule-based debugging is significantly faster and more efficient than using LLMs for the same task.
- Adaptive Planning is Key: AdaCoder's success stems from its adaptive nature – it only engages its planning and debugging agents when the LLM's direct generation fails, making it more resource-efficient.
Key Results
- Superior Performance: AdaCoder outperforms the best baseline, MapCoder, by an average of 27.69% in Pass@1 accuracy across ten diverse LLMs on the HumanEval benchmark.
- Efficiency Gains: AdaCoder is 16 times faster and consumes 12 times fewer tokens than MapCoder.
- Broad Applicability: The framework demonstrates high generalizability across LLMs with varying parameter sizes (1.3B to 34B) and architectures.
- Ablation Study: All agents within AdaCoder (Programming Assistant, Code Evaluator, Debug Specialist, Prompt Engineer) contribute significantly to its performance, highlighting their necessity.
Limitations and Future Work
- Iteration Count Tuning: While AdaCoder's performance scales with the number of iterations (
t), this comes at the cost of increased time and token consumption. The optimaltvalue may need adjustment based on the specific LLM and task. - Dataset Specificity: The current evaluation is based on HumanEval and MBPP. Future work could involve validating AdaCoder on more diverse datasets and in different environments to assess broader applicability.
- Future Research: The authors plan to explore more diverse datasets and environments in future research to further validate their approach.
Summary updated