Harrison Chase 于 2026 年 9 月 5 日分享了 Deep Agents 的上下文管理思路:压缩应减少送入模型的内容,但不应抹掉底层工作历史。原帖同时给出了大工具结果、旧消息和主动压缩的具体落盘路径与触发方式。
英文原文与中文翻译
This is very similar to how we think about context management in Deep Agents: compaction should reduce what is sent to the model, not erase the underlying work history.
In Deep Agents, the logic is:
- every agent gets a filesystem to work with (can be real or virtual)
- when a tool result is too large, we write the full result to the filesystem (/large_tool_results) and replace the model-visible message with a preview
- when the conversation gets long, we offload older messages to the filesystem (/conversation_history) history first, then generate a summary
- the agent can also decide to compact proactively via a compact_conversation tool, which uses the same offload + summarize logic
Summarization middleware with all this logic: https://github.com/langchain-ai/deepagents/blob/main/libs/deepagents/deepagents/middleware/summarization.py
中文:
这与我们在 Deep Agents 中思考上下文管理的方式非常相似:压缩应该减少发送给模型的内容,而不是抹掉底层工作历史。
在 Deep Agents 中,逻辑如下:
- 每个 Agent 都有一个可工作的文件系统,可以是真实文件系统,也可以是虚拟文件系统;
- 当工具结果过大时,把完整结果写入文件系统的
/large_tool_results,并将模型可见消息替换为预览;- 当对话变长时,先把较早的消息卸载到文件系统的
/conversation_history,再生成摘要;- Agent 也可以通过
compact_conversation工具主动压缩对话,该工具复用相同的“卸载并摘要”逻辑。实现上述全部逻辑的摘要中间件:deepagents/libs/deepagents/deepagents/middleware/summarization.py at main · langchain-ai/deepagents · GitHub
公开实现核对
对应的 Deep Agents 公开代码显示,摘要中间件会在达到配置阈值后压缩对话,并将被移出的完整历史保存到后端,以便之后重新读取。历史按会话写入 /conversation_history/{session_id}.md;大工具结果使用 /large_tool_results 前缀;SummarizationToolMiddleware 则提供 compact_conversation 主动压缩入口。
原帖没有提供压缩前后的 token 节省比例、延迟或质量基准,因此这些效果不能仅凭该帖量化。
原作者:Harrison Chase(@hwchase17)
原帖:Harrison Chase on X: "This is very similar to how we think about context management in Deep Agents: compaction should reduce what is sent to the model, not erase the underlying work history. In Deep Agents, the logic is: - every agent gets a filesystem to work with (can be real or virtual) - w… / X