Abstract
Prompt engineering for Large Code Models (LCMs) is currently a manual, time-consuming "dark art." This paper introduces APE-CoT, an automated framework that combines optimized task instructions with multi-step reasoning to dramatically boost model performance. Tested on both open-source benchmarks and WeChat’s internal C++ codebase, the approach yielded performance gains of up to 148% in real-world industrial scenarios.
Introduction
Large Code Models (LCMs) such as CodeLlama and DeepSeek-Coder have become indispensable tools for modern software development. However, these models are notoriously "prompt-sensitive"—the quality of their output depends heavily on how a task is phrased. Currently, developers spend hours manually crafting prompts, a process that is tedious, unscalable, and often fails to generalize across different models.
While Automated Prompt Generation (APG) has gained traction in general Natural Language Processing (NLP), its application to specialized "Code Intelligence" tasks (like code translation or API recommendation) has remained largely unexplored. This research aims to bridge this gap by identifying which automated strategies work best for code and proposing a unified framework that outperforms human-written baselines.
Methodology: The APE-CoT Framework
The researchers decomposed the APG process into two functional components and evaluated existing state-of-the-art techniques for each:
- Instruction Generation (IG): This creates the "what to do" part of the prompt. The study compared APE (Automatic Prompt Engineer), which selects the best instruction based on log probability, against OPRO, which uses an iterative "meta-prompt" to refine instructions. Surprisingly, APE outperformed the more complex OPRO by generating more concise, technically focused instructions.
- Multi-Step Reasoning (MSR): This guides the model's logical flow. The researchers tested Chain-of-Thought (CoT), AutoCoT, and Self-Plan. Standard CoT proved to be the most stable and consistent performer.
The Novel Approach: APE-CoT Based on these findings, the authors proposed APE-CoT. This hybrid method uses APE to generate a precise, token-efficient instruction and then appends a CoT "Let’s think step by step" trigger. This ensures the model understands technical constraints while breaking down the logic into manageable steps.
Experimental Setup and Datasets
The study utilized a mix of standard academic benchmarks and a unique industrial dataset to test four major LCMs (DeepSeek-Coder, Magicoder, CodeLlama, and Qwen2.5-Coder):
- CodeXGLUE: Code summarization (Java/Python).
- AVATAR: Code translation (Java ↔ Python).
- APIBENCH-Q: API recommendation.
- WeChat-Bench: A proprietary dataset introduced in this paper, consisting of 1,000 C++ samples from the WeChat production codebase, designed to test API recommendation in a complex, real-world environment.
Key Results and Insights
The APE-CoT framework showed significant improvements over basic prompts across all tested models:
- Code Translation: +28.38% average improvement in CodeBLEU.
- Code Summarization: +58.11% average improvement in ROUGE-L.
- API Recommendation: +84.53% average improvement in SuccessRate@1.
- Industrial Impact: On WeChat-Bench, the framework achieved a staggering 148.89% improvement in Mean Reciprocal Rank (MRR). This demonstrates that APG effectively solves the "domain specificity" problem where models struggle with internal, proprietary APIs.
Critical Observations
- APE > OPRO for Code: APE-generated instructions focused on critical technical aspects like syntax and naming conventions, whereas OPRO often included redundant "fluff."
- Stability of CoT: Standard Chain-of-Thought provided the most consistent performance gains and the lowest variance, making it the most reliable reasoning method for code.
- Output Synergy: The combination of automated instructions and reasoning was most effective for tasks where the model writes code (NL-to-PL) rather than just summarizing it.
Conclusion and Future Work
APE-CoT represents a significant advancement in automating the interaction with Large Code Models. By moving away from manual prompt engineering, developers can achieve higher accuracy and better generalization, especially in proprietary industrial environments.
Future research will focus on scaling these methods to ultra-large models (100B+ parameters) and developing execution-based evaluation metrics to ensure that generated code is not only similar to ground truth but fully functional.
Summary updated