AMPO: Automatic Multi-Branched Prompt Optimization

Yurong Wu

Abstract

Prompt engineering is very important to enhance the performance of large language models (LLMs). When dealing with complex issues, human experts tend to distill multiple patterns from data and inject relevant solutions to optimize the prompts, achieving satisfying results. However, existing automatic prompt optimization techniques are only limited to producing single flow instructions, struggling with handling diverse patterns. In this paper, we present AMPO, an automatic prompt optimization method that can iteratively develop a multi-branched prompt using failure cases as feedback. Our goal is to explore a novel way of structuring prompts with multi-branches to better handle multiple patterns in complex tasks, for which we introduce three modules: Pattern Recognition, Branch Adjustment, and Branch Pruning. In experiments across five tasks, AMPO consistently achieves the best results. Additionally, our approach demonstrates significant optimization efficiency due to our adoption of a minimal search strategy.

Introduction

Prompt engineering is the art of coaxing the best performance out of Large Language Models (LLMs). While automatic prompt optimization (APO) tools exist, they typically produce a single, linear sequence of instructions. This "one-size-fits-all" approach struggles with complex tasks where different inputs require fundamentally different reasoning paths—such as medical diagnosis, where a clinical scenario requires a different logic than a biochemical experiment.

Human experts handle this complexity by distilling patterns and creating conditional strategies. AMPO addresses this by structuring prompts more like a decision tree than a simple list, allowing for adaptive "if-else" logic within the model's instructions.

The AMPO Framework

AMPO introduces an iterative framework that transforms a simple initial prompt into a sophisticated multi-branched structure using three core modules:

  1. Pattern Recognition: When the model fails on a task, an LLM-Analyzer identifies the root causes of the errors. An LLM-Summarizer then groups these individual errors into broader "patterns" and assigns them importance scores. This prevents the prompt from becoming a cluttered list of fixes for specific examples.
  2. Branch Adjustment: An LLM-Revisor takes the top-scoring patterns and decides how to update the prompt. It chooses between depth (adding more detail to an existing instruction) or breadth (creating a new branch/conditional statement to handle a specific pattern).
  3. Branch Pruning: To prevent the prompt from becoming overly complex and "overfitting" to the training data, AMPO uses both pre-pruning (stopping growth if validation performance plateaus) and post-pruning (having the LLM review and delete redundant or non-generalizable branches).
The iterative workflow of AMPO, featuring Pattern Recognition, Branch Adjustment, and Branch Pruning modules.

Crucially, AMPO uses a minimal search strategy. Unlike methods that explore hundreds of prompt variations (like Monte Carlo Tree Search), AMPO focuses on the most critical patterns, making it highly efficient.

Experimental Evaluation

The researchers evaluated AMPO across five diverse tasks categorized into two domains:

  • General NLU: SST-5 (sentiment analysis), TREC (question classification), and RACE (reading comprehension).
  • Domain Knowledge (Biomedical): MedQA and MedMCQA (medical multiple-choice questions).

These datasets represent varying levels of complexity, with the medical tasks requiring significant domain-specific reasoning and pattern recognition.

Key Results and Efficiency

AMPO consistently achieved the highest accuracy across all tested tasks and models (GPT-3.5-turbo and GPT-4-turbo). In the complex MedQA task using GPT-4-turbo, AMPO reached 89.00% accuracy, a 5.75% improvement over the next best method (APO).

Beyond raw accuracy, AMPO demonstrates significant optimization efficiency. By retaining only the single best prompt per iteration and focusing on high-quality error analysis, it avoids the computational overhead of complex tree-search methods.

Accuracy vs. the number of explored prompts across different tasks. AMPO achieves high accuracy with significantly fewer explored prompts compared to baseline methods.

As illustrated in the figure above, AMPO (red and green markers) consistently occupies the high-accuracy, low-exploration region of the performance space. Compared to PromptAgent, AMPO achieved better results while exploring 6.4x fewer prompts. Compared to APO, it was 48x more efficient in terms of the number of prompts generated during optimization.

Conclusion

AMPO demonstrates that LLMs perform significantly better when explicitly guided to categorize problems before solving them. By summarizing errors into patterns and adaptively scaling prompt complexity, AMPO provides a robust framework for handling diverse data distributions. Future work will explore integrating this branching logic with other techniques like Chain-of-Thought (CoT) to further enhance reasoning capabilities.

Summary updated

BibTeX
@misc{wu2024ampo,
  author = {Yurong Wu},
  title = {{AMPO: Automatic Multi-Branched Prompt Optimization}},
  year = {2024},
  eprint = {2410.08696},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.08696},
}
Figure