面向智能体的上下文工程:策略、实现与 LangGraph 实践
文章大纲
-
- 简介
- 上下文工程是什么? What is Context Engineering?
- 四大策略 Four Core Patterns
-
- 1. Write Context – 写出去
-
- 1.1 Scratchpad – 草稿本
- 1.2 Memory – 长期记忆
- 2. Select Context – 选进来
-
- 2.1 从草稿/记忆选择
- 2.2 Tool 选择
- 2.3 Knowledge 检索
- 3. Compress Context – 压缩
- 4. Isolate Context – 隔离
-
- 4.1 多智能体 Multi-Agent
- 4.2 沙盒 Sandbox
- 4.3 State 字段隔离
- LangGraph 落地指南 LangGraph Implementation Guide
- 结论 Conclusion
-
- 资源链接 Resources
简介
中文:智能体需要上下文才能执行任务。上下文工程就是在每一步把恰好合适的信息塞进有限的上下文窗口的艺术与科学。本文用「写-选-压-隔」四大策略拆解主流做法,并展示如何用 LangGraph 落地。
EN: Agents need context to perform. Context engineering is the art & science of filling the context window with exactly the right information at each step. We break it down into four patterns—write, select, compress, isolate—and show how to implement them with LangGraph.
上下文工程是什么? What is Context Engineering?
中文:
Andrej Karpathy 把 LLM 比作新型操作系统:
- LLM ≈ CPU
- 上下文窗口 ≈ RAM
操作系统必须精挑细选地加载内存;同理,上下文工程就是“把 RAM 填满正确内容”的过程。