Abstract
The performance of Large Language Models (LLMs) critically depends on designing effective instructions, which is particularly challenging for black-box LLMs with inaccessible internal states. To this end, we introduce Learning to Instruct, a novel paradigm that formulates instruction optimization as an LLM fine-tuning objective for a white-box "instruction engineer" LLM, leveraging its rich learning capacity and vast pre-trained knowledge to enable efficient and effective instruction optimization. Within this paradigm, we propose Automatic Instruction Optimizer (AIO), a novel framework that fine-tunes a white-box LLM into a capable instruction engineer. AIO learns to optimize task-aware, human-comprehensible instructions by incorporating task nuances and feedback from the task-solving black-box LLM. To overcome the challenges of inaccessible black-box gradients and high API costs, AIO introduces a novel zeroth-order (ZO) gradient approximation mechanism guided by Thompson Sampling (TS), which reuses informative black-box LLM feedback for improved query efficiency. Extensive experiments show that AIO generally outperforms strong baselines in both effectiveness and efficiency, establishing Learning to Instruct as a promising new direction for black-box LLM instruction optimization.
Introduction
The efficacy of Large Language Models (LLMs) is highly sensitive to the quality of the prompts or instructions provided. However, manual prompt engineering is labor-intensive and often fails to scale across diverse tasks. While automated methods have emerged, they face significant challenges when applied to "black-box" models like GPT-4 or Claude-3, which are accessed only via APIs and do not expose internal gradients. Existing solutions often rely on shallow In-Context Learning (ICL) or computationally expensive Zeroth-Order (ZO) optimization. This paper addresses the "efficiency vs. effectiveness" trade-off by proposing a fine-tuning-based approach to instruction optimization.
Methodology: The Automatic Instruction Optimizer (AIO)
The proposed Automatic Instruction Optimizer (AIO) framework shifts the paradigm from simple prompting to parameter-efficient fine-tuning (PEFT). It utilizes a tunable white-box LLM (e.g., Llama-3) as an "instruction engineer" to generate optimized prompts for a fixed black-box "solver" LLM.
The technical core of AIO consists of three components:
- Gradient Decomposition: The gradient flow is split using the chain rule. Standard backpropagation updates the white-box model, while the black-box component is estimated via ZO methods.
- TS-aided ZO Approximation: To minimize expensive API calls, AIO treats the selection of perturbation directions for gradient estimation as a Contextual Bandit problem. By employing Thompson Sampling (TS), the system reuses feedback from previous queries to prioritize the most promising update directions.
- Task-Aware Fine-Tuning: Unlike generic optimizers, AIO learns from specific black-box feedback on a per-task basis, allowing it to capture deep task nuances that ICL-based methods might miss.
Experimental Setup
AIO was evaluated on a wide array of benchmarks, including 15 tasks from Instruction Induction and BigBench, mathematical reasoning tasks (GSM8K, AQUA, SVAMP), and summarization tasks (SummEdits). The experiments primarily used Llama-3-8B-Instruct as the white-box optimizer and Claude-3-Sonnet as the black-box solver.
Results and Discussion
AIO consistently outperformed strong baselines such as APE and ProTeGi. In zero-shot instruction induction, AIO variants achieved the highest average rankings across 15 diverse tasks. Notably, on the GSM8K math reasoning benchmark, AIO improved accuracy from a 0.724 baseline to 0.862.
Beyond raw performance, AIO demonstrates superior query efficiency. By intelligently navigating the optimization landscape, it significantly reduces the number of tokens required to reach high accuracy compared to traditional ICL-based iterative methods.
Furthermore, the fine-tuned instruction engineer exhibits strong transferability. A model trained on one set of reasoning tasks often performs better on related, unseen tasks without additional tuning, suggesting that the model has learned generalizable "instruction engineering" capabilities.
Conclusion
The Learning to Instruct paradigm, exemplified by AIO, offers a robust and efficient solution for optimizing instructions for black-box LLMs. By combining the learning capacity of white-box models with intelligent zeroth-order optimization, it bridges the gap between manual prompt engineering and fully automated, gradient-based tuning. Future work will explore scaling the optimizer model and integrating human-in-the-loop evaluation to further enhance the interpretability and effectiveness of generated instructions.
Summary updated