Abstract
Designing optimal prompts for Large Language Models (LLMs) is a complicated and resource-intensive task, often requiring substantial human expertise and effort. Existing approaches typically separate the optimization of prompt instructions and in-context learning examples, leading to incohesive prompts that are defined and represented by suboptimal task performance. To overcome these challenges, we propose a novel Cohesive In-Context Prompt Optimization framework that refines both prompt instructions and examples. However, formulating such an optimization in the discrete and high-dimensional space of natural language poses significant challenges in both convergence and computational efficiency. To address these issues, we introduce SEE, a scalable and efficient prompt optimization framework that adopts metaheuristic optimization principles and strategically balances exploration and exploitation to enhance optimization performance and achieve efficient convergence. SEE features a quad-phased design that alternates between global traversal (exploration) and local optimization (exploitation) and adaptively chooses LLM operators during the optimization process. We have conducted a comprehensive evaluation across 35 benchmark tasks, and SEE significantly outperforms state-of-the-art baseline methods by a large margin, achieving an average performance gain of 13.94 while reducing computational costs by 58.67.
Introduction: The Challenge of Prompt Engineering
Prompt engineering has become a critical yet labor-intensive aspect of working with Large Language Models (LLMs). While a well-crafted prompt can significantly enhance model performance, the process of finding the "perfect" prompt remains largely manual and resource-heavy. Existing Automatic Prompt Optimization (APO) tools often suffer from a "separation of concerns" problem: they typically focus on either refining the instruction (zero-shot) or selecting the best in-context examples (few-shot), but rarely both simultaneously.
This separation leads to "incohesive" prompts where the instruction and examples do not complement each other effectively. Furthermore, the search space for natural language is discrete and high-dimensional, making it easy for optimization algorithms to get trapped in local minima—finding a "good enough" prompt while missing the global optimum.
Methodology: The SEE Framework
To address these challenges, we introduce SEE (Strategic Exploration and Exploitation), a framework built on metaheuristic principles designed to find high-quality solutions in complex optimization landscapes. The core of SEE is its quad-phased design, which strategically balances "Exploration" (searching new areas of the prompt space) and "Exploitation" (refining the best prompts found so far).
The Four Phases of Optimization
The SEE framework operates through four distinct phases that alternate between global traversal and local refinement:
- Phase 0: Global Initialization (Exploration): This phase generates a diverse pool of candidate prompts. It utilizes a Lamarckian Operator to "reverse-engineer" instructions from input-output pairs, ensuring a broad starting point.
- Phase 1: Local Feedback Mutation (Exploitation): An "LLM Examiner" identifies mistakes in current prompts, while an "LLM Improver" generates specific remediation strategies to refine them.
- Phase 2: Global Fusion Mutation (Exploration): To avoid local optima, SEE combines traits from high-performing prompts using Crossover and EDA (Estimation of Distribution) operators. This allows the algorithm to "jump" to more promising regions of the search space.
- Phase 3: Local Semantic Mutation (Exploitation): The final phase performs "last-mile" refinements using lexical modifications that preserve semantic meaning while maximizing performance.
Strategic Design Choices
A key innovation in SEE is the use of Performance Vectors and Hamming Distance instead of standard semantic similarity. Rather than measuring how similar prompts sound, SEE analyzes which specific test cases a prompt gets right or wrong. By calculating the Hamming distance between these performance vectors, SEE ensures that fused prompts combine strengths from candidates that fail on different types of problems, thereby maximizing the "genetic diversity" of the prompt pool. Additionally, an Adaptive Phase Stop mechanism automatically transitions between phases based on performance plateaus, preventing unnecessary computational expenditure.
Evaluation and Results
We evaluated SEE across 35 benchmark tasks spanning three domains: Big Bench Hard (BBH) reasoning tasks, NLP detection tasks (e.g., hate speech, fake news), and Instruction Induction tasks.
Key Performance Metrics
- Superior Accuracy: SEE outperformed state-of-the-art baselines (such as APE, APO, and OPRO) by a significant margin, achieving an average performance gain of 13.94 points on difficult BBH tasks.
- Computational Efficiency: Despite its comprehensive four-phase process, SEE reduced computational costs by 58.67% compared to other leading methods.
- Model Agnosticism: While primarily tested with GPT-3.5-turbo, the framework demonstrated consistent gains across GPT-4, Claude 2, and open-source models like Llama-3 and Mistral-7B.
- Human-Readability: Prompts generated by SEE were often more elaborative and "human-understandable" compared to the cryptic outputs of other automated tools.
Discussion and Future Work
The success of SEE highlights that cohesion is king in prompt engineering; instructions and examples must be optimized in harmony. Furthermore, the shift toward mistake-based diversity—fusing prompts based on their failure patterns rather than their linguistic similarity—proves to be a highly efficient strategy for prompt evolution.
While SEE significantly reduces costs, the process still requires multiple iterations and several thousand API calls, which may be a limitation for real-time applications. Future work could involve multi-objective optimization to balance accuracy with factors like prompt brevity, safety, or inference cost, as well as exploring even more robust initialization strategies.
Summary updated