Tree-of-Prompts: Abstracting Control-Flow for Prompt Optimization

Jihyuk Kim, Shubham Garg, Lahari Poddar, Seung-won Hwang, Chris HenchACL 2025

Abstract

Prompt Optimization (PO) is a critical process for enhancing the performance of Large Language Models (LLMs) on specific tasks. Current PO methodologies generally fall into two categories: iterative sequential refinement, which excels at handling task complexity, and conditional branching, which manages disjoint logic. However, real-world applications often demand both. We introduce Tree-of-Prompts (ToP), a framework that models prompt optimization as a Control Flow Graph (CFG). ToP organizes prompts into a hierarchical tree structure where sibling nodes address disjoint cases and child nodes provide iterative refinements. By utilizing solution-based clustering and case-augmented search, ToP dynamically selects the most appropriate "expert" prompt for a given input. Our evaluation across benchmarks such as Gorilla, MATH, and Big-Bench-Hard shows that ToP consistently outperforms existing state-of-the-art methods, particularly for smaller models and complex reasoning scenarios.

Introduction

The effectiveness of Large Language Models (LLMs) is highly sensitive to the quality of the provided prompts. Automated Prompt Optimization (PO) aims to alleviate the manual effort of prompt engineering by iteratively refining instructions based on performance feedback. Despite recent progress, existing PO techniques are often limited in their scope. Iterative sequential methods, like PromptAgent, focus on deepening reasoning but can become biased toward majority cases. Conversely, conditional methods, such as Mixture-of-Prompts (MoP), handle diverse inputs well but lack the depth needed for multi-step problems.

The Tree-of-Prompts Framework

To bridge this gap, we propose Tree-of-Prompts (ToP). This framework treats prompt optimization as the construction of a Control Flow Graph (CFG), allowing for a sophisticated blend of iterative and conditional logic.

Conceptual comparison of prompt optimization paradigms: (a) Iterative Sequential, (b) Conditional, and (c) the proposed Tree-of-Prompts composition.

Core Components

  1. Hierarchical Tree Structure: ToP recursively expands prompts into a tree. Sibling prompts are designed to handle disjoint subsets of the data (e.g., answerable vs. unanswerable questions), while child prompts inherit and refine the instructions of their parents. This inheritance ensures that foundational task knowledge is preserved while specific edge cases are addressed.
  2. Solution-based Clustering: Unlike traditional methods that cluster inputs based on semantic text similarity, ToP clusters examples based on the prompts that successfully solve them. This ensures that inputs requiring similar reasoning strategies are grouped together, regardless of their surface-level textual features.
  3. Case-Augmented Search: At inference time, a dedicated "Search LLM" analyzes the input to identify key factors and selects the most suitable expert prompt from the optimized tree.
The Tree-of-Prompts architecture, illustrating the recursive generation of specialized prompts (p1, p3, p4) from a root prompt (p0).

Experimental Evaluation

We evaluated ToP against three diverse benchmarks:

  • Gorilla: Tests API function calling capabilities.
  • MATH: A collection of challenging competition-level mathematics problems.
  • Big-Bench-Hard (BBH): A suite of tasks requiring complex reasoning, such as temporal sequences and causal judgment.

Key Results

ToP demonstrated superior performance across various model sizes and task types:

  • Model Agnostic Gains: Using GPT-4o-mini, ToP improved performance by 1.4% over PromptAgent and 3.2% over MoP. The benefits were more pronounced for smaller models like Llama 3.2-3B, with gains of approximately 4.5% over both baselines.
  • Handling Complexity and Disjointness: On the MATH dataset, ToP excelled in "Hard" categories (Levels 4-5) where iterative refinement is crucial. In the Gorilla benchmark, it successfully balanced "Answerable" and "Unanswerable" cases, avoiding the bias common in single-prompt methods.

Insights and Discussion

A key finding of our work is that semantic similarity is often a poor proxy for reasoning requirements. Visualization of solution-based embeddings showed much clearer separation of task logic compared to standard text-based clustering. Furthermore, the tree-based inheritance model allows for more robust "expert" prompts that do not need to relearn basic task constraints.

Conclusion

Tree-of-Prompts offers a structured and scalable approach to prompt optimization by abstracting control flow. By combining the strengths of iterative refinement and conditional branching, ToP provides a more comprehensive solution for complex, real-world LLM applications. Future work will explore multi-objective optimization and managing deeper tree hierarchies for even more intricate tasks.

Summary updated

BibTeX
@inproceedings{kim2025tree,
  author = {Jihyuk Kim and Shubham Garg and Lahari Poddar and Seung-won Hwang and Chris Hench},
  title = {{Tree-of-Prompts: Abstracting Control-Flow for Prompt Optimization}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure