AMPO: Automatic Multi-Branched Prompt Optimization

Sheng Yang, Yurong Wu, Yan Gao, Zineng Zhou, Bin Benjamin Zhu, Xiaodi Sun, Jian-Guang Lou, Zhiming Ding, Anbang Hu, Yuan Fang, Yunsong Li, Junyan Chen, Linjun Yang · DOI

Abstract

Traditional automatic prompt optimization (APO) techniques typically treat instructions as a single, linear sequence. This approach often fails on complex, multi-modal tasks where different inputs require distinct reasoning paths. We present AMPO (Automatic Multi-Branched Prompt Optimization), a framework that automatically transforms simple prompts into sophisticated, multi-branched structures using "if-else" logic. By identifying failure patterns and adaptively expanding prompt breadth or depth, AMPO significantly outperforms state-of-the-art optimizers. On the MedQA dataset, AMPO achieves 89.0% accuracy, surpassing previous best methods while requiring 6.4x fewer prompt explorations.

Introduction

Most current APO techniques, such as APO or OPRO, attempt to improve performance by refining a single flow of instructions. While effective for straightforward tasks, this approach struggles with complex data where different inputs necessitate fundamentally different logic. For instance, a medical diagnostic task might require one set of reasoning steps for clinical cases and another for biochemical theory questions. When linear optimizers encounter errors in one mode, their attempts to fix them often cause "regressions" in others. AMPO addresses this by allowing prompts to branch, effectively turning the LLM into a "router" that selects the appropriate logic path for each specific input.

The AMPO Framework

AMPO utilizes three specialized LLM-based agents to iteratively evolve prompts within an optimization loop:

  1. Pattern Recognition: An LLM-Analyzer identifies the root causes of failures, which an LLM-Summarizer then groups into high-level "patterns." This prevents the system from overfitting to noisy edge cases.
  2. Branch Adjustment: An LLM-Revisor updates the prompt by either adding depth (more detail to existing steps) or breadth (creating new "if-else" branches for specific patterns).
  3. Branch Pruning: To maintain efficiency and prevent overfitting, AMPO employs pre-pruning (stopping if performance plateaus) and post-pruning (removing redundant branches).
The iterative workflow of AMPO, featuring pattern recognition, branch adjustment, and pruning.

Unlike methods that rely on expensive tree searches, AMPO uses a minimal search strategy, keeping only the single best prompt per iteration. This efficiency is driven by the quality of its pattern summarization, which guides the search more effectively than raw error logs.

Experimental Evaluation

The researchers evaluated AMPO across five diverse tasks:

  • General NLU: TREC (Question Classification), SST-5 (Sentiment Analysis), and RACE (Reading Comprehension).
  • Medical Domain: MedQA and MedMCQA (USMLE-style exams).

GPT-4-turbo served as the optimizer agent, while both GPT-3.5-turbo and GPT-4-turbo were used as target models.

Results and Discussion

AMPO consistently achieved the highest accuracy across all benchmarks. In the medical domain, AMPO reached 89.00% on MedQA using GPT-4-turbo, a substantial improvement over the 77.00% achieved by the previous state-of-the-art, PromptAgent. In general NLU tasks, it outperformed competitors by up to 3.5%.

The "Router" Effect and Branching Logic

A key insight is that branched structures allow the LLM to act as its own router. By identifying the input category early in the prompt, the model follows the most relevant logic path. Ablation studies confirmed that for complex tasks, increasing prompt breadth (adding branches) is more effective than increasing depth (adding detail).

An example of an AMPO-optimized prompt for a medical task, showing the multi-branched "if-else" logic.

Furthermore, AMPO's focus on pattern summarization creates a "gradient-like" optimization effect that is both cleaner and more generalizable. This targeted approach allowed AMPO to converge much faster than competitors, often showing a steep learning curve after just a single iteration of branching.

Conclusion

AMPO represents a shift from linear to structured prompt engineering. By automatically discovering and branching for diverse data patterns, it provides a robust solution for complex, multi-domain tasks. While it requires a target LLM with strong reasoning capabilities to follow the branched instructions, its efficiency and performance gains make it a powerful tool for advanced prompt optimization.

Summary updated

BibTeX
@misc{yang2024ampo,
  author = {Sheng Yang and Yurong Wu and Yan Gao and Zineng Zhou and Bin Benjamin Zhu and Xiaodi Sun and Jian-Guang Lou and Zhiming Ding and Anbang Hu and Yuan Fang and Yunsong Li and Junyan Chen and Linjun Yang},
  title = {{AMPO: Automatic Multi-Branched Prompt Optimization}},
  year = {2024},
  eprint = {2410.08696},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.08696},
}
Figure