

大家好,我是Ai学习的老章
关于大模型中的上下文工程,刚看了一个Langchain的演讲,很不错,分享给大家

https://docs.google.com/presentation/d/16aaXLu40GugY-kOpqDU4e-S0hD1FmHcNyF0rRRnb1OU/edit?slide=id.p#slide=id.p



+1 for "context engineering" over "prompt engineering".
人们通常将提示与日常使用中给 LLM 的简短任务描述联系起来。而在每一个工业级的 LLM 应用中,上下文工程是填充上下文窗口以提供恰到好处的信息的艺术和科学,以便为下一步提供正确的背景信息。这是一门科学,因为正确地做到这一点需要任务描述和解释、少量示例、检索增强(RAG)、相关(可能跨模态)数据、工具、状态和历史记录,以及信息的压缩……如果信息不足或形式不对,LLM 将无法获得最佳性能所需的正确背景。如果信息过多或不相关,LLM 的成本可能会增加,性能可能会下降。做好这一点是非常非平凡的。而这也是一门艺术,因为它涉及到对 LLM 心理学和人类直觉的指导性理解。

1、转移上下文负担

2、精简上下文

3、检索上下文
4、隔离上下文

5、缓存上下文
总结:有得必有失,压缩过程中存在信息丢失的风险,这是一个问题。因此,更倾向于采用转移(上下文负担)的方式。多智能体之间存在协调问题,这也是一种风险。

正如Andrej Karpathy所说: 除了上下文工程本身之外,一个 LLM 应用还需要:
所以,上下文工程只是正在兴起的复杂软件层中的一个小部分,这一层软件协调着单个 LLM 调用(以及更多内容),使之成为完整的 LLM 应用。术语“ChatGPT 封装器”已经过时了,而且真的很不对。
PPT中附加的一篇文章写的也相当好《# How to Fix Your Context》[23]
文章承接前文 “长上下文如何失效”[24],探讨缓解或避免上下文失效的方法。
先回顾长上下文失效的四种模式:
上下文中毒,即幻觉或错误进入上下文并被反复引用;
上下文干扰,上下文过长使模型过度关注上下文而忽视训练内容;
上下文混淆,模型利用上下文中多余信息生成低质量回复;
上下文冲突,新信息与提示中的其他信息冲突。
接着介绍六种上下文管理策略:
文章对每种策略详细阐述其原理、应用案例及优势,强调上下文管理在构建智能体时的重要性,提醒构建或优化智能体时需审视上下文信息的有效性,并利用这六种策略解决问题。

制作不易,如果这篇文章觉得对你有用,可否点个关注。给我个三连击:点赞、转发和在看。
参考资料
[1]
Drew’s post: https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html
[2]
Anthropic multi-agent: https://www.anthropic.com/engineering/built-multi-agent-research-system
[3]
Manus: https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
[4]
Manus: https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
[5]
course: https://academy.langchain.com/courses/ambient-agents/
[6]
repo: https://github.com/langchain-ai/agents-from-scratch
[7]
Drew’s post: https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html
[8]
Drew’s post: https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html
[9]
open-deep-research: https://github.com/langchain-ai/open_deep_research
[10]
Cognition: https://cognition.ai/blog/dont-build-multi-agents#a-theory-of-building-long-running-agents
[11]
Cognition: https://cognition.ai/blog/dont-build-multi-agents#a-theory-of-building-long-running-agents
[12]
Manus: https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
[13]
take: https://x.com/_mohansolo/status/1899630246862966837?ref=blog.langchain.com
[14]
Preempt: https://lexfridman.com/cursor-team-transcript
[15]
Drew’s post: https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html
[16]
Drew’s post: https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html
[17]
Anthropic: https://www.anthropic.com/engineering/built-multi-agent-research-system
[18]
Cognition: https://cognition.ai/blog/dont-build-multi-agents#a-theory-of-building-long-running-agents
[19]
Walden Yan: https://x.com/jxnlco/status/1945490018127987092
[20]
Cognition: https://cognition.ai/blog/dont-build-multi-agents#a-theory-of-building-long-running-agents
[21]
Walden Yan: https://x.com/jxnlco/status/1945490018127987092
[22]
open-deep-research: https://github.com/langchain-ai/open_deep_research
[23]
《# How to Fix Your Context》: https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html
[24]
“长上下文如何失效”: https://www.dbreunig.com/2025/06/22/how-contexts-fail-and-how-to-fix-them.html