NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

HiFo-Prompt: Prompting with Hindsight and Foresight for LLM-based Automatic Heuristic Design

ChentongChen, Mengyuan Zhong, Jialong Shi, Jianyong Sun, Ye Fan

TL;DR

HiFo-Prompt is a new framework that transforms Large Language Models (LLMs) from passive code generators into active "reasoners" for designing optimization algorithms. By combining a high-level meta-controller (Foresight) to steer search dynamics and a persistent knowledge base (Hindsight) to store distilled design principles, it consistently outperforms state-of-the-art methods across complex tasks like the Traveling Salesman Problem with significantly higher query efficiency.

What Problem Does This Paper Address?

Designing "heuristics"—the rules of thumb used to solve complex Combinatorial Optimization (CO) problems—has traditionally been a manual, labor-intensive process for human experts. Recently, researchers have started using LLMs paired with Evolutionary Computation (EC) to automate this. In this "LLM+EC" paradigm, the LLM acts as a mutation operator, tweaking code over several generations to find better solutions.

However, the authors identify two major "blind spots" in current approaches:

  1. Lack of Global Control: Most methods are reactive, looking only at a single candidate solution. They can’t "see" the big picture of the population, leading to issues like stagnation (getting stuck) or diversity collapse (everyone finding the same mediocre solution).
  2. Knowledge Decay: When a piece of code is discarded in an evolutionary loop, the "why" behind its success is often lost. The system fails to build a cumulative understanding of what makes a good algorithm, essentially "rediscovering the wheel" every few generations.

Methods

The authors introduce HiFo-Prompt (Hindsight-Foresight Prompt), a hierarchical architecture that adds two core modules to the LLM-driven design process.

HiFo-Prompt Architecture
  • Foresight (The Evolutionary Navigator): This acts as a project manager. It monitors the "health" of the population by tracking performance trends and phenotypic diversity (how different the code implementations actually are). Based on these metrics, it injects "verbal gradients"—natural language instructions—into the prompt to switch the LLM between three regimes: Explore (try something wild), Exploit (refine what works), or Balance.
  • Hindsight (The Insight Pool): This is the system's memory. Instead of just saving code, it asks the LLM to distill abstract, generalizable "insights" from successful heuristics. These insights are stored in a pool and retrieved using a utility function that balances effectiveness, how recently they were used, and a penalty for overusing the same idea.
  • Composite Prompting: Every time the LLM is asked to generate a new heuristic, it receives a "Composite Prompt" that includes foundational strategies (like crossover or mutation), the current strategic directive from Foresight, and the most relevant lessons learned from Hindsight.

Datasets

The framework was evaluated on several classic, NP-hard optimization benchmarks:

  • Traveling Salesman Problem (TSP): Tested on both step-by-step construction and Guided Local Search (GLS) using the standard TSPLib dataset.
  • Online Bin Packing Problem (Online BPP): Evaluated using Weibull-distributed instances, which are more representative of real-world scenarios than simple uniform distributions.
  • Flow Shop Scheduling Problem (FSSP): Tested on the well-known Taillard instances.
  • Bayesian Optimization (BO): Used to design cost-aware acquisition functions across standard synthetic benchmarks like Ackley and Rastrigin.

Key Insights and Ideas

  • Decoupling Thoughts from Code: One of the most powerful ideas here is that "insights" are more valuable than the code itself. By distilling principles into natural language, the system creates a "symbolic" knowledge base that is much easier for an LLM to build upon than raw Python scripts.
  • Verbal Gradients vs. Numerical Gradients: Instead of expensive fine-tuning or complex math to steer the LLM, the authors use "verbal gradients." Simply telling the LLM "the population is stagnating, try a significantly different approach" acts as a highly effective control signal.
  • Phenotypic Diversity Matters: The authors argue that looking at fitness (how well the code performs) isn't enough to judge diversity. They use exact string matching on standardized code templates to ensure the logic of the algorithms remains diverse, preventing the search from narrowing too early.

Key Results

HiFo-Prompt achieved state-of-the-art (SOTA) results across the board.

TSP Benchmark Results
  • Superior Performance: In TSP construction tasks, HiFo-Prompt reduced the performance gap to the optimal solution to 6.625% (on TSP50), significantly beating previous SOTA methods like ReEvo (10.239%) and EoH (12.820%).
  • High Efficiency: The system is remarkably "sample efficient," often finding superior heuristics with only 200 LLM requests, whereas other methods might require thousands.
  • Robustness: The framework proved adaptable across different LLMs, including Qwen-2.5-Max, GPT-4o-mini, and Claude-3.5-Sonnet, showing that the methodology of Foresight and Hindsight is more important than the specific model used.

Limitations and Future Work

  • Static Navigator Logic: Currently, the "Foresight" module uses a rule-based system with fixed thresholds for stagnation and diversity. The authors suggest that this meta-controller could itself be learned via Reinforcement Learning in the future.
  • Intra-task Knowledge: The "Hindsight" pool currently resets for each new problem type. A promising next step is inter-task knowledge transfer, where insights gained from solving TSP could help the LLM solve Bin Packing or Scheduling problems more effectively.
  • Generalizability: While it works well on the tested benchmarks, the authors note that the true generalizability of distilled insights across vastly different problem domains remains an open question.

Summary updated

BibTeX
@inproceedings{chentongchen2026hifo,
  author = {ChentongChen and Mengyuan Zhong and Jialong Shi and Jianyong Sun and Ye Fan},
  title = {{HiFo-Prompt: Prompting with Hindsight and Foresight for LLM-based Automatic Heuristic Design}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=imSLzfZ6av},
}
Figure