# 第二章 提示工程核心技术

[提示工程（Prompt Engineering）](https://yeasy.gitbook.io/prompt_engineering_guide) 是与 Claude 高效沟通的艺术与科学。一个好的提示词，能让 Claude 的输出质量提升数倍。

> **提示工程 vs 上下文工程**：本章聚焦**单次交互层面**的提示技巧——如何措辞、结构化指令、设计示例和引导推理。这些是与 LLM 协作的基本功。而第十三章介绍的“上下文工程”（Context Engineering）则是**系统架构层面**的实践——如何动态选择、组织和管理提供给模型的全部信息（包括 RAG 检索结果、工具输出、对话历史等）。可以这样理解：提示工程解决“怎么说”，上下文工程解决“给什么”。掌握本章的提示技巧，是迈向上下文工程的必要基础。

***

## 为什么提示工程重要？

同样的模型，不同的提示词，效果天差地别：

```
❌ 差的提示词
"帮我写个代码"

✅ 好的提示词
"请用 Python 编写一个函数，功能是计算斐波那契数列的第 n 项。
要求：
1. 使用递归实现
2. 添加缓存优化性能
3. 包含类型注解
4. 编写 docstring 说明函数用法"
```

提示工程不是“玄学”，而是一套可学习、可复用的技术。

***

## 本章学习目标

完成本章后，你将掌握：

* [ ] 编写清晰、直接、具体的提示词
* [ ] 使用 XML 标签结构化复杂指令
* [ ] 设计高质量的系统提示词
* [ ] 应用少样本学习提升输出质量
* [ ] 使用思维链引导 Claude 逐步推理
* [ ] 精确控制输出格式
* [ ] 调试和优化不理想的提示词

***

## 章节导航

| 章节                                                                           | 主题               | 核心技术      |
| ---------------------------------------------------------------------------- | ---------------- | --------- |
| [2.1](/claude_guide/di-yi-bu-fen-ji-chu-pian/02_prompt/2.1_basics.md)        | 基础原则             | 清晰、直接、具体  |
| [2.2](/claude_guide/di-yi-bu-fen-ji-chu-pian/02_prompt/2.2_xml.md)           | XML 标签           | 结构化复杂指令   |
| [2.3](/claude_guide/di-yi-bu-fen-ji-chu-pian/02_prompt/2.3_system_prompt.md) | 系统提示词            | 角色设定与行为约束 |
| [2.4](/claude_guide/di-yi-bu-fen-ji-chu-pian/02_prompt/2.4_few_shot.md)      | 少样本学习：AI 的“举一反三” | 通过示例引导输出  |
| [2.5](/claude_guide/di-yi-bu-fen-ji-chu-pian/02_prompt/2.5_cot.md)           | 链式思维与逐步推理        | 逐步推理与深度思考 |
| [2.6](/claude_guide/di-yi-bu-fen-ji-chu-pian/02_prompt/2.6_format.md)        | 输出控制             | 格式、长度、风格  |
| [2.7](/claude_guide/di-yi-bu-fen-ji-chu-pian/02_prompt/2.7_optimization.md)  | 调试优化             | 常见问题与解决方案 |

***

## 核心理念

与 Claude 沟通的核心理念可以概括为：

> **把 Claude 当作一个聪明但不了解背景的新同事**

你需要告诉它：

1. **你是谁**（上下文）
2. **你需要什么**（任务）
3. **怎样才算做好**（标准）
4. **有哪些限制**（约束）

***

## 提示工程的 ROI

掌握提示工程的回报是巨大的：

| 投入           | 回报         |
| ------------ | ---------- |
| 10 分钟学习结构化提示 | 避免数小时的来回修改 |
| 5 分钟思考示例设计   | 显著提升首次输出质量 |
| 1 次系统提示词优化   | 整个项目的持续受益  |

***

> 💡 **实践建议**：本章每节都有可运行的示例。建议在 [claude.ai](https://claude.ai) 或 API 中同步实践，加深理解。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/claude_guide/di-yi-bu-fen-ji-chu-pian/02_prompt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
