---
title: "Prompt engineering — 提示词工程"
source: "https://systems-analysis.info/int/Prompt_engineering_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%B7%A5%E7%A8%8B"
wiki: "systems-analysis.info/int"
article: "Prompt_engineering_—_提示词工程"
language: "zh"
categories:
  - "Category:Chinese"
  - "Category:Large language models"
  - "Category:Machine learning"
  - "Category:Prompt engineering"
revision_id: 6018
wiki_created_at: 2026-09-06T23:57:13Z
wiki_modified_at: 2026-09-06T23:57:13Z
downloaded_at: 2026-09-07T23:11:34Z
---

# Prompt engineering — 提示词工程

**提示词工程**（Prompt engineering）是一门开发和优化提示词（prompt）的学科，旨在与大型语言模型 (LLM)进行高效交互。提示词的质量直接决定了模型响应的准确性、相关性和安全性。该领域正在迅速发展，从手动调整指令逐步过渡到创建复杂的智能体系统，并利用具备内置推理机制的模型。

## 提示词的基本原则与结构

尽管目前尚无统一标准，但高效的提示词通常基于不同研究者和公司提出的通用方法（例如，OpenAI 的 6 种策略或 Anthropic 的实践指南）构建。

- 一个高效的提示词通常包含以下几个组成部分：
  - 角色 (*Persona*): 为模型设定行为背景和风格（例如：“你是一名资深研究员……”）。
  - 指令 (*Instructions*): 清晰、分步地说明需要完成的任务。
  - 上下文 (*Context*): 执行任务所需的背景信息。
  - 示例 (*Examples*): 展示期望的输出格式或风格（少样本提示，few-shot prompting）。
  - 输出格式 (*Output Format*): 指明响应的结构（例如，JSON、Markdown）。

## Reasoning - 推理能力提升技巧

这些技巧能促使模型进行更结构化的“思考”。*重要提示（涌现性）：\`Chain-of-Thought\`（思维链）技术的效果仅在大型模型（约1000亿参数及以上）上才显著，较小的模型效果不明显甚至可能表现更差。*

- **思维链 (Chain-of-Thought, CoT)**：指示模型在给出最终答案前，生成一步一步的推理过程（“一步一步地思考”）。
- CoT 的变体与替代方案：
  - **自我一致性 (Self-Consistency)**：生成多个推理链，并通过“投票”选择最常见的答案。
  - **思维树 (Tree-of-Thoughts, ToT)**：以树状结构探索多个推理路径，并对每一步进行评估，必要时回溯到之前的步骤。
  - **思维图 (Graph-of-Thought, GoT)**：一种更先进的技术，主要有两种实现方式：一种是将推理过程建模为图，以实现更灵活的逻辑流（Besta 等人）；另一种则侧重于融合不同的推理路径（Yao 等人）。
- **内置推理机制的模型 (Reasoning Models)**：据报道，新一代模型（如 OpenAI 的 *o1* 和 *o3*）在训练时就已内置了内部推理链。这使它们无需明确的 CoT 提示就能执行复杂任务。

## 上下文管理与记忆处理

随着上下文窗口的扩大，新的挑战和解决方案也随之出现。

- **上下文窗口 (2024-2025年)**：

| 模型                        | 最大上下文窗口 |
|-----------------------------|----------------|
| Google Gemini 2.0 Pro       | 200万 token    |
| Google Gemini 1.5 Pro       | 200万 token    |
| Anthropic Claude 3.5 Sonnet | 約20万 token   |
| OpenAI GPT-4o               | 約12.8万 token |

从2025年3月起，Google Gemini 2.5 Pro 推出100万 token 的上下文窗口，而 Pro-Experimental 版本预计在2025年5月达到200万 token。

- **检索增强生成 (Retrieval-Augmented Generation, RAG)**：经典的 RAG 通过从外部数据库检索信息来增强提示词。现代实现方式包括：
  - **GraphRAG**：利用知识图谱提取语义上更相关的知识。
  - **多模态 RAG**：不仅处理文本，还能处理图像、音频和视频。
  - **代理式 RAG (Agentic RAG)**：将 RAG 集成到智能体循环中，由智能体自主决定何时以及检索何种信息。
- **长上下文技术**：为了有效处理大容量窗口，业界采用了多种先进但通常是专有的技术，例如 **Cascading KV Cache** 和 **Infinite Retrieval**。

## 高级技巧：智能体与工具

- 工具使用 (Tool Usage)：
  - **函数调用 (Function Calling)**：模型（如 GPT-4、Claude 3.5）内置的调用外部 API 的能力。
  - **模型上下文协议 (Model Context Protocol, MCP)**：根据一些初步报告（有待证实），一个旨在统一工具 API 的新标准正在开发中，并得到了微软的支持。
- 智能体与框架 (2024-2025年)：
  - **LangChain (v0.3)**：随着 LangChain v0.3 于2024年9月发布，该框架已完全迁移到 Pydantic 2，并根据2024年10月的 EOL 期限停止了对 Python 3.8 的支持。<sup>[\[1\]](https://systems-analysis.info/int/Prompt_engineering_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%B7%A5%E7%A8%8B#cite_note-1)</sup>
  - **AutoGen**：已完全转向基于 actor model 的异步、事件驱动架构。
  - **CrewAI**：一个迅速普及的高性能框架，用于编排多智能体系统。
- No-code 平台：像 AutoGen Studio 这样的工具，允许用户无需编写代码即可创建和配置复杂的智能体。

## 减少幻觉的技巧

幻觉（生成与事实不符的信息）仍然是一个关键问题。截至2024年，主流模型的幻觉率在3%到16%之间，造成的经济损失估计高达数百亿美元。

- **经典方法**：RAG、要求引用来源、调整生成参数（如 temperature、top-p）。
- **现代对齐 (Alignment) 方法**：
  - **宪法 AI (Constitutional AI, CAI)**：由 Anthropic 提出的一种方法，模型通过 AI 生成的反馈来学习遵循一套原则（即“宪法”）。
  - **直接偏好优化 (Direct Preference Optimization, DPO)**：一种比 RLHF 更简单、更高效的替代方案。在多模态视觉语言模型 (VLM) 上的研究（例如用于放射学报告）表明，DPO 可将幻觉减少3至4.8倍。

## 提示词模式：现状

许多模式（如角色 Persona、输出定制 Output Customization）仍然有效。

- **需要重新审视的模式**：
  - **事实核查列表模式 (Fact Check List Pattern)**：已被证明不可靠。模型不擅长通过提示词进行自我事实核查，需要与外部验证系统集成。
- **新模式 (2024-2025年)**：
  - **元提示 (Meta-prompting)**：使用一个 LLM 为另一个 LLM 生成和优化提示词。
  - **专家混合 (Mixture-of-Experts, MoE) 提示词**：创建能够动态调用模型不同“专家”部分的提示词。
  - **多模态模式**：包含文本、图像和其他数据类型的提示词结构，用于处理复杂查询。

## 外部链接

- <a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview" class="external text" rel="nofollow">Anthropic Prompt Engineering Guide</a>
- <a href="https://platform.openai.com/docs/guides/text" class="external text" rel="nofollow">OpenAI Prompt Engineering Guide</a>
- <a href="https://cloud.google.com/discover/what-is-prompt-engineering" class="external text" rel="nofollow">Google's Prompting Guide</a>
- <a href="https://www.promptingguide.ai/zh" class="external text" rel="nofollow">PromptingGuide.ai</a>
- <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-engineering-guidelines.html" class="external text" rel="nofollow">Amazon Bedrock</a>

## 参考文献

- Radford, A. et al. (2019). *Language Models are Unsupervised Multitask Learners*. <a href="https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf" class="external text" rel="nofollow">PDF</a>.
- Brown, T. B. et al. (2020). *Language Models are Few-Shot Learners*. <a href="https://arxiv.org/abs/2005.14165" class="external text" rel="nofollow">arXiv:2005.14165</a>.
- Li, X. L.; Liang, P. (2021). *Prefix-Tuning: Optimizing Continuous Prompts for Generation*. <a href="https://arxiv.org/abs/2101.00190" class="external text" rel="nofollow">arXiv:2101.00190</a>.
- Liu, Y. et al. (2021). *Fantastically Ordered Prompts and Where to Find Them: Overcoming Few-Shot Prompt Order Sensitivity*. <a href="https://arxiv.org/abs/2104.08786" class="external text" rel="nofollow">arXiv:2104.08786</a>.
- Bai, Y. et al. (2022). *Constitutional AI: Harmlessness from AI Feedback*. <a href="https://arxiv.org/abs/2212.08073" class="external text" rel="nofollow">arXiv:2212.08073</a>.
- Kojima, T. et al. (2022). *Large Language Models are Zero-Shot Reasoners*. <a href="https://arxiv.org/abs/2205.11916" class="external text" rel="nofollow">arXiv:2205.11916</a>.
- Wang, X. et al. (2022). *Self-Consistency Improves Chain of Thought Reasoning in Language Models*. <a href="https://arxiv.org/abs/2203.11171" class="external text" rel="nofollow">arXiv:2203.11171</a>.
- Wei, J. et al. (2022). *Chain-of-Thought Prompting Elicits Reasoning in Large Language Models*. <a href="https://arxiv.org/abs/2201.11903" class="external text" rel="nofollow">arXiv:2201.11903</a>.
- Zhang, Z. et al. (2022). *Automatic Chain of Thought Prompting in Large Language Models*. <a href="https://arxiv.org/abs/2210.03493" class="external text" rel="nofollow">arXiv:2210.03493</a>.
- Zhou, D. et al. (2022). *Least-to-Most Prompting Enables Complex Reasoning in Large Language Models*. <a href="https://arxiv.org/abs/2205.10625" class="external text" rel="nofollow">arXiv:2205.10625</a>.
- Besta, M. et al. (2023). *Graph of Thoughts: Solving Elaborate Problems with Large Language Models*. <a href="https://arxiv.org/abs/2308.09687" class="external text" rel="nofollow">arXiv:2308.09687</a>.
- Madaan, A. et al. (2023). *Self-Refine: Iterative Refinement with Self-Feedback*. <a href="https://arxiv.org/abs/2303.17651" class="external text" rel="nofollow">arXiv:2303.17651</a>.
- Rafailov, R. et al. (2023). *Direct Preference Optimization: Your Language Model is Secretly a Reward Model*. <a href="https://arxiv.org/abs/2305.18290" class="external text" rel="nofollow">arXiv:2305.18290</a>.
- Schick, T. et al. (2023). *Toolformer: Language Models Can Teach Themselves to Use Tools*. <a href="https://arxiv.org/abs/2302.04761" class="external text" rel="nofollow">arXiv:2302.04761</a>.
- Wang, Y. et al. (2023). *Self-Instruct: Aligning Language Models with Self-Generated Instructions*. <a href="https://arxiv.org/abs/2212.10560" class="external text" rel="nofollow">arXiv:2212.10560</a>.
- Yao, S. et al. (2023). *Tree of Thoughts: Deliberate Problem Solving with Large Language Models*. <a href="https://arxiv.org/abs/2305.10601" class="external text" rel="nofollow">arXiv:2305.10601</a>.
- Chang, K. et al. (2024). *Efficient Prompting Methods for Large Language Models: A Survey*. <a href="https://arxiv.org/abs/2404.01077" class="external text" rel="nofollow">arXiv:2404.01077</a>.
- Genkina, D. (2024). *AI Prompt Engineering Is Dead*. *IEEE Spectrum*. <a href="https://spectrum.ieee.org/prompt-engineering-is-dead" class="external autonumber" rel="nofollow">[2]</a>.
- Li, Z. et al. (2024). *Prompt Compression for Large Language Models: A Survey*. <a href="https://arxiv.org/abs/2410.12388" class="external text" rel="nofollow">arXiv:2410.12388</a>.
- Liang, X. et al. (2024). *Internal Consistency and Self-Feedback in Large Language Models: A Survey*. <a href="https://arxiv.org/abs/2407.14507" class="external text" rel="nofollow">arXiv:2407.14507</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>.
- Wu, Z. et al. (2025). *The Dark Side of Function Calling: Pathways to Jailbreaking Large Language Models*. *EMNLP 2025*. <a href="https://aclanthology.org/2025.coling-main.39.pdf" class="external text" rel="nofollow">PDF</a>.
- Yang, B. et al. (2025). *Hallucination Detection in Large Language Models with Metamorphic Relations*. <a href="https://arxiv.org/abs/2502.15844" class="external text" rel="nofollow">arXiv:2502.15844</a>.

## 注释

1.  <span id="cite_note-1">[↑](https://systems-analysis.info/int/Prompt_engineering_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%B7%A5%E7%A8%8B#cite_ref-1) 《LangChain v0.3》。 https://python.langchain.com/docs/versions/v0_3/.<a href="https://python.langchain.com/docs/versions/v0_3/" class="external autonumber" rel="nofollow">[1]</a></span>
