TL;DR:Prompt Engineering 是"写好一句话",Context Engineering 是"组装好一次输入",Harness Engineering 是"设计好一整个跑 Agent 的环境"。三者不是替代关系,而是从 2022 年到 2025 年逐层叠加的演进路径——做 ChatBot 只用第一层,做 RAG 助手要加第二层,做 Claude Code / Cursor 这类 Agent 三层都得做。


一、定义:三个工程到底是什么

工程一句话定义关心的核心问题来源
Prompt Engineering设计单次给模型的指令(特别是 System Prompt)"怎么把一句话写好"2022 GPT-3 时代
Context Engineering在每次 LLM 推理时,策展出最优的 token 集合"这次调用要塞哪些信息进去"Anthropic 2025 官方提出
Harness Engineering设计模型外部的 scaffolding(脚手架):循环、工具、沙箱、解析、重试"怎么让模型能持续工作、跟真实世界交互"METR / Anthropic Agent 论文

Prompt Engineering(提示工程)

聚焦点很窄——"how to write effective prompts, particularly system prompts"。它适合一次性任务(one-shot):写文案、做翻译、生成结构化 JSON。在 ChatGPT 3.5 时代是绝对主角。

Context Engineering(上下文工程)

Anthropic 在 2025 年 9 月的官方文章里给的定义是:

"the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference, including all the other information that may land there outside of the prompts."

通俗讲:模型在推理时它的上下文窗口里出现的 所有 东西——System prompt、工具定义、MCP 数据、历史消息、检索结果、用户消息——你都要负责安排。Philipp Schmid 的定义更工程化:

"the discipline of designing and building dynamic systems that provides the right information and tools, in the right format, at the right time."

七大组件:System Prompt / User Prompt / State & History / Long-Term Memory / Retrieved Information (RAG) / Available Tools / Structured Output。

Harness Engineering(执行环境工程)

Anthropic 在 SWE-bench 论文里直接把 Agent 定义为:

"the combination of an AI model and the software scaffolding around it."

这层 scaffolding 包括:

  1. Prompt 生成器 — 把任务变成模型输入
  2. 输出解析器 — 把模型回复变成可执行动作
  3. 交互循环管理 — 把每一步的执行结果回灌到下一轮 prompt
  4. 工具集合 — Bash、Edit、Web Fetch 等
  5. 采样循环(sampling loop) — 持续运行直到模型决定结束或上下文耗尽

Anthropic 在 SWE-bench 论文中强调:"agent performance on benchmarks varies significantly based on scaffolding quality, even with identical underlying models"——同一个模型,harness 不同,得分差距可以非常大。


二、三层的关系:从一句话到一套系统

┌─────────────────────────────────────────────────┐
│  Harness Engineering                            │
│  ├─ 循环 / 工具 / 沙箱 / 解析 / 重试 / 权限      │
│  │                                              │
│  │   ┌───────────────────────────────────────┐ │
│  │   │  Context Engineering                  │ │
│  │   │  ├─ System / Tools / RAG / History    │ │
│  │   │  │                                    │ │
│  │   │  │   ┌─────────────────────────────┐ │ │
│  │   │  │   │  Prompt Engineering         │ │ │
│  │   │  │   │  ├─ 这一条 System Prompt    │ │ │
│  │   │  │   │  └─ 这一句 User Prompt      │ │ │
│  │   │  │   └─────────────────────────────┘ │ │
│  │   │  └───────────────────────────────────┘ │
│  │   └───────────────────────────────────────┘ │
│  └───────────────────────────────────────────── │
└─────────────────────────────────────────────────┘

关键认知

  • Prompt Engineering 是 Context Engineering 的子集(写好的 prompt 只是众多 token 之一)
  • Context Engineering 是 Harness Engineering 在 单次推理 这个时间切片上的快照
  • Harness Engineering 关心的是 跨多轮、跨多个工具调用 的整体系统

Anthropic 官方原话总结得很精准:"prompt engineering is discrete task-focused work, while context engineering is iterative, happening each time an engineer decides what information to pass to the model."


三、演进时间线

年份主流范式代表产品工程焦点
2022Prompt EngineeringChatGPT / Jasper / Copy.ai怎么写 prompt
2023+ RAGLangChain / LlamaIndex怎么塞知识进 prompt
2024Context EngineeringCursor / Devin v0 / Dify怎么管理 token 预算
2025Harness EngineeringClaude Code / Cursor Composer / OpenHands怎么设计 Agent 跑得稳

为什么会演进:模型能力越来越强、上下文窗口越来越大(200k+)、外部工具越来越多(MCP 生态),导致 "塞什么、什么时候塞、塞完怎么用""怎么写" 重要得多。

Philipp Schmid 一句话点穿:"Agent failures aren't only model failures; they are context failures."——Agent 跑挂了,多数情况下不是模型蠢,是上下文塞错了或 harness 设计漏了。


四、各层最佳实践

Prompt Engineering 最佳实践

  1. 角色+任务+约束+示例 四要素齐全
  2. System Prompt 控制风格,User Prompt 表达意图
  3. 结构化输出 用 JSON Schema / XML 标签
  4. 少样本学习(Few-shot)放典型示例而非边角案例

Context Engineering 最佳实践

Anthropic 官方文章列出的核心原则是:找到 "the smallest possible set of high-signal tokens that maximize the likelihood of some desired outcome"——用最少的高信号 token。

具体 7 个技巧:

技巧说明
System Prompt 精校不写废话,每一行问"删掉这行 Claude 会不会犯错"
Token-efficient tools工具描述简短、避免功能重叠
策展示例(curated examples)用 2-3 个典型示例代替长篇规则
Just-in-time 检索不预加载所有文档,按需 runtime 取
Compaction长任务做摘要压缩
结构化笔记关键信息写入 memory 文件而非塞回上下文
Sub-agent 架构子 Agent 在独立上下文里做研究,只回传结论

Harness Engineering 最佳实践

参考 Anthropic 的 Claude Code 文档,一个完整的 Agent harness 至少要包含 8 层组件:

层级组件例子
1采样循环While(not done): call_model → parse → execute → append_result
2工具系统Read / Edit / Write / Bash / WebFetch / Grep / Glob
3权限层Auto mode / Allowlist / Sandboxing 三档可调
4上下文管理器/clear、/compact、checkpointing、rewind
5记忆系统CLAUDE.md(项目级) + 用户级 memory 文件
6子 Agent 编排Task tool 派生子上下文
7钩子(Hooks)工具调用前后自动触发 lint / 测试
8错误恢复工具失败重试、上下文超限自动压缩

五、做 AI 应用:该投入哪一层?

你在做什么必做层选做层
写一个客服 ChatBotPromptContext
做一个文档问答助手Prompt + Context (RAG)
做一个 Agent 类产品(Coding / 研究 / 自动化)Prompt + Context + Harness
接入 Claude Code / Cursor 用看懂 Harness、用好 CLAUDE.md

六、常见误区

误区真相
Context Engineering 取代了 Prompt Engineering不,Prompt 是 Context 的一个子集,写不好 prompt context 也救不回来
Harness 就是 Agent 框架(LangGraph / AutoGen)框架只是 harness 的实现工具,harness 是设计哲学
RAG = Context EngineeringRAG 只是 Context Engineering 的一种"信息检索手段"
MCP 是协议不算 harnessMCP 定义了 harness 与外部工具的接口,是 harness 的关键组件
个人开发者不用懂 harness用 Claude Code、Cursor 时配置 CLAUDE.md、permission、hooks,本质都在做 harness 工程

七、FAQ

Q1:三个概念哪个最重要?
做单次任务最重要 Prompt;做问答应用最重要 Context;做 Agent 最重要 Harness。没有绝对答案,看你做什么。

Q2:Context Engineering 是 Anthropic 提出的吗?
是。Anthropic 在 2025 年 9 月发布的《Effective Context Engineering for AI Agents》是第一次官方系统化定义。Philipp Schmid、Simon Willison 等同期也在传播这个概念。

Q3:Harness Engineering 有官方定义吗?
"Harness" 一词在 Anthropic SWE-bench 论文、METR 评测、Claude Code 文档中被频繁使用,指代 agent scaffolding 的工程实践,但目前尚无单篇官方文章像 Context Engineering 那样给出标准定义。

Q4:RAG 属于 Context 还是 Harness?
检索动作属于 Harness(什么时候触发、调用哪个检索器是 harness 决策),检索结果如何拼接进 prompt 属于 Context Engineering。

Q5:MCP 属于哪一层?
MCP(Model Context Protocol)跨两层——它是 Harness 与外部世界通信的 协议,同时它返回的工具列表和数据要 作为 token 进入 Context

Q6:我用 Claude Code,要不要自己做 harness?
不用自己写,但要会 配置:CLAUDE.md(项目记忆)、permissions(权限)、hooks(自动化检查)、skills(领域知识)、subagents(专项任务),这些本质都是在调 Anthropic 已经写好的 harness 的参数。

Q7:Context 窗口越大就不用 Context Engineering 了吗?
恰恰相反。Anthropic 反复强调:"LLM performance degrades as context fills"——窗口大不等于塞满后还能用,Context Engineering 在长上下文时代更关键。


七牛云行业应用
10 声望10 粉丝