[{"data":1,"prerenderedAt":854},["ShallowReactive",2],{"article-other\u002Fagent_memory":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":13,"_type":848,"_id":849,"_source":850,"_file":851,"_stem":852,"_extension":853},"\u002Farticles\u002Fother\u002Fagent_memory","other",false,"","Agent 的短期记忆与长期记忆：概念、设计与实现","从 State、Checkpointer 和 Store 出发，理解 Agent 记忆的作用域、持久化、检索与上下文注入，并梳理面试中的易错点。","2026-09-14",[12],"随笔",{"type":14,"children":15,"toc":831},"root",[16,24,34,39,44,65,215,221,228,233,275,287,313,319,344,356,369,375,380,413,418,423,429,434,440,445,483,519,546,558,577,583,588,593,617,636,642,665,678,684,689,728,733,743,755,761,780,800,805,810,815,820,825],{"type":17,"tag":18,"props":19,"children":21},"element","h2",{"id":20},"面试题",[22],{"type":23,"value":20},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28],{"type":17,"tag":29,"props":30,"children":31},"strong",{},[32],{"type":23,"value":33},"Memory 是 Agent 的一个关键模块。请问如何为 Agent 设计短期记忆和长期记忆系统？可以借助哪些外部工具或技术？",{"type":17,"tag":18,"props":35,"children":37},{"id":36},"先用一句话理解",[38],{"type":23,"value":36},{"type":17,"tag":25,"props":40,"children":41},{},[42],{"type":23,"value":43},"自己的理解：短期记忆像当前会话的工作记录，长期记忆像跨会话使用的用户档案和经验库。",{"type":17,"tag":25,"props":45,"children":46},{},[47,49,54,56],{"type":23,"value":48},"它们的核心区别是",{"type":17,"tag":29,"props":50,"children":51},{},[52],{"type":23,"value":53},"信息的使用作用域",{"type":23,"value":55},"，不是数据存放在内存还是数据库，也不是保存时间的长短。下面以 LangChain \u002F LangGraph 为例说明。",{"type":17,"tag":57,"props":58,"children":62},"a",{"href":59,"rel":60},"https:\u002F\u002Fdocs.langchain.com\u002Foss\u002Fpython\u002Fconcepts\u002Fmemory",[61],"nofollow",[63],{"type":23,"value":64},"官方记忆概念说明",{"type":17,"tag":66,"props":67,"children":68},"table",{},[69,93],{"type":17,"tag":70,"props":71,"children":72},"thead",{},[73],{"type":17,"tag":74,"props":75,"children":76},"tr",{},[77,83,88],{"type":17,"tag":78,"props":79,"children":80},"th",{},[81],{"type":23,"value":82},"对比项",{"type":17,"tag":78,"props":84,"children":85},{},[86],{"type":23,"value":87},"短期记忆",{"type":17,"tag":78,"props":89,"children":90},{},[91],{"type":23,"value":92},"长期记忆",{"type":17,"tag":94,"props":95,"children":96},"tbody",{},[97,116,134,161,179,197],{"type":17,"tag":74,"props":98,"children":99},{},[100,106,111],{"type":17,"tag":101,"props":102,"children":103},"td",{},[104],{"type":23,"value":105},"主要用途",{"type":17,"tag":101,"props":107,"children":108},{},[109],{"type":23,"value":110},"连续完成当前会话或任务",{"type":17,"tag":101,"props":112,"children":113},{},[114],{"type":23,"value":115},"在后续会话中复用有价值的信息",{"type":17,"tag":74,"props":117,"children":118},{},[119,124,129],{"type":17,"tag":101,"props":120,"children":121},{},[122],{"type":23,"value":123},"常见内容",{"type":17,"tag":101,"props":125,"children":126},{},[127],{"type":23,"value":128},"对话消息、工具结果、当前任务进度",{"type":17,"tag":101,"props":130,"children":131},{},[132],{"type":23,"value":133},"用户偏好、事实、历史经验、可复用规则",{"type":17,"tag":74,"props":135,"children":136},{},[137,142,156],{"type":17,"tag":101,"props":138,"children":139},{},[140],{"type":23,"value":141},"默认作用域",{"type":17,"tag":101,"props":143,"children":144},{},[145,147,154],{"type":23,"value":146},"某个 ",{"type":17,"tag":148,"props":149,"children":151},"code",{"className":150},[],[152],{"type":23,"value":153},"thread_id",{"type":23,"value":155}," 对应的会话",{"type":17,"tag":101,"props":157,"children":158},{},[159],{"type":23,"value":160},"应用定义的用户、组织或其他共享范围",{"type":17,"tag":74,"props":162,"children":163},{},[164,169,174],{"type":17,"tag":101,"props":165,"children":166},{},[167],{"type":23,"value":168},"LangGraph 中的常见实现",{"type":17,"tag":101,"props":170,"children":171},{},[172],{"type":23,"value":173},"State + Checkpointer + thread_id",{"type":17,"tag":101,"props":175,"children":176},{},[177],{"type":23,"value":178},"Store + namespace + key + value",{"type":17,"tag":74,"props":180,"children":181},{},[182,187,192],{"type":17,"tag":101,"props":183,"children":184},{},[185],{"type":23,"value":186},"读取方式",{"type":17,"tag":101,"props":188,"children":189},{},[190],{"type":23,"value":191},"恢复当前会话的状态",{"type":17,"tag":101,"props":193,"children":194},{},[195],{"type":23,"value":196},"按键读取、条件筛选或语义检索",{"type":17,"tag":74,"props":198,"children":199},{},[200,205,210],{"type":17,"tag":101,"props":201,"children":202},{},[203],{"type":23,"value":204},"是否必须使用向量数据库",{"type":17,"tag":101,"props":206,"children":207},{},[208],{"type":23,"value":209},"不需要",{"type":17,"tag":101,"props":211,"children":212},{},[213],{"type":23,"value":214},"也不需要，语义检索只是可选能力",{"type":17,"tag":18,"props":216,"children":218},{"id":217},"_1短期记忆怎么设计",[219],{"type":23,"value":220},"1、短期记忆怎么设计",{"type":17,"tag":222,"props":223,"children":225},"h3",{"id":224},"用-state-管理状态用-checkpointer-保存状态",[226],{"type":23,"value":227},"用 State 管理状态，用 Checkpointer 保存状态",{"type":17,"tag":25,"props":229,"children":230},{},[231],{"type":23,"value":232},"可以先记住这三个概念：",{"type":17,"tag":234,"props":235,"children":236},"ul",{},[237,256,266],{"type":17,"tag":238,"props":239,"children":240},"li",{},[241,246,248,254],{"type":17,"tag":29,"props":242,"children":243},{},[244],{"type":23,"value":245},"State",{"type":23,"value":247},"：当前会话的运行状态。默认包含 ",{"type":17,"tag":148,"props":249,"children":251},{"className":250},[],[252],{"type":23,"value":253},"messages",{"type":23,"value":255},"，也可以扩展任务进度等字段。",{"type":17,"tag":238,"props":257,"children":258},{},[259,264],{"type":17,"tag":29,"props":260,"children":261},{},[262],{"type":23,"value":263},"Checkpointer",{"type":23,"value":265},"：把运行状态保存成检查点，支持后续读取和恢复，不只是保存最终聊天记录。",{"type":17,"tag":238,"props":267,"children":268},{},[269,273],{"type":17,"tag":29,"props":270,"children":271},{},[272],{"type":23,"value":153},{"type":23,"value":274},"：标识这份状态属于哪个逻辑会话。",{"type":17,"tag":25,"props":276,"children":277},{},[278,280,285],{"type":23,"value":279},"例如，第一轮用户说“我叫张三”，第二轮问“我叫什么”。在同一套检查点存储中，两次调用使用相同的 ",{"type":17,"tag":148,"props":281,"children":283},{"className":282},[],[284],{"type":23,"value":153},{"type":23,"value":286},"，Agent 就可以恢复之前的状态，再处理新问题。",{"type":17,"tag":25,"props":288,"children":289},{},[290,292,297,299,304,306],{"type":23,"value":291},"这里的 ",{"type":17,"tag":29,"props":293,"children":294},{},[295],{"type":23,"value":296},"thread 是逻辑会话，不是操作系统线程",{"type":23,"value":298},"。",{"type":17,"tag":148,"props":300,"children":302},{"className":301},[],[303],{"type":23,"value":153},{"type":23,"value":305}," 标识一条会话下的检查点序列，而不是某一份唯一的状态快照。",{"type":17,"tag":57,"props":307,"children":310},{"href":308,"rel":309},"https:\u002F\u002Fdocs.langchain.com\u002Foss\u002Fpython\u002Flangchain\u002Fshort-term-memory",[61],[311],{"type":23,"value":312},"短期记忆文档",{"type":17,"tag":222,"props":314,"children":316},{"id":315},"是否重启就丢失取决于存储方式",[317],{"type":23,"value":318},"是否重启就丢失，取决于存储方式",{"type":17,"tag":234,"props":320,"children":321},{},[322,333],{"type":17,"tag":238,"props":323,"children":324},{},[325,331],{"type":17,"tag":148,"props":326,"children":328},{"className":327},[],[329],{"type":23,"value":330},"InMemorySaver",{"type":23,"value":332},"：保存在当前 Python 进程的内存里，进程退出后数据会丢失。",{"type":17,"tag":238,"props":334,"children":335},{},[336,342],{"type":17,"tag":148,"props":337,"children":339},{"className":338},[],[340],{"type":23,"value":341},"PostgresSaver",{"type":23,"value":343},"：保存在 PostgreSQL 中。只要检查点仍然保留，程序重启后连接同一存储、使用对应的会话配置，就可以恢复状态。",{"type":17,"tag":25,"props":345,"children":346},{},[347,349,354],{"type":23,"value":348},"因此，",{"type":17,"tag":29,"props":350,"children":351},{},[352],{"type":23,"value":353},"短期记忆可以长期保存在数据库里，但仍然是短期记忆",{"type":23,"value":355},"，因为它服务的是某个会话内的连续执行。",{"type":17,"tag":25,"props":357,"children":358},{},[359,361,367],{"type":23,"value":360},"反过来，",{"type":17,"tag":148,"props":362,"children":364},{"className":363},[],[365],{"type":23,"value":366},"InMemoryStore",{"type":23,"value":368}," 可以演示跨会话长期记忆，但进程退出后数据仍会丢失。“长期记忆”这个名称并不自动保证持久化。",{"type":17,"tag":222,"props":370,"children":372},{"id":371},"保存全部历史不等于每次都发给模型",[373],{"type":23,"value":374},"保存全部历史，不等于每次都发给模型",{"type":17,"tag":25,"props":376,"children":377},{},[378],{"type":23,"value":379},"对话越来越长时，需要控制输入模型的上下文大小：",{"type":17,"tag":234,"props":381,"children":382},{},[383,393,403],{"type":17,"tag":238,"props":384,"children":385},{},[386,391],{"type":17,"tag":29,"props":387,"children":388},{},[389],{"type":23,"value":390},"裁剪",{"type":23,"value":392},"：只保留最近或最相关的一部分消息。",{"type":17,"tag":238,"props":394,"children":395},{},[396,401],{"type":17,"tag":29,"props":397,"children":398},{},[399],{"type":23,"value":400},"删除",{"type":23,"value":402},"：从当前状态中移除指定消息。",{"type":17,"tag":238,"props":404,"children":405},{},[406,411],{"type":17,"tag":29,"props":407,"children":408},{},[409],{"type":23,"value":410},"摘要",{"type":23,"value":412},"：把较早的消息压缩成摘要，再保留近期原始消息。",{"type":17,"tag":25,"props":414,"children":415},{},[416],{"type":23,"value":417},"裁剪和删除的区别不能简单理解成“一个在调用前、一个在调用后”。是否改变保存的状态，取决于实现：只调整本次模型请求，可以保留完整 State；把裁剪结果写回 State，则会改变后续读取的当前状态。",{"type":17,"tag":25,"props":419,"children":420},{},[421],{"type":23,"value":422},"还要注意：摘要可能遗漏信息；从当前 State 删除消息，也不代表历史检查点、日志和备份中的内容已被物理清除。如果有隐私删除要求，需要额外设计数据清理流程。",{"type":17,"tag":18,"props":424,"children":426},{"id":425},"_2长期记忆怎么设计",[427],{"type":23,"value":428},"2、长期记忆怎么设计",{"type":17,"tag":25,"props":430,"children":431},{},[432],{"type":23,"value":433},"长期记忆不是把所有聊天记录原封不动再存一遍，而是选择值得跨会话复用的信息，例如用户偏好、明确确认的事实，以及经过验证的任务经验。",{"type":17,"tag":222,"props":435,"children":437},{"id":436},"用-namespacekeyvalue-组织信息",[438],{"type":23,"value":439},"用 namespace、key、value 组织信息",{"type":17,"tag":25,"props":441,"children":442},{},[443],{"type":23,"value":444},"LangGraph Store 中，一条记忆可以这样理解：",{"type":17,"tag":446,"props":447,"children":450},"pre",{"className":448,"code":449,"language":23,"meta":7,"style":7},"language-text shiki shiki-themes github-dark","namespace = (\"users\", \"Alice\", \"memories\")\nkey       = \"preferences\"\nvalue     = {\"sports\": \"跑步\", \"food\": \"酸奶\"}\n",[451],{"type":17,"tag":148,"props":452,"children":453},{"__ignoreMap":7},[454,465,474],{"type":17,"tag":455,"props":456,"children":459},"span",{"class":457,"line":458},"line",1,[460],{"type":17,"tag":455,"props":461,"children":462},{},[463],{"type":23,"value":464},"namespace = (\"users\", \"Alice\", \"memories\")\n",{"type":17,"tag":455,"props":466,"children":468},{"class":457,"line":467},2,[469],{"type":17,"tag":455,"props":470,"children":471},{},[472],{"type":23,"value":473},"key       = \"preferences\"\n",{"type":17,"tag":455,"props":475,"children":477},{"class":457,"line":476},3,[478],{"type":17,"tag":455,"props":479,"children":480},{},[481],{"type":23,"value":482},"value     = {\"sports\": \"跑步\", \"food\": \"酸奶\"}\n",{"type":17,"tag":234,"props":484,"children":485},{},[486,497,508],{"type":17,"tag":238,"props":487,"children":488},{},[489,495],{"type":17,"tag":148,"props":490,"children":492},{"className":491},[],[493],{"type":23,"value":494},"namespace",{"type":23,"value":496},"：记忆所在的逻辑分组，类似目录。",{"type":17,"tag":238,"props":498,"children":499},{},[500,506],{"type":17,"tag":148,"props":501,"children":503},{"className":502},[],[504],{"type":23,"value":505},"key",{"type":23,"value":507},"：这条记录在该分组中的标识。",{"type":17,"tag":238,"props":509,"children":510},{},[511,517],{"type":17,"tag":148,"props":512,"children":514},{"className":513},[],[515],{"type":23,"value":516},"value",{"type":23,"value":518},"：实际保存的结构化内容。",{"type":17,"tag":25,"props":520,"children":521},{},[522,528,530,536,538,544],{"type":17,"tag":148,"props":523,"children":525},{"className":524},[],[526],{"type":23,"value":527},"namespace + key",{"type":23,"value":529}," 共同定位一条记录。同一个 namespace 下使用相同 key 再次 ",{"type":17,"tag":148,"props":531,"children":533},{"className":532},[],[534],{"type":23,"value":535},"put()",{"type":23,"value":537},"，通常是在更新这条记录；",{"type":17,"tag":148,"props":539,"children":541},{"className":540},[],[542],{"type":23,"value":543},"get()",{"type":23,"value":545}," 可以按 namespace 和 key 精确读取。",{"type":17,"tag":25,"props":547,"children":548},{},[549,551,556],{"type":23,"value":550},"Alice 开启新会话后，即使 ",{"type":17,"tag":148,"props":552,"children":554},{"className":553},[],[555],{"type":23,"value":153},{"type":23,"value":557}," 改变，应用仍可以访问 Alice 对应的 namespace，复用她的偏好。Bob 则应访问 Bob 自己的记忆。",{"type":17,"tag":25,"props":559,"children":560},{},[561,563,568,570],{"type":23,"value":562},"所以，长期记忆是",{"type":17,"tag":29,"props":564,"children":565},{},[566],{"type":23,"value":567},"在规定范围内跨会话复用",{"type":23,"value":569},"，不是“所有会话、所有用户都能看见”。namespace 负责组织数据，不能代替身份认证和权限校验；应用仍需根据可信用户身份限制读写范围。",{"type":17,"tag":57,"props":571,"children":574},{"href":572,"rel":573},"https:\u002F\u002Fdocs.langchain.com\u002Foss\u002Fpython\u002Flangchain\u002Flong-term-memory",[61],[575],{"type":23,"value":576},"长期记忆文档",{"type":17,"tag":222,"props":578,"children":580},{"id":579},"精确查询与语义检索各有用途",[581],{"type":23,"value":582},"精确查询与语义检索，各有用途",{"type":17,"tag":25,"props":584,"children":585},{},[586],{"type":23,"value":587},"如果已经知道要读取“用户偏好”这条记录，按 key 查询就够了，不需要先做向量检索。",{"type":17,"tag":25,"props":589,"children":590},{},[591],{"type":23,"value":592},"如果想寻找“与当前问题相关的历史经验”，则可以使用嵌入模型和语义检索：",{"type":17,"tag":594,"props":595,"children":596},"ol",{},[597,602,607,612],{"type":17,"tag":238,"props":598,"children":599},{},[600],{"type":23,"value":601},"保存记忆时，把配置中选定的 value 字段转成向量。",{"type":17,"tag":238,"props":603,"children":604},{},[605],{"type":23,"value":606},"查询时，用兼容的嵌入模型把问题转成向量。",{"type":17,"tag":238,"props":608,"children":609},{},[610],{"type":23,"value":611},"在允许访问的范围内比较相似度，召回相关记录。",{"type":17,"tag":238,"props":613,"children":614},{},[615],{"type":23,"value":616},"将召回记录的文本内容提供给模型，而不是把向量本身当作提示词。",{"type":17,"tag":25,"props":618,"children":619},{},[620,622,627,629],{"type":23,"value":621},"这里比较的是",{"type":17,"tag":29,"props":623,"children":624},{},[625],{"type":23,"value":626},"问题向量与被索引内容的向量",{"type":23,"value":628},"，不一定是整个 value：索引字段配置决定了哪些内容参与检索。相似度高也不代表内容一定正确，还需要考虑来源、时效和相关性。",{"type":17,"tag":57,"props":630,"children":633},{"href":631,"rel":632},"https:\u002F\u002Fdocs.langchain.com\u002Foss\u002Fpython\u002Flanggraph\u002Fstores",[61],[634],{"type":23,"value":635},"Store 与语义检索文档",{"type":17,"tag":222,"props":637,"children":639},{"id":638},"还要设计什么时候写写什么",[640],{"type":23,"value":641},"还要设计“什么时候写、写什么”",{"type":17,"tag":234,"props":643,"children":644},{},[645,650,655,660],{"type":17,"tag":238,"props":646,"children":647},{},[648],{"type":23,"value":649},"用户明确要求记住偏好时，可以在当前流程中立即写入。",{"type":17,"tag":238,"props":651,"children":652},{},[653],{"type":23,"value":654},"从大量历史记录中提炼经验，可以放到后台任务中处理。",{"type":17,"tag":238,"props":656,"children":657},{},[658],{"type":23,"value":659},"记录必要的来源和更新时间，处理重复、冲突、过期与删除。",{"type":17,"tag":238,"props":661,"children":662},{},[663],{"type":23,"value":664},"不要把模型猜测直接当作用户事实，也不要无差别保存敏感信息。",{"type":17,"tag":25,"props":666,"children":667},{},[668,670,676],{"type":23,"value":669},"这些读写规则需要应用通过工具、中间件或后台任务实现。仅仅给 Agent 配置一个 ",{"type":17,"tag":148,"props":671,"children":673},{"className":672},[],[674],{"type":23,"value":675},"store",{"type":23,"value":677},"，不会自动完成记忆提取、检索和上下文注入。",{"type":17,"tag":18,"props":679,"children":681},{"id":680},"_3两种记忆怎样配合",[682],{"type":23,"value":683},"3、两种记忆怎样配合",{"type":17,"tag":25,"props":685,"children":686},{},[687],{"type":23,"value":688},"一次带记忆的 Agent 调用，可以按下面的过程理解：",{"type":17,"tag":594,"props":690,"children":691},{},[692,703,708,713,718,723],{"type":17,"tag":238,"props":693,"children":694},{},[695,697,702],{"type":23,"value":696},"确认用户身份和 ",{"type":17,"tag":148,"props":698,"children":700},{"className":699},[],[701],{"type":23,"value":153},{"type":23,"value":298},{"type":17,"tag":238,"props":704,"children":705},{},[706],{"type":23,"value":707},"从 Checkpointer 恢复当前会话 State，合入本轮输入。",{"type":17,"tag":238,"props":709,"children":710},{},[711],{"type":23,"value":712},"从允许访问的长期记忆范围内，按需读取或检索相关信息。",{"type":17,"tag":238,"props":714,"children":715},{},[716],{"type":23,"value":717},"组合系统指令、相关历史、长期记忆和本轮问题，构建模型上下文。",{"type":17,"tag":238,"props":719,"children":720},{},[721],{"type":23,"value":722},"模型生成回答或提出工具调用；工具结果返回后，必要时继续调用模型。",{"type":17,"tag":238,"props":724,"children":725},{},[726],{"type":23,"value":727},"框架在执行过程中保存状态检查点；应用按规则把值得复用的信息写入长期记忆。",{"type":17,"tag":25,"props":729,"children":730},{},[731],{"type":23,"value":732},"长期记忆也可以在工具执行过程中按需读取，不一定全部在第一次模型调用前准备好。",{"type":17,"tag":25,"props":734,"children":735},{},[736,741],{"type":17,"tag":29,"props":737,"children":738},{},[739],{"type":23,"value":740},"存储记忆和让模型看到记忆，是两件事。",{"type":23,"value":742}," State 中的自定义字段、Store 中的记录，并不会天然全部进入模型上下文；需要相应的消息构造、工具或中间件逻辑。",{"type":17,"tag":25,"props":744,"children":745},{},[746,748,753],{"type":23,"value":747},"因此，记忆系统更适合放在",{"type":17,"tag":29,"props":749,"children":750},{},[751],{"type":23,"value":752},"上下文工程",{"type":23,"value":754},"中理解：它既涉及存储、更新和检索，也涉及本次究竟给模型看什么。提示词工程侧重如何表达指令；记忆系统不只是写提示词，更不是修改模型参数、让模型本身永久学会这些信息。",{"type":17,"tag":18,"props":756,"children":758},{"id":757},"_4可以选择哪些工具",[759],{"type":23,"value":760},"4、可以选择哪些工具",{"type":17,"tag":25,"props":762,"children":763},{},[764,766,771,773,778],{"type":23,"value":765},"学习和验证时，可以使用 ",{"type":17,"tag":148,"props":767,"children":769},{"className":768},[],[770],{"type":23,"value":330},{"type":23,"value":772}," 管理会话检查点，使用 ",{"type":17,"tag":148,"props":774,"children":776},{"className":775},[],[777],{"type":23,"value":366},{"type":23,"value":779}," 演示长期记忆读写。",{"type":17,"tag":25,"props":781,"children":782},{},[783,785,790,792,798],{"type":23,"value":784},"需要跨进程持久化时，可以使用 PostgreSQL：通过 ",{"type":17,"tag":148,"props":786,"children":788},{"className":787},[],[789],{"type":23,"value":341},{"type":23,"value":791}," 保存检查点，通过 ",{"type":17,"tag":148,"props":793,"children":795},{"className":794},[],[796],{"type":23,"value":797},"PostgresStore",{"type":23,"value":799}," 保存长期记忆。两者可以使用同一种数据库，但职责不同，不能互相替代。",{"type":17,"tag":25,"props":801,"children":802},{},[803],{"type":23,"value":804},"需要语义检索时，再配置嵌入模型和支持向量索引的存储。向量检索是长期记忆的一种召回手段，不是长期记忆的定义，也不是每个场景都必需。",{"type":17,"tag":18,"props":806,"children":808},{"id":807},"面试时可以这样回答",[809],{"type":23,"value":807},{"type":17,"tag":25,"props":811,"children":812},{},[813],{"type":23,"value":814},"我会把 Agent 记忆分成会话级状态和跨会话可复用信息。短期记忆保存消息、工具结果和任务进度，用 State 管理，通过 Checkpointer 按 thread_id 保存与恢复，并用裁剪、摘要等方式控制上下文大小。",{"type":17,"tag":25,"props":816,"children":817},{},[818],{"type":23,"value":819},"长期记忆保存用户偏好、事实和经验，按用户或组织划分 namespace，使用数据库或 Store 管理。已知记录用精确查询，相关经验可以用嵌入模型做语义检索，再把需要的内容放入本次模型上下文。同时设计记忆写入、更新、去重、过期和权限控制。",{"type":17,"tag":25,"props":821,"children":822},{},[823],{"type":23,"value":824},"实现上，学习环境可以使用内存存储，持久化可以选择 PostgreSQL，语义检索按需引入向量索引。两种记忆的关键区别是作用域，而不是保存时间；长期记忆也不意味着所有用户共享。",{"type":17,"tag":826,"props":827,"children":828},"style",{},[829],{"type":23,"value":830},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":467,"depth":467,"links":832},[833,834,835,840,845,846,847],{"id":20,"depth":467,"text":20},{"id":36,"depth":467,"text":36},{"id":217,"depth":467,"text":220,"children":836},[837,838,839],{"id":224,"depth":476,"text":227},{"id":315,"depth":476,"text":318},{"id":371,"depth":476,"text":374},{"id":425,"depth":467,"text":428,"children":841},[842,843,844],{"id":436,"depth":476,"text":439},{"id":579,"depth":476,"text":582},{"id":638,"depth":476,"text":641},{"id":680,"depth":467,"text":683},{"id":757,"depth":467,"text":760},{"id":807,"depth":467,"text":807},"markdown","content:articles:other:agent_memory.md","content","articles\u002Fother\u002Fagent_memory.md","articles\u002Fother\u002Fagent_memory","md",1789465114555]