MLOPS-COMMUNITY · 2025-11 AI & TECH
MLOPS-COMMUNITY · EPISODE DECK

Context Engineering for Coding Agents

你能控制的,只有 context window

Faus · Applied AI researcher / former restaurateur

一位 MLOps community Amsterdam 的现场分享。讲者把 "context engineering" 拆成一个 很哲学的命题:每周一个新模型,你能控制的只有那个 context window —— 怎么往里塞东西, 比模型本身更重要。从 25% 的经验法则、context 的三分法(deterministic / probabilisti…

Context Engineering for Coding Agents
Context Engineering for Coding Agents AI & TECH

为什么这场分享值得看

不是 syntax 教学,而是 "怎么在每周一个新模型的世界里保持工作姿势" 的心智模型。

焦点法则
"focus on the things that you can change" —— 那就是 context window
25% 上限
不管是 1M 还是 200K 模型,超过 25% 就慢、贵、错
context 三分法
deterministic / probabilistic / human —— 一个有争议但好用的分类
大脑作类比
working memory + 海马体 + 长期记忆 —— 不是拟人,是借结构
markdown 当记忆
Karpathy 提议:别上 RAG,先用 markdown 文件做 wiki
5 分钟实测
同样的 Opus 4.7,有 wiki 的赢,没 wiki 的来不及
Context Engineering for Coding Agents AI & TECH

讲者是谁

一个 "不像工程师" 的工程师

  • 学术背景是社会学
  • 两年前才卖掉自己开的餐厅
  • 现在在一家 applied AI lab 做研究

怎么掉进 AI 这个坑的

讲者讲的是一个很具体的故事:开餐厅时被会计搞出一摊事,最后被法院逼着反向做了三年的账目整理 —— 就是从那一刻开始研究 "怎么从文档里抽出结构化数据"。

作者概括:他特别强调自己不是来教 syntax —— "I'm here to provide you my humble lens on this changing world." 一个看世界的镜头,不是一本手册。

Context Engineering for Coding Agents AI & TECH

焦点法则

每周一个新模型,每月一次行业地震 —— 怎么不被卷死?

讲者把这事拆得很哲学:

  • 模型在变,labs 自己都说不清里面发生了什么
  • 你训不动模型,也没法影响 parametric memory
  • 能动的只有一个东西:context window

"focus on the things that you can change and that is essentially this little window which could be a million tokens."

即便它能涨到 1M、10M token,也还是一个有限的空间。

context engineering 就是怎么填好这个空间。

Context Window (1M / 200K tokens)Anthropic system instructionsCLAUDE.md (user / project / sub)Skills + MCP descriptionsMemory + rulesChat history + tool outputs (grows)← 25% ruleabove 25%: slower · costlier · more errors
Context Engineering for Coding Agents AI & TECH

context window 是一个 "对问题的解"

"the context window is a solution to a problem. Your problem is that you want your AI to be focused on whatever it is that you do and you want it to remember all that you did."

问题

  • 你想让 agent 专注
  • 你想让 agent 记住

"塞进 context" 只是答案之一

1M token 的窗口很方便,但不是唯一解。

讲者反复强调:还有别的办法,今晚就讲那些办法。

Context Engineering for Coding Agents AI & TECH

25% 的经验法则

他自认没人真知道阈值在哪 —— "anyone who's going to tell you that they know is talking [bleep]" —— 但还是给了一个 rule of thumb:

别越过 25%

≤ 25%

不管是 1M 模型还是 200K 模型 —— 一样。

越过会怎样

更慢 — 更长的 prompt 算得更久
更贵 — token 是直接成本
更易错 — 信号被噪声淹没

"context is not just neutral data" —— 你的 context 里如果同时漂着 3 个互相冲突的概念,模型很难只盯着你想要的那个。

Context Engineering for Coding Agents AI & TECH

context 优化是什么

"context optimization is getting the highest form of efficiency: getting the best result with the minimum input injected at exactly the right time."

最好结果
不是 "更多上下文"
最少输入
"less is always more"
恰到好处
时间和位置都对

这就是为什么不是把所有规则塞进一个超大 CLAUDE.md,

而是切成不同 scope、不同触发条件的小块。

Context Engineering for Coding Agents AI & TECH

一个 context 三分法

讲者自承这是个 "highly debatable" 的分类 —— 但很好用:

  • Deterministic —— 你启动 session 就一定会被注入的东西
  • Probabilistic —— 模型 / LLM 决定什么时候用的东西
  • Human —— 你这个活人提供的输入和判断

关键区别:"the way that they are injected"。同一段 markdown,被硬塞、被按需 fetch、被你打字打出来 —— 是三种完全不同的 context。

Deterministic· CLAUDE.md· rules· hooks· auto memory· loopsProbabilistic· sub-agents· agent teams· skills· plugins· MCPsHuman· chat input· steering· domain knowledge· reading the docs· judgment
Context Engineering for Coding Agents AI & TECH

Deterministic: CLAUDE.md 与 rules

CLAUDE.md

  • user scope / project scope / 子目录 scope
  • 启动 default agent 就必定注入
  • 原则:越少越好 ("as little as possible")
  • 只放总体性的偏好

Rules

他认为很多人把"Python 写法约定"塞进 CLAUDE.md 是错的。

那些约定应该是 rules —— 它们可以是:

  • 路径 scope 的
  • 文件扩展名触发的
  • 甚至 probabilistic fetched

作者概括:把 "什么时候用" 写进文件本身,比把它写进一个 always-on 的大 markdown 更省 context。

Context Engineering for Coding Agents AI & TECH

Deterministic: hooks, loops, auto-memory

Hooks

Claude Code 暴露了一堆生命周期事件,你可以挂任何脚本。

讲者用 hook 在 user input 之后接一个 TTS 转写后的重写步骤 —— 因为他打字慢,靠语音输入,要让另一个模型把口语洗成 prompt。

Loops

"If you are flush in credits and flushing tokens, loops are a great thing."

设个 cron job,每 30 分钟自己往前推一步。是烧 token 但省人力的方案。

Auto memory

Claude 自带的 markdown memory。

讲者承认 "I don't really like it" ——

它不太知道何时该存,retrieval 时机也不准。"probably going to be awesome" 但还没到。

Context Engineering for Coding Agents AI & TECH

Probabilistic: sub-agent

最重要的一类 probabilistic context:sub-agent 与 agent team。

讲者的关键观察:sub-agent 不继承 default agent 的:

  • Anthropic 给 Claude Code 的系统指令
  • CLAUDE.md 文件
  • 你建起来的 memory

默认会继承的只有:model 和 MCPs,而且这两个也都能改。

所以 sub-agent 的本质是 "clean slate per job" —— 给一个非编程任务(比如生成发票)派一个干净的 agent,比让默认编程 agent 兼职做要好得多。

Default agent✓ Anthropic system instructions✓ CLAUDE.md hierarchy✓ Memory✓ Skills + MCPs✓ Tools→ heavy, opinionatedSub-agent✗ No system prompt✗ No CLAUDE.md✗ No memory✓ Model + MCPs (by default)→ clean slate per job
Context Engineering for Coding Agents AI & TECH

Probabilistic: skills

Skill 不是黑魔法

  • 最朴素的 skill = 一个 markdown 文件 + 一个 slash command
  • 进阶:里头可以装脚本、装别的 agent

讲者举例:让 skill 去调一个 Gemini agent 做 native video 分析 —— Claude 自己不擅长视频,那就把 skill 当 "外援接口"。

"Skill to make skills"

他工作流的关键:聊到一个有意思的发现,立刻让 Claude 把它存成 skill。

以前他存 markdown 散落在各处。"和数据库说再见" 之后,技能就是可复用、可发现的。

Anthropic 自己也提供 "make-skill skill"。

Context Engineering for Coding Agents AI & TECH

200 个 skill 怎么办

skill 多了之后会撞到一个真实问题:每个 skill 的 description 都要让 LLM 看到才能选,200 个 skill 就是 200 段 description 都塞进 context。

deferred tools

Claude Code 的一个 flag。打开之后,skill 与 MCP 的描述按需加载,不再开局全注入 —— context 直接省下一大块。

但 trade-off 存在

你可以压缩 description 来省 token,代价是 LLM 选错的概率上升。

讲者说:让 LLM 替你选 —— 比让它替你做 —— 反而是 AI 未来更重要的用法。

"You are not going to think about 200 different skills when you are in a process —— there's just no way that a human will be able to choose from so many options. So you need the LLM to help you choose."

Context Engineering for Coding Agents AI & TECH

Human: 读 [bleep] 文档

讲者反复回到这个点:在 agent 普及的时代,读文档比以前更重要,不是不重要。

他原话用了一个不太印刷的版本 —— "read the [bleep] manuals" —— 但意思是认真的:

  • 不是要把整本 Anthropic 文档背下来
  • 是要知道什么是可能的
  • 文档给你 "ideas about what is possible"
  • 有 idea 才知道往哪儿配 skill / hook / agent

"What you need to have is ideas, and you need to sort of have a feeling what is possible."

模型每周升级一次(讲者讲这个 talk 时 Opus 4.7 刚出,"highly opinionated, really does as you say"),文档跟着变。不读文档,等于自愿放弃可控性。

Context Engineering for Coding Agents AI & TECH

大脑作类比

讲者特意先打预防针:"I am not standing here anthropomorphizing anything"。

这不是 "LLM = 脑子" 的浪漫话术。

是借大脑结构来抽象掉一个太复杂的系统。

  • Working memory ≈ context window,容量 7±2
  • Hippocampus ≈ 把短期变长期的中介
  • Long-term memory ≈ 你的 markdown wiki / 模型参数

一个被忽视的事实:memory 在被取出来的时候会被改写。所以 "查一下笔记" 这个动作本身就不中性。

Working memory~7±2 items(context window)Hippocampus(consolidate)Long-term memory(markdown wiki/ parametric)retrieval alters the memory
Context Engineering for Coding Agents AI & TECH

知识不在真空里生长

"knowledge does not get embedded in a vacuum. So you can only see things when you know things."

讲者举的例子

带两岁的女儿走进同一个房间,她看到的不是同一个世界 —— 物理实景一样,但她的 priors 不同,被注意到的东西完全不同。

对 agent 也一样

你必须先给 agent "a mental model of the world it's operating in"。

否则它就算扫到了关键信息,也不会知道那是关键 —— 它不知道自己在找什么。

Context Engineering for Coding Agents AI & TECH

Karpathy 的建议:markdown 当 memory

讲者点名引用了 Andrej Karpathy 几周前的一个建议(YouTube 自动字幕把名字打成了 "Kapati"):

做 agent 的工程师,把 memory storage 当作一堆 markdown 文件就够了 —— 不用上 RAG。

为什么这个建议有意思:

  • RAG 是个好方案,但 "a lot of moving parts"
  • 你研究过的论文、读过的文档,反正都是文本
  • 一个 wiki + 一个 index,对人也好用

讲者说他用 Obsidian 可视化,看到所有 note 之间的连线 —— "super easy".

hot.mdindex.mdattention.mdscore: 0.9hippocampus.mdscore: 0.7old-note.mdscore: 0.2 ↓Ebbinghaus decay: unused notes lose score
Context Engineering for Coding Agents AI & TECH

他在 Karpathy 之上加的东西

Karpathy 的建议到 "markdown 文件 + index" 就停了。讲者继续往下做:

hot.md

顶层一个文件,每次有新信息处理都被更新。是当前 "热点" 的快照。

重要度 score

每条 note 都有一个数值 —— 表示 "这条多大可能性还属于这套 corpus"。

Ebbinghaus 衰减

14 天 / 30 天没被用到的 note 会被降分。同主题的新 note 进来则会把这个主题的所有 note 提分。

关键的设计选择:保留原始文件 + 处理后的摘要 + 抽取出的概念

讲者承认这token 很重,但他坚持:每一篇论文都整篇地让 agent 读 —— 切片会丢上下文。

Context Engineering for Coding Agents AI & TECH

Observer pattern + tmux

讲者最近在玩的另一个 pattern:另开一个终端 session 当观察者。

数据本身就在

Claude Code 的 session 是本地的 JSONL 文件。另一个进程要读它易如反掌。

通过 tmux(讲者口误说成 "Tumix" / "Timox",是同一回事)让两个终端互发消息。

Observer 能做什么

  • 看到主 agent 正搜某个东西、而 wiki 里其实已有 → 推一条消息进去
  • 看到主 agent 学到新东西 → 把它写回 wiki
  • 看到模型升级前后的语气差异 → 自动调整

他用的还是 "the most important use of AI is offloading the things we have to make choices about" —— 让 LLM 替我决定 "这条信息要不要回头查",是节省人脑的最关键场景。

Context Engineering for Coding Agents AI & TECH

实测:Default vs Configured

讲者现场放了一个对比 demo。

任务:从零做一个 cellular automata visualization。

两边都是:Opus 4.7、同样的 CLAUDE.md、同样的 skills、同样的 sub-agents。

唯一区别:configured 版本带一个事先填好的 wiki(他花了一小时研究 + 读论文 + 喂进数据库)。

Hard 约束:5 分钟硬性 timer,每 30 秒 hook 一次提醒 "hurry up"。

带 wiki 的那个直接 fetch 概念建图。

默认版本只能靠 parametric memory 或临时研究 —— 时间用完了还在搜资料。

Default runCLAUDE.md + skills + sub-agentsOpus 4.7Configured runSame setup + a wikiOpus 4.7Build a cellular-automata visualizationHard cap: 5 minutesconfigured run finishes ✓default run runs out of time
Context Engineering for Coding Agents AI & TECH

一个被低估的产物:serendipity

"the most beautiful things are the unexpected things —— the sort of serendipity, the findings that actually update the priors not only confirm the priors."

标准 research agent

你派它去 arxiv 抓某个主题的论文 —— 它会聚焦在那个主题,这是它该做的。

把 5% 注入,95% 存起来

但你还可以让另一批指令不同的 agent 处理那些"顺手挖到的"论文 —— 95% 不直接进 context,先沉到 wiki 里。

未来某次任务它们就成了你 priors 之外的意外。

Context Engineering for Coding Agents AI & TECH

什么时候 不 该用 LLM

讲者花了几分钟讲他认为不该给 LLM 的活 —— 这部分他口气最坚决:

"if you are not able to say that if a model produces an output, if that output is good or bad, then you probably shouldn't give the task to an LLM."

不该让 LLM 写 essay

你说不清什么样的 essay 是 "好" 的。

拼写检查可以,主体写作不行。

不该让 LLM 做客服

理由很经济学 —— 任何免费、人人可得的东西就失去价值了。

客服的一半意义是品牌感知,不只是解决问题。

判别标准简单粗暴:你能不能事先说出 "好 / 坏" 的定义? 说不出 → 别上 LLM。

Context Engineering for Coding Agents AI & TECH

一个"非常适合 LLM"的活:从图纸里抽数据

讲者整场分享的实战环节就围绕这件事 —— 这也是他个人入行的起点:

技术图纸 = 有损 2D 投影

工业里到处都是技术图纸:一个机械零件的 3D 实物 → 2D 视图。你看到的是有损版本,但里面其实塞满了可被还原的信息。

为什么这个适合 LLM

  • 任务很难(多视图推断、行业知识)
  • 但答案是否对可被验证(有真值)
  • 完美符合 "说得清好坏 → 上 LLM"

讲者把自己怎么进 AI 圈的故事接在这儿:开餐厅时被会计搞砸,被法院判要倒着补三年的账 —— "that is the point where I started learning about structured extraction." 财务表也好、机械图也好,规则是一样的:抽得出,验得了。

Context Engineering for Coding Agents AI & TECH

情绪向量的小心使用

观众问到 Anthropic 的 emotion vectors 论文 —— 讲者答得很小心:

论文说的事

你给 LLM 一个高情绪冲击的故事,研究者能在内部测到 "emotion vectors" 被激活。

这些 vector 是从人类语料中学来的模式,不是真情绪。

讲者的警告

"you can use sort of reverse psychology to work with it, but it doesn't mean it's actually true."

可以借这个机制写更有效的 prompt,但不要在街上公开讲—— 大多数人会把"模型会有反应"听成"模型有感受"。

"I am not standing here anthropomorphizing anything" —— 但允许借大脑、借情绪当类比,因为模型本来就是被人类语料训出来的。

Context Engineering for Coding Agents AI & TECH

Stateless 和有状态的差别

Raw API call

讲者强调:"a raw API call is stateless"。

你打过去就只有这一发,没有任何隐含 context。

Claude Code 不是 stateless

"cloud code does not come stateless." (原字幕,意指 Claude Code)

打开一个 terminal 就已经预装了系统指令、CLAUDE.md 层级、可能还有 skill 描述、memory、tools。

这个区别为什么重要

所有 "怎么管 context" 的讨论,只有在有状态的封装里才存在。

如果你直接用 API,你就是 statelessness 的全部责任人。

如果你用 Claude Code,你是在调一个已经装满东西的环境 —— 别假装它是空的。

Context Engineering for Coding Agents AI & TECH

它们在 runtime 解决问题

"the whole thing with Claude and AI agents is that they can solve problems at runtime. It's not always your production solution, but it's definitely something you can learn a lot from."

老世界

你写 Pydantic model + rich description

→ 你已经知道要抽什么

→ 才能写出 schema

→ 这是 script 的活

Agent 的新能力

未知 schema 也能干 ——

你给一张你从没见过领域的图,agent 在 runtime 自己定义 schema。

对生产未必稳,但学到的东西巨多。

Context Engineering for Coding Agents AI & TECH

不要只看一个"超级模型"

讲者反复纠正一种主流叙事 —— 主流报刊把 AI 想成 "一个全能模型"。他认为这是误判:

"Magic thinking"

"people look at it with a sort of like magic thinking" —— 总在等那个万能模型。

但你不需要每个模型都是全能。

真实路径

  • 很多不那么全能的模型
  • 各做小事
  • 系统工程把它们串起来
  • 有办法判断每个输出对不对

→ 加在一起一样有大影响力。

这也是为什么他不停在 Claude 之外接 Codex / Gemini —— 把不同模型当作不同 sub-agent,谁擅长什么用谁。

Context Engineering for Coding Agents AI & TECH

把 Claude Code 当业务操作系统

讲者讲了一段挺个人的话:这件事已经不是 "写代码" 了:

Quote 生成

从客户通话录音里自动起报价单。

客户对接

生成发票草稿、回邮件草稿。

研究 & ideation

研究新主题、写 talk、做对比实验(比如这场分享)。

一个具体的提醒

他强调:千万别让默认的 coding agent 做非 coding 的事。

"sending a coding agent on a non-coding job —— probably works, but probably not optimal."

正确做法是:对每一类业务任务设计一个 sub-agent,给它自己的 system message、skill 子集、模型选择。

Context Engineering for Coding Agents AI & TECH

核心金句

这场分享里最值得记住的几句,每一条都能在原始字幕里检索:

"focus on the things that you can change, and that is essentially this little window."

— 关于 context engineering 的核心动机

"don't even think about going over 25% of context usage" / "less is always more when it comes to context."

— 25% 的 rule of thumb

"knowledge does not get embedded in a vacuum. You can only see things when you know things."

— 为什么 agent 需要先有 mental model

"if you are not able to say that if a model produces an output, if that output is good or bad, then you probably shouldn't give the task to an LLM."

— 何时不该用 LLM

"the most beautiful things are the unexpected things —— the serendipity, the findings that actually update the priors not only confirm the priors."

— 为什么把 95% 存回 wiki,比只注入 5% 更有价值

"the whole thing with Claude and AI agents is that they can solve problems at runtime."

— Agent 与 script 的本质差别
Faus

Thank you for your attention.

你的 attention,是有价格的

"As we all learned —— that comes at a price."

—— 讲者在演讲结尾对全场说的最后一句

← PodDeck