封面

Tina Huang · 12:48 · 发布 2025-08-01 · 20.5万次观看(截至抓取) · 观看原视频

🔥 观众最高回放 06:55 — Tina 演示一个完整的 context-engineered system prompt(给 AI 研究助理用),展开 role/task/input/output/constraints/capabilities 六段式结构;观众多从此处回看是因前 6 分钟的定义与组件铺垫已足够,想要看实际拼出来长什么样。

主旨

Tina Huang 用 12 分钟把”上下文工程”从术语讲到一手 prompt 范例:先与提示词工程划清边界,再把上下文工程定位为”为 Agent 撰写使用说明书”——把六类组件(model/tools/knowledge/memory/audio/guardrails/orchestration)如何协同用一段大 prompt 写死,最后给一份她自用的 AI 研究助理 prompt 与两条深入资源链接。

核心论点

  1. 上下文工程不是提示词工程的替代,而是提示词工程在”造 AI 应用”场景下的延伸——日常聊天仍属提示词工程,只有无法靠多轮迭代修正、必须一次给齐指令的 Agent 场景才需要上下文工程。(→ 详解1)
  2. 上下文工程 = 给 AI Agent 写使用说明书——Agent 自带的六类组件(model/tools/knowledge/memory/audio/guardrails/orchestration)必须由 prompt 串成可执行单元,prompt 因此开始带 XML 标签与 markdown、长得像代码。(→ 详解2/3)
  3. 六类组件是 Agent 的必要构件,缺一不可——类比汉堡的”面包、肉饼、菜、酱”四件套,每类组件内部可换形态(不同模型/不同工具/不同记忆方案),但六大件必须都在场。(→ 详解3)
  4. 真正用上下文工程写出来的 prompt 远长于普通聊天 prompt——Tina 自用 AI 研究助理的 system prompt 已包含 role/task/input/output/constraints/capabilities 六段,她说”this is actually considered a very very simple prompt”——言下之意是更复杂的 agent prompt 还要再长。(→ 详解4)
  5. 写上下文工程 prompt 也有公认的四类策略可循——Cognition 给出多 agent 框架的两条原则(agent 间共享上下文、动作即隐含决策);LangChain 总结出四类策略(write/select/compress/isolate),两者都是更系统的资料入口。(→ 详解5)

知识点详解

1. 定义:上下文工程是”为 LLM 装好正确信息”的动态系统设计 00:39

Tina 给定义一句话:“Context engineering is designing and building dynamic systems that give an LM the right info in the right format at the right time to accomplish a task”(00:39)——三个关键限定:动态系统对的信息对的时机。她随即把它简化为一个更形象的说法:“you’re packing the context window, which is the input area of a large language model just right”(00:53)——“装”是关键词,不是”写”一个 prompt 那么单点,而是把一整套信息打包进 上下文窗口。

她提示一个最常见的误读:“You may have already heard or read online that context engineering is the new prompt engineering. That is true, but it doesn’t mean that like prompt engineering is dead”(01:00)——“新提示词工程”的说法没错,但提示词工程并没有死。两者差异不在”难度”,而在使用场景——和 ChatGPT 聊跑鞋、聊菜谱、聊配色,这种来回多轮的对话仍是提示词工程;只有当你开始造 AI 应用时,上下文工程才登场。

2. 区分:为什么”造应用”必须上下文工程 01:27

Tina 用一个客服 agent 的设想把场景具体化:“if you’re building a customer service AI agent for your online store, that agent needs to be equipped with the ability to handle all sorts of inquiries like billing problems, refund issues, login issues”——一个客服 agent 要能处理账单、退款、登录、条款检索、用户骂人、必要时转人工。她点出关键性质转换:“you can’t iteratively keep talking to the agent until it gets the answer correct”(01:38)——聊天时你可以多轮纠错,让 ChatGPT 修正到对为止;但 agent 必须一次给齐指令

随之而来的是 prompt 体积的膨胀:“your prompts become larger and larger and more and more complex. At some point they even start to resemble code with XML tags and markdown”(02:14)——上下文工程 prompt 长得像代码,带 XML 标签、带 markdown 结构。这与传统提示词工程”几行文字”形态完全不同,也是社区开始用”上下文工程”这个新词的原因。

她顺手给了一个抓人的类比:“As Andre Kaparthy explains the LM is the CPU and the context window is the RAM”(02:39)——上下文窗口 是 RAM,LLM 是 CPU。上下文工程就是给 RAM 装好要让 CPU 跑的程序——不是装哪段都行,得装到刚好够用、装到格式对、装到时机对。

3. AI Agent 六组件 + 汉堡类比:为什么”使用说明书”必须写 03:00

Tina 先把 Agent 词条统一一下:“the definition of an AI agent is a software system that uses AI to pursue goals and complete tasks on behalf of users”(03:00)——目标驱动、替用户执行任务的软件系统。客服 agent、销售 lead 资格化 agent、编程 agent 都属此类。

她随即列出六类必含组件:“there are six components which are essential building blocks that make up an AI agent”(03:18)——model(模型)、tools(工具,接外部系统,Agent 工具(Tool Use) 类)、knowledge and memory(知识与记忆,Agent 记忆 类)、audio and speech(语音)、guardrails(护栏)、orchestration(编排,Agent 编排(Orchestration) 类)。六件缺一不可。

类比是这段最抓人的一句:“these six components of AI agents is sort of like a burger. Like in order for a burger to be considered a burger, it needs to have a bun, a patty, vegetables, and condiments”(04:32)——汉堡四件套(面包、肉饼、蔬菜、酱)缺一不可,但每件内部可换(全麦/白面包/生菜包,鸡/牛/猪排),agent 也是如此:不同模型可换、不同工具可换、不同记忆方案可换,但六大件必须齐。

Tina 把外星人做汉堡的类比继续推进:“whoever is telling you to make a burger probably needs to also provide an instructions manual telling you that the bun goes on either side”——光有组件不够,还得有组装说明书。这正是上下文工程的位置:“that is where the context engineer comes in. You’re coming up with that prompt that exactly details how everything is working together”(05:30)——上下文工程的工作产出,就是那段把六大件串起来的 prompt。

她用一句金句收尾:“It is really important to get this prompt right, and people spend a lot of time context engineering until they get that perfect prompt”(05:41)——这段 prompt 的好坏直接决定 agent 能不能工作,因此工程团队会花大量时间迭代。

4. 演示:她自用的 AI 研究助理 prompt 长什么样 06:42

Tina 拿出一份真实在用的 system prompt 演示。她先讲整体结构:“The general structure of the system prompt is that I have these six different components. It helps um structure the prompt in a way that is easier to follow”(06:58)——六段式结构组织整份 prompt,逐段如下。

第一段 role:“you’re an AI research assistant focused on identifying and summarizing recent trends in AI from multiple source types”(07:04)——给 agent 一个清晰角色定位:研究助理,识别并总结 AI 趋势,信源类型多样。

第二段 task——把要做的事拆成五步:“Step one is to extract up to 10 diverse high priority subtasks each targeting a different angle or source type. Step two is to prioritize by engagement such as views, likes, repost, and citations as well as authority of source”(07:33)——拆子任务、按互动与权威度排序、生成 JSON 输出、算时间窗口、最终汇总成 ≤300 字趋势摘要。

第三段 input/output——输入用 XML 标签 <user_query> 框住用户查询;输出指定一个固定 JSON 格式(每条 subtask 含 ID/query/source_type/time_period/domain_focus/priority/start_date/end_date 八字段)。

第四段 constraints——明确限制:聚焦要点、允许不完整句子、剔除水信息、禁止加入 AI 自己的分析与观点。第五段 capabilities & reminders——告诉 agent 可用什么工具(如 web search)、提醒它”必须清楚当前日期、只总结过去 10 天内新闻”。

她对这份 prompt 的总结非常关键:“this is actually considered a very very simple prompt”(10:05)——这还算是”很简单的 prompt”。她随即补一句:“normally when I do something like this, I would generally split it into multi-agent systems”——她实际生产里会拆成多 agent(一个检索、一个汇总),这版单体 agent 是为了讲解做的简化。言下之意:真正在产的 agent prompt 还要再复杂一截

5. 资源:两条深读链接与四类上下文策略 11:24

Tina 在收尾前给两条深入资源。第一条来自 Cognition(Devin 团队),讲多 agent 框架的两条原则:“to always share context between your agents. And the second is that actions carry implicit decisions”(11:24)——一是agent 间共享上下文(不让每个 agent 各持一份信息),二是动作即隐含决策(agent 每做一步都是决策,设计时要谨慎)。

第二条来自 LangChain,把上下文工程策略归成四类:“The first one is writing context. How it is that you can allow your large language model to write down information surrounding a task”(11:46)——上下文,让 LLM 把任务相关信息先写下来以备后用。“The second is selecting context. How it is that you can pull information from external sources to help your agent perform a task”(11:55)——上下文,从外部源(数据库/RAG/工具)按需拉信息。

“The third is compressing context. When there is a lot of information that you’re trying to give in large language model, there are techniques that you can do in order to help compress that information in a more compact way”(12:02)——上下文,把大量信息压成更紧凑的形态喂入窗口(对应 Compaction 类做法)。“And the fourth is isolating context. How to split context in between different environments and different places”(12:13)——隔离上下文,让不同环境/子 agent 各持自己的窗口,避免主上下文被污染。

Tina 明确不展开这四类,只点到为止:“I’m not going to go into more details about this to keep this video relatively succinct”——她认为本片是把术语一次说清、把这四类当”深读入口”留给观众自己看。

可执行步骤

  • 先判断当前任务是聊天还是造应用——日常聊天继续用提示词工程套路(多轮迭代),只有造 Agent 才进上下文工程语境。
  • 拿到一个 agent 需求后,先列六大组件(model/tools/knowledge/memory/audio/guardrails/orchestration)各打算用哪种——汉堡四件套类比反向用:先把空组件填实,再考虑 prompt 怎么写。
  • 写 system prompt 时按 role/task/input/output/constraints/capabilities 六段式分块组织——每段一职责,XML 标签标边界,长 prompt 也要可读。
  • 输入用 <user_query> 等 XML 标签包住,输出用固定 JSON 格式锁死字段——给 agent 明确的数据边界,减少自由发挥。
  • 读 Cognition 博客的”always share context + actions carry implicit decisions”两条原则,作为多 agent 设计的第一性检查项。
  • 读 LangChain 的四类策略(write/select/compress/isolate)详解,逐条套到自己当前 agent prompt,看哪条最值得改。

关联

  • Agentic课·子代理 ——互补。Tina 讲单 agent 内的”六大组件 + 一份大 prompt 串起一切”,Agentic 工作流课讲子代理把脏活分到独立窗口(上下文隔离 + 上下文污染)。两片互为正反:Tina 是”不拆”路线,Agentic 课是”拆”路线,实际工程按 prompt 体量与稳定度选择。
  • WISC上下文管理四策略 ——互补。LangChain 把上下文策略归成 write/select/compress/isolate 四类,Tina 在结尾顺手带过;Cole 提的 WISC(Write/Isolate/Select/Compress)同样四类但顺序不同,两片互为印证(四类策略是社区共识),可对照读。
  • Agentic课·五要素 ——进阶。Tina 的六大组件里 model/tools/knowledge-memory/audio/guardrails/orchestration 与 Agentic 课的 PTMRO 五要素(规划/工具/记忆/反思/编排)高度重叠,但 PTMRO 把”规划”提到首位、把”反思”独立出来——读 Tina 的”组装说明书”视角后,再读 PTMRO 看”agent 自身五步循环”如何对应更系统。
  • 复现:先学先赢的 6 个 AI 技能 把 上下文工程 列为”有正职、不想辞职开公司”人群该保住饭碗的 6 项 AI 技能之一,是本片定义在个人技能框架里的具体应用。
  • 复现:数据科学家转型AI工程师路线图 把 上下文工程 放进 DS→AI 工程师转型的”LLM 层”基础层,强调上下文给错/给晚/给多/给少是多数 agent 异常的根因。

一手来源与延伸

术语

  • Context engineering(上下文工程):为 LLM 在对的时间、对的格式、给对的信息以完成任务而设计的动态系统。
  • Context window(上下文窗口):LLM 单次可接受的输入区域,即 Karpathy 类比里的”RAM”。
  • System prompt(系统提示词):决定 agent 角色、任务、行为约束的顶层 prompt;Tina 的范例把它拆成 role/task/input/output/constraints/capabilities 六段。
  • Agent components(Agent 六组件):Model、Tools、Knowledge & Memory、Audio & Speech、Guardrails、Orchestration 六大件,Tina 类比为汉堡四件套。
  • Guardrail(护栏):agent 的安全机制,确保其不会产生不期望行为(如客服 agent 不回骂用户)。
  • Orchestration(编排):让 agent 能被部署、监控、随时间改进的系统层。
  • Multi-agent(多 agent):把单一 agent 的功能拆给多个子 agent 协作的架构,Tina 提到她实际生产会拆(讲解里没展开)。

金句

“Context engineering is designing and building dynamic systems that give an LM the right info in the right format at the right time to accomplish a task.”(00:39) → 一句话定义,三个”对”信息(right info/right format/right time)就是上下文工程的全部工作量。

“As Andre Kaparthy explains the LM is the CPU and the context window is the RAM.”(02:39) → 把 LLM 比 CPU、context window 比 RAM,直接点明上下文工程 = 装 RAM 程序;工程思维立刻可类比。

“It is really important to get this prompt right, and people spend a lot of time context engineering until they get that perfect prompt.”(05:41) → 上下文工程是 AI Agent 项目的硬迭代项,不是一次写就完;上线后还会反复改。

“this is actually considered a very very simple prompt”(10:05) → Tina 对自用 AI 研究助理 prompt 的评价。“简单”是相对生产中多 agent 系统的复杂 prompt 而言,新手不要被这句话低估入门门槛。

立场与利益

  • 与利益同向(待印证):Tina 自言已在卖/预备卖 “AI Agent Bootcamp”(见 description 中的 lonelyoctopus.com/ai-agent-bootcamp 链接);本片关于”造 agent 必须上下文工程、prompt 写得越长越复杂”是直接为课程铺路——“agent 工程比聊天重要得多”这一框架性结论本身有外部共识(Cognition/LangChain 资源可印证),但”必须花大量时间精修 prompt”的具体工程纪律需独立查证。
  • 利益中性:Karpathy 的 CPU/RAM 类比、汉堡组件类比、Cognition/LangChain 两条引用、Cognition 的两条原则、LangChain 的四类策略——这些都是社区/原厂既有说法,Tina 只是转述与串联,与课程/工具无直接利益绑定,按内容本身采信。
  • 利益反向(可信度最高):Tina 整片没避谈”我这份 prompt 还算简单”和”实际生产用多 agent 更复杂”——把”看完这 12 分钟不等于能造 agent”明说,不夸大自学可达水平,这与卖课话术相悖,故本片对入门难度的判断可作外部印证。
  • 利益证据一行带过:description 含 augmentcode.com(7 天试用 affiliate)、lonelyoctopus.com/ai-agent-bootcamp(自己课程 waitlist)、365datascience/StrataScratch affiliate 链接;本片 Augment 中段有约 50 秒口头广告段。

价值定位

  • 适合谁:正在从”用 ChatGPT 写提示词”过渡到”造 AI Agent / AI 应用”的开发者或产品人——已有 prompt engineering 基础、想搞清”为什么 AI 应用 prompt 这么长、长得像代码、为什么叫 context engineering”的入门读者。
  • 解决什么:给入门者一张术语地图——把 context engineering 与 prompt engineering 的边界、agent 的六大组件、prompt 的六段式结构、两条深读资源四件事一次性讲清,12 分钟即可完成”认知升级”,再按需跳到 Cognition/LangChain 深入。
  • 认知 vs 实操:偏认知。给定义、给类比、给一份范例 prompt 看看,但不教具体怎么迭代、不教怎么用 n8t/OpenAI Agents SDK 落地——Tina 自己在 Augment 段也承认她用的是 NAT(她自创的 n8n 变体),但没在视频里展开操作流程。
  • Agentic课·五要素 重叠时:本片独有”汉堡组件类比 + 六段式 system prompt 范本 + 现实生产里要拆多 agent”三点,Agentic 课覆盖更系统的 PTMRO 五要素循环与子代理机制;入门先看本片,真要落地再看 Agentic 课。

自检问题

  1. 上下文工程和提示词工程的核心边界是什么?为什么 Tina 说”提示词工程没有死”? 答案:边界在”使用场景”——聊天型来回多轮仍是提示词工程,只有造 AI Agent(无法靠多轮迭代、必须一次给齐指令)才需要上下文工程,见详解1/2。
  2. Tina 把 AI Agent 拆成哪六大组件?她用什么生活类比让六大件”缺一不可”这件事变得直观? 答案:六大组件是 model/tools/knowledge & memory/audio & speech/guardrails/orchestration,见详解3;类比是汉堡的面包/肉饼/菜/酱四件套——缺一不算汉堡,每件内部可换但必须齐。
  3. Tina 演示的 system prompt 用了哪六段式结构?每段大致承担什么职责? 答案:role(给角色)/task(拆步骤)/input(用 XML 标签包输入)/output(锁 JSON 格式)/constraints(明确限制)/capabilities & reminders(给工具与提醒),见详解4。
  4. LangChain 总结的四类上下文策略是哪四类?对应什么工程直觉? 答案:write(让 LLM 写下来备后用)/select(从外部源按需拉)/compress(把大信息压紧凑)/isolate(把上下文拆到不同环境/子 agent),见详解5。
  5. Tina 对”自己这份 AI 研究助理 prompt 算复杂还是简单”的判断是什么?这对入门者的工程预期有什么含义? 答案:Tina 说这份 prompt”算很简单的”——她实际生产拆成多 agent(检索+汇总),本片为讲解做了单体简化,入门者不要把”看完 12 分钟能造 agent”当成真实门槛,见详解4 末段与立场与利益节。