---
title: "Automatic Prompt Engineer (APE) — 自动化提示工程 (APE)"
source: "https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)"
wiki: "systems-analysis.info/int"
article: "Automatic_Prompt_Engineer_(APE)_—_自动化提示工程_(APE)"
language: "zh"
categories:
  - "Category:Chinese"
  - "Category:Large language models"
  - "Category:Machine learning"
  - "Category:Prompt engineering"
revision_id: 503
wiki_created_at: 2026-09-06T22:34:41Z
wiki_modified_at: 2026-09-06T22:34:41Z
downloaded_at: 2026-09-07T22:40:33Z
---

# Automatic Prompt Engineer (APE) — 自动化提示工程 (APE)

**自动化提示工程**（**APE**，Automatic Prompt Engineer）是一种用于自动生成和优化文本指令（提示词）的方法，旨在控制大型语言模型 (LLM)的行为。该方法由**周永超**（*Yongchao Zhou*）领导的研究团队于2022年提出<sup>[\[1\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-ape_zhou_2022-1)</sup>。

APE 方法不采用手动选择和迭代改进提示词的方式，而是将提示工程形式化为一个优化问题。在此任务中，提示词被视为一种自然语言“程序”，需要通过合成来最大化某个质量函数（例如，模型回答的准确性或真实性）<sup>[\[2\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-survey_li_2025-2)</sup>。

## 基本概念与方法

APE 方法结合使用两种语言模型：*生成模型*和*目标模型*。该过程是一个迭代的搜索与选择（*search-and-select*）循环：

1.  **候选生成**。生成模型接收若干目标任务的“输入-输出”对作为示例，并基于这些示例创建大量可能的候选提示词。
2.  **评估**。每个生成的候选提示词被传递给目标 LLM。目标模型在一组新的测试数据上执行指令，其回答根据预定义的指标（如准确率、完整度、F1 分数）进行评估。
3.  **选择**。选择在评估中表现最佳的提示词。
4.  **迭代（可选）**。循环可以重复。生成模型接收到改进最佳提示词的指令，为其创建变体，然后重复评估和选择过程，以达到最高效率<sup>[\[1\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-ape_zhou_2022-1)</sup>。

这种方法能够自动复现手动调整提示词的过程，利用 LLM 生成假设（提示词）并对其进行后续评估。

## 关键方法论

提示工程的自动化通过多种算法方法实现。

### 基于 LLM 的自动化

这是上文描述的经典 APE 方法，其中一个 LLM 用于为另一个（或同一个）LLM 生成和评估提示词。这种方法对于离散的文本提示词非常有效<sup>[\[1\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-ape_zhou_2022-1)</sup>。

### 演化方法

使用遗传算法或集束搜索（beam search）来创建和选择提示词，特别是长而复杂的提示词。例如，**APEX**（*Automatic Engineering of Long Prompts*）框架应用演化算法来逐步“培育”和改进复杂的指令<sup>[\[3\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-apex_hsieh_2024-3)</sup>。

### 梯度方法 (Soft Prompts)

这种方法处理*连续*或*软*提示词（*soft prompts*），它们是可训练的向量（嵌入），而不是文本指令。这些向量通过梯度下降直接在目标任务上进行优化。这包括 Prompt Tuning 和 Prefix-Tuning 等技术。

### 强化学习

在此范式中，LLM 扮演代理（agent）的角色，生成提示词（动作），而环境则返回对回答质量的评估（奖励）。目标是通过强化学习（RL）方法找到最优的提示词生成策略，以最大化累积奖励<sup>[\[2\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-survey_li_2025-2)</sup>。

## 结果与发现

APE 原始研究中的实验表明，自动生成的指令在大多数情况下优于人类编写的提示词。

- 在对 24 个自然语言处理（NLP）任务的测试中，APE 生成的提示词在 **24 个案例中的 19 个** 都比人类编写的更有效<sup>[\[1\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-ape_zhou_2022-1)</sup>。
- APE 能够自动“发现”一种更有效的思维链（Chain-of-Thought）风格的提示词表述。APE 没有使用标准的“*Let's think step by step*”（让我们一步一步地思考），而是生成了一个更详尽、更有效的指令：“*Let's work this out in a step by step way to be sure we have the right answer*”（让我们一步一步地解决这个问题，以确保我们得到正确的答案）。这种表述提高了在 MultiArith 和 GSM8K 等数据集上解决数学问题的准确性<sup>[\[1\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-ape_zhou_2022-1)</sup>。

## 应用与优势

### 应用

- **改进 few-shot learning**：自动选择最佳示例和指令。
- **提高模型的可信度**：可配置 APE 来寻找能最小化“幻觉”并在 *TruthfulQA* 等基准测试上最大化回答真实性的提示词。
- **自动化开发**：加速聊天机器人、信息提取系统及其他 LLM 应用的开发<sup>[\[4\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-mdpi_app-4)</sup>。

### 优势

- **可扩展性**：能够自动生成并评估成百上千个提示词，无需人工干预。
- **适应性**：轻松将 LLM 调整到新的、高度专业化的领域。
- **节约资源**：显著减少手动选择提示词所花费的时间和精力。

## 发展与相关方法

APE 的概念在不断发展。出现了像 **APET**（*Automatic Prompt Engineering Toolbox*）这样的完全自主系统，它允许 LLM（例如 GPT-4）独立应用复杂的提示策略（*Expert Prompting*、*Chain of Thought*、*Tree of Thoughts*），并在没有外部干预的情况下动态改进指令<sup>[\[5\]](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_note-apet_kepel_2024-5)</sup>。

APE 是自动化与 LLM 交互这一更广泛趋势的一部分，该趋势还包括：

- **AutoPrompt**：一种早期方法，使用基于梯度的搜索来寻找特定的“触发”词元（token）。
- **OPRO** (*Optimization by PROmpting*): 由 DeepMind 提出的一种与 APE 类似的方法，也利用 LLM 来优化提示词。

## 外部链接

- <a href="https://sites.google.com/view/automatic-prompt-engineer" class="external text" rel="nofollow">Automatic Prompt Engineer (APE) 项目官方网站</a>
- <a href="https://arxiv.org/abs/2211.01910" class="external text" rel="nofollow">学术论文《Large Language Models Are Human-Level Prompt Engineers》</a>
- AutoPrompt (2020). *AutoPrompt – Official GitHub Repository*. <a href="https://github.com/ucinlp/autoprompt" class="external text" rel="nofollow">GitHub</a>。

## 参考文献

- Zhou, Y. et al. (2022). *Large Language Models Are Human-Level Prompt Engineers*. <a href="https://arxiv.org/abs/2211.01910" class="external text" rel="nofollow">arXiv:2211.01910</a>.
- Li, W. et al. (2025). *A Survey of Automatic Prompt Engineering: An Optimization Perspective*. <a href="https://arxiv.org/abs/2502.11560" class="external text" rel="nofollow">arXiv:2502.11560</a>.
- Hsieh, C.-J. et al. (2024). *Automatic Engineering of Long Prompts*. Findings of ACL 2024. <a href="https://aclanthology.org/2024.findings-acl.634" class="external text" rel="nofollow">2024.findings-acl.634</a>.
- Hsieh, C.-J. et al. (2023). *Automatic Long Prompt Engineering*. <a href="https://arxiv.org/abs/2311.10117" class="external text" rel="nofollow">arXiv:2311.10117</a>.
- Shin, T. et al. (2020). *AutoPrompt: Eliciting Knowledge from Language Models with Automatically Generated Prompts*. <a href="https://arxiv.org/abs/2010.15980" class="external text" rel="nofollow">arXiv:2010.15980</a>.
- Yang, C. et al. (2023). *Large Language Models as Optimizers (OPRO)*. <a href="https://arxiv.org/abs/2309.03409" class="external text" rel="nofollow">arXiv:2309.03409</a>.
- Liu, Y. et al. (2024). *Revisiting OPRO: The Limitations of Small-Scale LLMs as Optimizers*. <a href="https://arxiv.org/abs/2405.10276" class="external text" rel="nofollow">arXiv:2405.10276</a>.
- Kepel, D.; Valogianni, K. (2024). *Autonomous Prompt Engineering in Large Language Models (APET)*. <a href="https://arxiv.org/abs/2407.11000" class="external text" rel="nofollow">arXiv:2407.11000</a>.
- Yang, C. et al. (2024). *Optimizing Instructions and Demonstrations for Multi-Stage LM Programs*. <a href="https://arxiv.org/abs/2406.11695" class="external text" rel="nofollow">arXiv:2406.11695</a>.
- Hsieh, C.-J. et al. (2024). *APEX (code repository and results)*. <a href="https://aclanthology.org/2024.findings-acl.634.pdf" class="external text" rel="nofollow">PDF</a>.

## 注释

1.  <span id="cite_note-ape_zhou_2022-1">↑ <sup>[1.0](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-ape_zhou_2022_1-0)</sup> <sup>[1.1](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-ape_zhou_2022_1-1)</sup> <sup>[1.2](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-ape_zhou_2022_1-2)</sup> <sup>[1.3](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-ape_zhou_2022_1-3)</sup> <sup>[1.4](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-ape_zhou_2022_1-4)</sup> Zhou, Y. et al. «Large Language Models Are Human-Level Prompt Engineers». *arXiv:2211.01910*, 2022. <a href="https://arxiv.org/abs/2211.01910" class="external autonumber" rel="nofollow">[1]</a></span>
2.  <span id="cite_note-survey_li_2025-2">↑ <sup>[2.0](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-survey_li_2025_2-0)</sup> <sup>[2.1](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-survey_li_2025_2-1)</sup> Li, W. et al. «A Survey of Automatic Prompt Engineering: An Optimization Perspective». *arXiv:2502.11560*, 2025. <a href="https://arxiv.org/abs/2502.11560" class="external autonumber" rel="nofollow">[2]</a></span>
3.  <span id="cite_note-apex_hsieh_2024-3">[↑](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-apex_hsieh_2024_3-0) Hsieh, C.-J. et al. «Automatic Engineering of Long Prompts». *Findings of the Association for Computational Linguistics: ACL 2024*. <a href="https://aclanthology.org/2024.findings-acl.634/" class="external autonumber" rel="nofollow">[3]</a></span>
4.  <span id="cite_note-mdpi_app-4">[↑](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-mdpi_app_4-0) Fernandez-garcia, A. et al. «Automatic Prompt Engineering for Foundation Models: A Survey». *MDPI Electronics*, 2025. <a href="https://www.mdpi.com/2079-9292/14/11/2145" class="external autonumber" rel="nofollow">[4]</a></span>
5.  <span id="cite_note-apet_kepel_2024-5">[↑](https://systems-analysis.info/int/Automatic_Prompt_Engineer_(APE)_%E2%80%94_%E8%87%AA%E5%8A%A8%E5%8C%96%E6%8F%90%E7%A4%BA%E5%B7%A5%E7%A8%8B_(APE)#cite_ref-apet_kepel_2024_5-0) Kepel, D. & Valogianni, K. «Autonomous Prompt Engineering in Large Language Models». *arXiv:2407.11000*, 2024. <a href="https://arxiv.org/abs/2407.11000" class="external autonumber" rel="nofollow">[5]</a></span>
