AAAEC Resources返回官网
AAAEC Resources

3. 记忆与上下文

10 模块知识库第 3 篇——讲 agent 如何在不同 session 之间保留信息:context window 限制、短期记忆、长期记忆、RAG、truncation 策略,以及在多 agent 间共享状态的方案。


本文覆盖 4 种 memory 与 context engineering,以及怎么用:

  • 4 种 memory episodic / semantic / procedural / working,各适用什么场景
  • Context Engineering 4 步流水线:压缩 / 摘要 / 检索 / 注入,跟 RAG 的关系
  • RAG 6 步流水线 从 chunking 到重排序,每个环节的 2-3 个选型
  • Chunking 3 策略 fixed / semantic / recursive 各自的 trade-off

选型快查 (TL;DR)

场景推荐子能力代表 agent
长文档问答(1M+ context)1M+ context windowClaude Sonnet 4.6+ / GPT-5.5 / Antigravity / Qwen-Agent 1M
跨 session 持久记忆Long-term memory + Memory bankChatGPT Memory / Claude Memory / Qwen-Agent 1M RAG
私有知识库 RAGHybrid RAG + agent decompositionQwen-Agent 1M RAG / WorkBuddy
多 agent 状态共享Shared memory layerCoze 3 / Copilot Studio System variables
Session 内 / 跨 Session 共享CLAUDE.md / Project memoryClaude Code nested CLAUDE.md
Context 超限处理Compaction + sub-agent 隔离Claude Code /rewind / ChatGPT Agent 3 mode
本地化长期记忆(隐私)100% 本地向量搜索Ollama + WorkBuddy

1. 这是什么 + 为什么重要

记忆与上下文决定 agent 能处理多复杂、多长时间跨度的任务。本模块拆解三层结构:

时间跨度典型实现失败后果
短期(in-session)当前对话context window + 消息历史答非所问、忘记前文
中期(project)项目级,跨 sessionCLAUDE.md / AGENTS.md / Project memory重复约定、风格漂移
长期(cross-session)跨周跨月Memory bank / ChatGPT Memory / Vector store用户每次重新教偏好

为什么是 agent 的硬约束:

  • 模型 context window 有上限(200K / 1M / 2M),超过必须压缩或截断
  • 长任务、多 agent 协作必须解决"子 agent 上下文隔离 vs 主 agent 信息汇总"的张力
  • 知识库(RAG)和长期记忆是 agent 从"工具"升级为"团队成员"的关键

2. 子模块分解

2.1 Context window(具体数字)

是什么:单次对话能塞多少 token,模型一次性"看见"的全部文本量。

跨 agent 数字表:


2.2 短期记忆(in-session)

是什么:当前 session 内的对话历史 + tool 调用结果 + 推理痕迹,在 context window 内维护。

跨 agent 差异表:

Agent短期记忆机制特殊能力来源
Claude Code完整 message history + thinking block + tool_use/rewind Esc+Esc 回滚到任意 checkpoint;compaction 后自动 re-read project root CLAUDE.mdanthropic.com
ChatGPT AgentServer-side / Standalone / ZDR 三种 compaction 模式Compaction item 是 opaque、encrypted、自动 carry stateplatform.openai.com
DevinSession transcript + 3h session timeout 自动 kill长 session 自动 sleep/wakedocs.devin.ai
Qwen-Agent5 步渐进截断 S1-S5自动按 max_input_tokens 触发截断qwenlm.github.io
WorkBuddy对话历史 + auto 蒸馏 30 天前日志用户可手动"压缩"前 N 轮(类似 GC)cnblogs.com/fengZQ ⚠️ + TRAE SOLO 同款机制 blog.csdn.net ⚠️
ManusWide Research sub-agent 独立 fresh context主 agent 拆分 + 汇总;Verify Agent 对抗测试manus.im
AutoGPTLLM context window + Redis 工作记忆 + classic 4000 字硬限制4000 字时强制要求 save important info to filescnblogs.com ⚠️
AntigravitySession 内 rewind/checkpointWalkthrough Report 截图+录屏作证据blog.google
Coze 3{{ }} 变量引用语法节点间显式传递 contextcoze.cn/open/docs
TRAE Solo子 Agent 独立 context + 上下文进度条手动 GC 压缩前 N 轮blog.csdn.net ⚠️
Copilot StudioSystem variables(user.Id / conversation.Id)+ topic-level/session-level/global 变量三级 scope 显式管理learn.microsoft.com
AgentforceState(短期 + 长期)+ Concierge 持久会话上下文Persistent Conversation Context 跨多 agentengineering.salesforce.com

2.3 长期记忆(跨 session)

是什么:跨多个 session 保留的用户偏好、项目状态、知识,agent 重新打开仍能"认识你"。

跨 agent 差异表:

Agent长期记忆机制自动 vs 手动来源
Claude CodeAuto memory(~/.claude/projects/<project>/memory/MEMORY.md 索引 + topic files);claude.ai Memory(Pro+)自动 + 用户说"remember this"code.claude.com/docs/en/memory
ChatGPT AgentChatGPT Memory(自动 detect + 手动 toggle);Project prompt 共享自动 detecthelp.openai.com
Codex(ChatGPT Agent 子集)Codex Chronicle(/memory list/add/clear)自动记录 build/lint/debugplatform.openai.com/codex/memories/chronicle
DevinKnowledge(2000 字/entry,per-scope);Playbooks;Past session 自动学User/Devin 都可 add(approve 闭环)docs.devin.ai/product-guides/knowledge
Qwen-AgentMCP memory server;百炼"记忆库"自动提取关键信息自动 + MCP 进程qwenlm.github.io ✅ + aliyun.com/bailian
WorkBuddyMEMORY.md(长期)+ YYYY-MM-DD.md(当日日志);30 天日志自动蒸馏自动 + 跨 Agent 记忆导入cnblogs.com/fengZQ ⚠️
AgentforceState 短期+长期;Data 360 Zero-Copy;Identity ResolutionCRM 原生自动engineering.salesforce.com
AntigravityMemory Bank(企业版)+ Memory Profiles(精确调用);Global + Workspace Rules企业版自动;个人 workspace 手动cloud.google.com
ManusProject 知识库(master instruction + 文件);Skills 跨 session 复用用户创建 + 自动manus.im/docs/features/projects.md
Coze 3用户级长期记忆(数据库 + 用户变量);Bot 知识库数据库持久化coze.cn/open/docs
Copilot StudioDataverse(长期结构化);Work IQ(M365 上下文智能)自动 + admin 配learn.microsoft.com
SierraAgent Memory(per-customer 短期 + 长期);Customer Profile;Glossary自动 + 平台级sierra.ai
TRAE Solo人设配置 + 记忆自管理("记住这个")自动 + 手动news.qq.com ⚠️
Cursor 2@Past Chats 跨对话引用;Plan 持久化为 .cursor/plans/显式 @cursor.com/blog/agent-best-practices

2.4 Knowledge base(KB)

是什么:用户上传的文档/数据,agent 检索使用,作为 LLM 知识的"外挂"。

跨 agent 差异表:

AgentKB 类型检索方式上限/容量来源
Claude CodeKnowledge file;Skills 资源;rules references全文 + MCP Resource单文件 200K token(WebFetch 单 URL 上限)code.claude.com/docs
ChatGPT AgentVector store(file_search);OpenAI 托管 pgvector语义 + chunk 检索单 store 10,000 files / 500K token/file;默认 800 token/chunk,200 overlapplatform.openai.com
DevinKnowledge base(per-repo);DeepWiki living docsKnowledge 注入到 session 起始 context2000 字/entrydocs.devin.ai
Qwen-Agent1M token RAG(hybrid RAG + agent-based decomposition)hybrid RAGneedle-in-the-haystack 测试通过qwenlm.github.io/blog/qwen-agent-2405
WorkBuddyima 知识库 + 腾讯乐享(企业版) + RAG_searchRAG由 ima/腾讯乐享决定news.qq.com
AgentforceKnowledge Articles(向量化 + RAG)+ Data 360 Zero-CopyHybrid Search(关键词 + 向量)CRM 原生,无外部 ETLengineering.salesforce.com
SierraKnowledge Base + Glossary + 40+ 预建集成Context Engineering 8 种 context block + Progressive DisclosureKB + Glossary 配 condition 激活sierra.ai
Coze 3知识库(文档 RAG:PDF/Docx/TXT/网页)RAG 切片 + 检索增强生成高级专业版 500GBcoze.cn/open/docs ✅ + blog.csdn.net ⚠️
Copilot StudioSharePoint / OneDrive / Dataverse / Microsoft Graph connectors / public website / filesAzure AI Search(底层)由 SharePoint/OneDrive 配额learn.microsoft.com
AntigravityWorkspace 集成;Code Context ItemsRAG由 workspace 决定antigravity.google/docs
TRAE Solo全仓库 RAG + 向量数据库索引(TRAE Enterprise)语义 + 文件级10万文件 / 1.5 亿行代码,实时增量byteplus.com/product/trae
Cursor 2Codebase-wide semantic index(Cursor 自研)语义索引大项目不用 Ctrl+Fcursor.com/blog/composer
AutoGPTVector store(Chroma / Pinecone / Milvus / Weaviate);Classic 本地 JSONtop_k 相似度(np.dot)理论无限blog.csdn.net ⚠️
Accio Work阿里国际站 10亿+商品 / 5000万+企业;实时海关/汇率阿里生态直连26 年数据沉淀ai-bot.cn ⚠️

2.5 Project memory / Rules

是什么:项目级指令(AGENTS.md / CLAUDE.md / rules / .claude/CLAUDE.md 等),影响 agent 在该项目内的行为。

跨 agent 差异表:

Agent文件格式加载顺序 / 优先级来源
Claude CodeCLAUDE.md(5 层加载:Managed → User → Project → Local → Parent/Subdirs);.claude/rules/*.md(有 paths: frontmatter 按 glob 懒加载);@AGENTS.md import5 层递归 4 层上限;nested CLAUDE.md 不自动 re-injectcode.claude.com/docs/en/memory
ChatGPT Agent(Codex)AGENTS.md(项目级自动读);.codex/rules/*.md(per-repo,配 paths:);@AGENTS.md 兼容team shared + commitplatform.openai.com/codex/guides/agents-md ✅ + platform.openai.com/codex/rules
Cursor 2.cursor/rules/*.md(每条 rule "always-on context" 自动读);Team Rules(admin 强制 / 推荐)用户级 + 项目级 + team 级cursor.com/blog/agent-best-practices ✅ + cursor.com/blog/enterprise
TRAE SoloTRAE Rules(全局生效,团队共享)单层全局trae.cn ⚠️
AntigravityGlobal Rules(~/.gemini/GEMINI.md)+ Workspace Rules(.agent/rules)双层antigravity.google/docs
WorkBuddy自定义指令(类似 CLAUDE.md 最高等级);全局预设话术用户级news.qq.com ,百炼走可视化编排)
Coze 3Bot 知识库;{{ }} 变量节点级
coze.cn/open/docsAgentforceAgent Script(确定性脚本);Metadata(自动读 CRM metadata)业务规则 + YAML 配置
salesforce.com/agentforce/agent-builder

2.6 Custom instructions / User preferences

是什么:用户级偏好(Custom Instructions / Memory / 人设配置),影响 agent 在所有对话/项目中的行为。

跨 agent 差异表:

Agent配置入口字符上限来源
ChatGPT AgentSettings → Personalization → Custom Instructions1500 字符help.openai.com
Claude Codeclaude.ai Memory(Settings → Memory)Pro+ planclaude.com/settings/memory
CodexProject prompt + Custom Instructions无明示platform.openai.com
WorkBuddy个性化设置 → 自定义指令(类 CLAUDE.md 模板)由版本决定news.qq.com ,全局生效)
无明示news.qq.com ⚠️Cursor 2@Past Chats 引用历史
由历史长度决定cursor.com/blog/agent-best-practicesManusProject master instruction
无明示manus.im/docs/features/projects.mdCoze 3数据库(用户变量);Persona 设置
由 plan 决定coze.cn/open/docs

2.7 Context truncation / Compaction

是什么:上下文超限时如何处理 — sliding(滑动窗口)/ summarization(摘要)/ ZDR(零数据保留)。

跨 agent 差异表:

Agent触发阈值策略用户可控来源
Claude CodeSonnet 4.6 ~150K / Opus 4.7 ~700KSkills re-attach(5000 tokens/FIFO)+ 保留 code patterns / 丢弃中间 reasoning/compact <instructions> + Custom 规则写进 CLAUDE.mdanthropic.com
ChatGPT Agentcompact_threshold: 200000Server-side / Standalone / ZDR;Compaction item opaque✅ 配置参数platform.openai.com
Devin200KLossy summary;3h session timeout 自动 kill❌ 不可配置docs.devin.ai
Qwen-Agentmax_input_tokens 配置S1-S5 渐进截断✅ 配置 + 5 步可调qwenlm.github.io
AntigravityADK 自动过滤 + summarization + lazy-load artifacts✅ 部分google.github.io/adk-docs/context/caching
TRAE Solo用户触发智能压缩 + 手动 GC 压缩前 N 轮✅ 手动进度条blog.csdn.net ⚠️
WorkBuddy262K 实测上限上下文超限触发熔断 + Error 400 + 外部通道失效 ⚠️❌ 无自动熔断cloud.tencent.com ⚠️ 开发者社区工单

2.8 RAG(向量 / 关键词 / 混合)

是什么:检索增强生成的实现方式 — 把外部知识喂给 LLM 的工程化路径。

跨 agent 差异表:

Agent检索方式Chunk 策略混合方式来源
ChatGPT Agentfile_search(vector store)默认 800 token / chunk,200 overlapranking_options.ranker: "auto" 混合(semantic + lexical)platform.openai.com ✅ + platform.openai.com/docs/guides/retrieval
AgentforceData 360 Hybrid SearchN/A关键词 + 向量检索融合engineering.salesforce.com
Qwen-Agent1M token RAG(hybrid + agent decomposition)needle-in-the-haystack 测试通过hybrid + agent-based decompositionqwenlm.github.io
SierraContext Engineering 8 block按 condition 激活;Progressive Disclosurestate-based + observation-based conditionsierra.ai
Cursor 2Codebase-wide semantic indexCursor 自研 RAG 索引semantic + grep stringscursor.com/blog/composer
AutoGPTVector store + get_relevanttop_k(np.dot)向量为主cnblogs.com ⚠️
Copilot StudioAzure AI Search(底层)SharePoint / OneDrive / Dataverse 原生索引由 Azure AI Search 提供learn.microsoft.com
AntigravityWorkspace + KI(Knowledge Items)Agentic RAG,AI 行动前查 KI 摘要Good/Bad examples 对比式少样本提示m.163.com ⚠️

2.9 Session persistence / Resume

是什么:session 中断后能否续上 / 跨设备接续,以及 session transcript / artifacts 的持久化。

跨 agent 差异表:

AgentResume 机制跨设备同步持久化存储来源
Claude Codeclaude --continue(最近)/ --resume(列表选)/ --resume <id>;/rename <name>;cleanupPeriodDays(默认 30 天);Esc + Esc /rewind 5 选项✅ Teleport(web/iOS ↔ local CLI);Dispatch(mobile → Desktop);Remote Control~/.claude/sessions/<id>.jsonl(本机)anthropic.com ✅ + code.claude.com/docs/en/overview
ChatGPT AgentCodex --resume / --resume <id>;ChatGPT history 跨设备✅ Chat history 跨 device sync(Web/iOS/Android)OpenAI 端 60 天(Assistants thread)platform.openai.com ✅ + help.openai.com
DevinCancel 后可恢复(企业版);3h session timeout 自动 sleep/wake;Replay URLapp.devin.ai/sessions/<id>(audit-ready format)docs.devin.ai
ManusMail Manus(专属邮箱);任务结束 state 保留(云端 persistent file system);Replay URL✅ Mail Manus + Scheduled Tasks 组合云端 VM 文件系统持久manus.im ✅ + manus.im
TRAE Solo桌面端 ↔ 网页端多端同步(Remote 任务后台异步)✅ 桌面 + 网页 + 云端算力任务列表持久化blog.csdn.net ⚠️
Cursor 2.cursor/plans/ markdown 持久化 plan;Cloud Agent(异步长任务)✅ cursor.com/agents;Mobile app;IDE ↔ CLIplan 文件cursor.com/blog/agent-best-practices
Antigravity/resume 命令跨 CLI ↔ GUI 同步会话✅ Antigravity CLI /resume;Session Sinking由 workspace 决定juejin.cn ⚠️
WorkBuddy任务列表持久化(左侧);Checkpoints 会话状态快照;锁屏远程✅ 微信小程序双模式(云端工作 / 连接电脑)由版本决定news.qq.com 。com/sswb/1762906.html](https://www.aliyun.com/sswb/1762906.html) ✅
AgentforcePersistent Conversation Context 跨多 agent✅ Enterprise-wideCRM Data 360engineering.salesforce.com
Copilot StudioSession record(30 天,CSV 导出:SessionID/StartDateTime/InitialUserMessage/TopicName/ChatTranscript)由 admin 配 retentionlearn.microsoft.com
AutoGPT断点续执行(PostgreSQL 状态持久化)PostgreSQL + Redis volumeblog.csdn.net ⚠️
Coze 3历史对话保存 + 复用✅ 跨端同步(Mac/Windows/网页)由 plan 决定coze.cn/open/docs ✅ + news.qq.com
SierraReplan / Replay URL(每个 Wide Research 任务公开)Sierra 云端manus.im/docs/features/wide-research.md

3. 横向对比总表

AgentContext window短期记忆长期记忆Project rulesCustom instrKB/RAGCompactionResume
Claude Code200K / 1M (Sonnet 4.6+/Opus 4.7+)完整 + checkpointauto memory + claude.ai MemoryCLAUDE.md 5 层 + Rulesclaude.ai MemoryKnowledge file + Skills refsAuto 150K/700K + /compact✅ --continue/--resume + Teleport
ChatGPT Agent1M(GPT-5.5)/ 272K-1M(5.4)/ 200K(o3)/ 128K(4o)compaction item + carry stateChatGPT Memory + Project promptAGENTS.md + Codex RulesCustom Instructions(1500 字)file_search vector storeserver-side/standalone/ZDRCodex --resume + Chat history 跨设备
Devin200K(SWE-1.6/Opus)/ 1M(Gemini 2.5 Pro)session transcript + 3h timeoutKnowledge(2000 字/entry)+ PlaybooksKnowledge per-repoKnowledge + DeepWikiLossy summary + 3h kill✅ Cancel resume(企业)
Qwen-Agent1M(qwen3-max)messages 数组 + 流式MCP memory server + 百炼记忆库❌(无 project rules)百炼 persona1M token hybrid RAG5 步渐进截断 S1-S5
WorkBuddy262144(实测上限)对话历史 + 30 天蒸馏MEMORY.md + 跨 Agent 导入自定义指令(类 CLAUDE.md)全局预设话术ima 知识库 + 腾讯乐享上下文超限触发熔断 ⚠️✅ 任务列表 + Checkpoints
Google Antigravity2M(Gemini 3 实验版)/ 1M(主推)Session + Walkthrough ReportMemory Bank + Memory Profiles(企业)Global + Workspace RulesWorkspace + KI Agentic RAGADK 自动 + Context Offloading✅ /resume + Session Sinking
Agentforce200K(常用)State 短期+长期CRM Data 360 Zero-CopyAgent Script + MetadataEinstein MemoryData 360 Hybrid SearchData 360Persistent Context 跨多 agent
Cursor 2200K+Composer model 工具调用@Past Chats.cursor/rules/ + Team RulesCodebase-wide semantic index自动 summarization.cursor/plans/ 持久化
Coze 3256K{{ }} 变量引用数据库 + 用户变量Bot 知识库Persona知识库(RAG)✅ 跨端同步(Mac/Win/网页)
Copilot Studio由底层模型决定System + 3 级 scope 变量Dataverse + Work IQtopic-level/session/global 变量SharePoint/OneDrive/Dataverse + GraphSession record(30 天,CSV)
TRAE Solo200K子 Agent 独立 context人设配置 + 记忆自管理TRAE Rules人设配置全仓库 RAG(Enterprise)智能压缩 + 手动 GC✅ 桌面/网页/云端多端
Sierra由 LLM constellation 决定session 内Agent Memory + Customer Profile + GlossaryJourneys(Goal + Guardrails)GhostwriterKB + Glossary + 40+ 集成Conditional Context ActivationReplay URL(每 Wide Research)
Manus由模型决定Wide Research 独立 fresh contextProject master instructionProject 共享Master instructionCloud Browser + MCPVerify Agent 对抗测试✅ Mail Manus + 云端持久
AutoGPT128K(GPT-4)ReAct loop + Redis 工作记忆Vector store(Chroma/Pinecone)+ Classic JSONGoals fileVector storeClassic 4000 字硬限制 + auto save✅ PostgreSQL 断点续
Accio Work国产大模型配置每 Agent 独立 context + 主 Agent 协调26 年阿里数据沉淀(10亿+商品 / 5000万+企业)阿里国际站实时数据Validator 层

4. 选型建议

按使用场景选型:

场景首选备选关键理由
超长文档问答(1M+)Qwen-Agent 1M RAG / AntigravityClaude Sonnet 4.6+(1M) / GPT-5.5(1M)needle-in-the-haystack 测试通过 + hybrid RAG
代码项目长 sessionClaude Code(Teleport + Rewind + Worktree 隔离)Cursor 2(Cloud Agent + git worktree)完整 CLAUDE.md 5 层 + checkpoint 5 选项 + auto-compaction 分档
跨会话项目记忆Claude Code auto memory / Codex ChronicleDevin Knowledge + Playbook自动 + 显式 / +AGENTS.md 兼容
企业数据接入(CRM/数据湖)Agentforce Data 360Copilot Studio(Dataverse + Graph connectors)Zero-Copy + Hybrid Search + Identity Resolution
代码库语义搜索Cursor 2 Codebase-wide semantic indexTRAE Enterprise(10万文件/1.5亿行)自研 RAG / 实时增量
客服场景(按 condition 激活)Sierra Context Engineering 8 block + Progressive DisclosureAgentforce KB + RAG按 state/observation 条件激活,避免 token 爆炸
国内合规 + 国产大模型Qwen-Agent / WorkBuddy / Coze 3TRAE Solo(国内版完全免费)信通院可信 / TC260 合规 / 私有化
长 session 超 3hManus(Mail Manus + Replay URL)Devin(3h timeout + auto sleep/wake)云端 VM 持久 + 异步邮件触发
多设备同步办公Claude Code(Teleport)TRAE Solo / WorkBuddy(微信小程序)跨 Web/iOS/CLI/Desktop 共享 engine
开源自托管AutoGPT(Classic / Platform)Qwen-Agent(Apache 2.0)数据自主可控 + Agent Protocol 标准

  • 2026-06-23 初版建立

On this page