TL;DR
While Large Language Models (LLMs) are increasingly used to automatically design optimization algorithms, the mechanics of how prompts influence their code generation have largely remained a black box. This paper uses token-wise feature attribution to reveal that code examples within prompts exert the strongest influence on LLM outputs. Leveraging this insight, the authors introduce BAG (Benchmark-Assisted Guided evolutionary approach), a framework that injects prior benchmark algorithms into prompts to systematically guide LLMs toward superior performance in black-box optimization.
What Problem Does This Paper Address?
Automated Algorithm Design (AAD) aims to automatically construct or configure optimization algorithms. Recently, LLMs have taken AAD to a new level by directly generating and evolving algorithmic code through iterative prompting loops. However, most existing frameworks rely on intuitive, trial-and-error prompt engineering (e.g., blindly instructing the LLM to "create a novel algorithm"). This raises concerns about the reliability, efficiency, and robustness of LLM-driven optimization.
Furthermore, applying LLMs to Black-Box Optimization (BBO)—where the internal structure of the objective function is completely unknown—presents a strict constraint: the prompt cannot expose problem names or metadata without violating the black-box assumption. The authors set out to understand exactly how different prompt components affect LLM code generation and how to rigorously guide LLMs under strict black-box conditions.
Methods
The authors tackle the problem in two phases: analysis and framework design.
- Relevance Analysis (AttnLRP & CodeBLEU): To uncover what LLMs actually pay attention to, the authors apply AttnLRP, an attention-aware feature attribution method, to compute token-to-token relevance scores between input prompts and generated code. They also use CodeBLEU to track the structural and semantic similarity between ancestral benchmark codes and newly evolved heuristics over time.
- The BAG Framework: Armed with the insight that code examples dominate LLM behavior, the authors propose BAG (Algorithm 1). Operating on a simple $(1+1)$ elitist evolutionary strategy, BAG maintains a benchmark set of established algorithms ($A_{bench}$).
Instead of relying purely on random initialization or linguistic instructions, BAG initializes the prompt with a high-quality benchmark code example. During the evolutionary loop, it alternates between refining the current best-found algorithm and injecting a randomly selected algorithm from $A_{bench}$ every $q$ iterations to maintain diversity and prevent the LLM from getting trapped in a local algorithmic neighborhood.
Datasets
The framework was evaluated across two widely accepted black-box optimization benchmark suites:
- pbo (pseudo-Boolean optimization suite): Consists of 23 discrete, 100-dimensional pseudo-Boolean optimization problems (e.g., OneMax, LeadingOnes, Ising models).
- bbob (black-box optimization suite): Consists of 24 continuous, 5-dimensional optimization problems (e.g., Sphere, Rosenbrock, Rastrigin functions).
Testing spanned 235 distinct problem instances across three state-of-the-art LLM families: Google's Gemini 2.5 Flash-Lite, OpenAI's GPT 5 Nano, and Alibaba's Qwen3 Coder Flash.
Key Insights and Ideas
- Code Over Text: The token-wise attribution analysis (via AttnLRP) revealed that the embedded code examples and their immediate strategy instructions have a vastly superior impact on the generated code compared to natural language task descriptions or historical performance scores.
- Prompts as Search Anchors: Providing a specific code example effectively acts as a neighborhood constraint. It anchors the LLM's generative behavior, transforming code generation into a localized neighborhood search rather than a chaotic, unconstrained global sampling.
- Efficiency Gains: Injecting strong priors allows the framework to be highly sample-efficient. BAG requires only a single LLM query per iteration to propose a valid candidate, whereas competing methods like Evolution of Heuristics (EoH) rely on up to five prompts per candidate generation.
Key Results
BAG consistently outperformed or matched six state-of-the-art LLM-driven optimization baselines (including EoH, LLaMEA, ReEvo, and ShinkaEvolve).
- Continuous Optimization (bbob): BAG demonstrated massive advantages, achieving an average 14% improvement in normalized Area Under the ECDF Curve (AUC) over the second-best baseline across all three tested LLMs.
- Discrete Optimization (pbo): BAG ranked first when using Gemini and Qwen, and second when using GPT (trailing EoH by a mere 0.5% margin despite using significantly fewer queries).
Limitations and Future Work
While BAG proves the power of strong code priors, it currently operates under a basic $(1+1)$ elitist search strategy. The authors note that integrating these benchmark priors into a more complex, population-based framework could unlock even greater diversity and search efficiency. Additionally, the benchmark set ($A_{bench}$) used in this study was static and drawn from a limited pool; future iterations could benefit from dynamically integrating massive, open-ended algorithm repositories like Nevergrad.
Summary updated