<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>junlin</title>
        <link>https://www.junlin-233.top/</link>
        <description>保持思考</description>
        <lastBuildDate>Sun, 19 Apr 2026 06:04:43 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2026, junlin</copyright>
        <item>
            <title><![CDATA[agent那些事：一文带你入门agent]]></title>
            <link>https://www.junlin-233.top/article/agent-analysis</link>
            <guid>https://www.junlin-233.top/article/agent-analysis</guid>
            <pubDate>Tue, 14 Apr 2026 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-341d690ad6d180879b67c08bcc3e5d23"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-341d690ad6d1809fa5dbeec13240b428" data-id="341d690ad6d1809fa5dbeec13240b428"><span><div id="341d690ad6d1809fa5dbeec13240b428" class="notion-header-anchor"></div><a class="notion-hash-link" href="#341d690ad6d1809fa5dbeec13240b428" title="agent 那些事"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">agent 那些事</span></span></h2><div class="notion-text notion-block-341d690ad6d180ff9f6fc5d4e5b4461a">Agent 这两年很热，但很多讨论还停留在“会调用工具的大模型”这个层面。真到工程落地时，问题很快就会变成另一类：到底什么时候该用 Agent，什么时候只需要 Workflow？所谓记忆到底是不是核心能力？多 Agent 是不是天然比单 Agent 更高级？</div><div class="notion-text notion-block-da18a57959f54f2793bbc2750884aa9c">这篇文章试着从工程实现的角度，结合我自己用oh my opencode/openagent 开发的经历，把这些问题重新梳理一遍。</div><hr class="notion-hr notion-block-ad7f9a40f38f4cfc9bc99ae10e707f75"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-3bf79907366d4c5b9841ce4c3b16b620" data-id="3bf79907366d4c5b9841ce4c3b16b620"><span><div id="3bf79907366d4c5b9841ce4c3b16b620" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3bf79907366d4c5b9841ce4c3b16b620" title="一、什么时候该用 Agent？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">一、什么时候该用 Agent？</span></span></h2><div class="notion-callout notion-block-8e4f9f386f0c493b9ebed63575d86085"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="💡">💡</span></div><div class="notion-callout-text"><div class="notion-text notion-block-928eb48ace20434b893b2e8e7d01a777"><b>核心原则：越简单越好，避免过度设计。</b></div></div></div><div class="notion-text notion-block-ef039695e3e14c5b96e38e24a2fe6272">对于依赖传统规则、结构稳定、输入输出边界清晰的系统，一般不需要引入 Agent，直接使用 <b>Workflow</b> 往往更稳、更省成本，也更容易维护。</div><div class="notion-text notion-block-cac43418de974901b40105f0f1ba333a">Agent 更适合以下场景：</div><ul class="notion-list notion-list-disc notion-block-72d2602c56e14e5aa7bfbb14afa73f84"><li><b>多轮动态决策</b> — 任务路径无法预先固定，需要根据中间结果灵活调整</li></ul><ul class="notion-list notion-list-disc notion-block-48df4aff3ded41118969957145de2771"><li><b>多工具 / 多数据源交互</b> — 需要在多个外部系统之间协调操作</li></ul><ul class="notion-list notion-list-disc notion-block-04ea826d7c7342b4a771b240500082b4"><li><b>用户意图模糊</b> — 需要系统先理解、澄清、拆解任务，再决定执行路径</li></ul><ul class="notion-list notion-list-disc notion-block-654f3dd6ca844e52b83b223e709d9ca5"><li><b>结果带有开放性</b> — 例如调研、分析、生成方案、制定计划等，本身就不是纯规则问题</li></ul><blockquote class="notion-quote notion-block-d50d15e75b014e40be750ca12750b9a8"><div>Workflow 与 Agent 并不完全对立。很多生产系统的最佳解法，往往是 <b>用 Workflow 承接确定性流程，用 Agent 处理不确定性环节</b>。</div></blockquote><hr class="notion-hr notion-block-431c5774e5c04052a18b6a82fd9d210d"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-fc32240ef2324c298007e82a9482beda" data-id="fc32240ef2324c298007e82a9482beda"><span><div id="fc32240ef2324c298007e82a9482beda" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fc32240ef2324c298007e82a9482beda" title="二、先判断任务类型，再设计系统"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">二、先判断任务类型，再设计系统</span></span></h2><div class="notion-text notion-block-943007d70e59402da0659a2c705c7462">设计 Agent 系统之前，一个很重要但经常被忽略的问题是：当前任务到底是<b>自由探索型</b>，还是<b>可枚举状态转换型（通常有几个稳定状态）</b>？</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-493b1e86954e44fba8e710246a882302" data-id="493b1e86954e44fba8e710246a882302"><span><div id="493b1e86954e44fba8e710246a882302" class="notion-header-anchor"></div><a class="notion-hash-link" href="#493b1e86954e44fba8e710246a882302" title="自由探索型任务"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">自由探索型任务</span></span></h3><div class="notion-text notion-block-a3b580fccea14af1af363d1a542414cd">这类任务的特点是：路径事先很难完全写死，中间需要边做边判断下一步。</div><div class="notion-text notion-block-d35c30ded2f04e7bb0316d53cd41af7f">典型例子：</div><ul class="notion-list notion-list-disc notion-block-5f224cf3e0be414aba1efd3838dce316"><li>调研某个技术方向</li></ul><ul class="notion-list notion-list-disc notion-block-f760e82484874e66a60208afd32dc399"><li>分析一个产品问题</li></ul><ul class="notion-list notion-list-disc notion-block-3b837dea5f804f06af988e28d14a9b5b"><li>阅读资料后形成观点</li></ul><ul class="notion-list notion-list-disc notion-block-f01301316bf748e9830a769ab178d013"><li>基于模糊目标提出方案</li></ul><div class="notion-text notion-block-756c96aec1fd4f6594b3c26513fe1673">这种任务更依赖模型的理解、归纳、搜索、判断和动态规划能力。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-aa280b3645bb4149a75f8a86366e3e12" data-id="aa280b3645bb4149a75f8a86366e3e12"><span><div id="aa280b3645bb4149a75f8a86366e3e12" class="notion-header-anchor"></div><a class="notion-hash-link" href="#aa280b3645bb4149a75f8a86366e3e12" title="可枚举状态转换型任务"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">可枚举状态转换型任务</span></span></h3><div class="notion-text notion-block-caa9fb2d52344dd08f814902173864e3">这类任务虽然也可能复杂，但整体流程通常可以拆成若干<b>稳定状态</b>，并且每一步从哪个状态走向哪个状态，大体是清楚的。</div><div class="notion-text notion-block-55a64d7447044e968aa23302952c9074">典型例子：</div><ul class="notion-list notion-list-disc notion-block-70ec7e2861d94e849b067bbf1cb803ed"><li>工单处理：新建 → 分类 → 分派 → 处理 → 关闭</li></ul><ul class="notion-list notion-list-disc notion-block-d9f8163f2b704506a5eac72352623587"><li>审批流程：提交 → 校验 → 审核 → 批准 / 驳回</li></ul><ul class="notion-list notion-list-disc notion-block-d1da174aab7b4d9b84075200580b0933"><li>代码交付：生成方案 → 编写代码 → 跑测试 → 修复 → 提交</li></ul><div class="notion-text notion-block-208d3529e3e9482cb762561b96bcdb78">这种任务更适合用 <b>状态机（State Machine）</b> 或 <b>工作流引擎（Workflow Engine）</b> 去实现，LLM 只需要作为某些节点的能力模块。</div><div class="notion-callout notion-block-ee81aaa247054410a5599606cf52f350"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="🧭">🧭</span></div><div class="notion-callout-text"><div class="notion-text notion-block-574445f937f5412b96a3a91c73c8825c">很多看起来像“Agent 架构”的系统，落到工程实现上，本质更接近<b>带大模型节点的状态机</b>。真正决定系统稳定性的，往往不是“有几个 Agent”，而是：状态如何流转、失败如何恢复、人工如何介入、工具结果如何落盘。</div></div></div><div class="notion-text notion-block-038b0e196ee240d3af7d95f252b1888f">因此，设计架构时可以多问几个更现实的问题：</div><ul class="notion-list notion-list-disc notion-block-05ecfb5013804c958adc26318595ddd9"><li>当前任务能不能画成几个比较稳定的状态？</li></ul><ul class="notion-list notion-list-disc notion-block-6f0f6ceeb07b42b9834671eb24300663"><li>出错后是让模型“继续想”，还是回到某个明确节点重试？</li></ul><ul class="notion-list notion-list-disc notion-block-ad565ef108ee435087c5eaa7a90c9fe2"><li>多个模块之间传递的是自然语言，还是结构化状态？</li></ul><ul class="notion-list notion-list-disc notion-block-32973f2495ae46129a7cfc35628ad3c9"><li>人工审批插在哪一步，审批结果如何写回系统？</li></ul><hr class="notion-hr notion-block-808e2f71bc7f4e8f999138e8839efafe"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6be0b98c79ff435bb5010d443f8d0ea9" data-id="6be0b98c79ff435bb5010d443f8d0ea9"><span><div id="6be0b98c79ff435bb5010d443f8d0ea9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6be0b98c79ff435bb5010d443f8d0ea9" title="三、搭建Agent流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">三、搭建Agent流程</span></span></h2><div class="notion-text notion-block-47c4c1cf693f4bffb0618038a070956e">一般来说，设计一个 Agent 系统可以遵循下面这条主线：</div><div class="notion-text notion-block-089fb98d67264124bfa263e30771c337">这条线索背后的重点不是“让模型更聪明”，而是把系统里真正影响稳定性的部分都显式设计出来。</div><hr class="notion-hr notion-block-beb8a0bc886d46a7a09544c067f1ecda"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-d3dc039b5fa542dc99c107dc6d773fd5" data-id="d3dc039b5fa542dc99c107dc6d773fd5"><span><div id="d3dc039b5fa542dc99c107dc6d773fd5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d3dc039b5fa542dc99c107dc6d773fd5" title="四、常见的 Agent 架构模式"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">四、常见的 Agent 架构模式</span></span></h2><div class="notion-text notion-block-5f80b0f61bd74e008b14804e84a13622">在“设计架构”这一步，常见模式有下面几类：</div><table class="notion-simple-table notion-block-b6b31c4009f143ac939db14d32f09212"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-ef9011a698174a4f8b976f0b17390405"><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>模式</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>说明</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>适用场景</b></div></td></tr><tr class="notion-simple-table-row notion-block-09e7ce2942f045df990f76db3187d5db"><td class="" style="width:120px"><div class="notion-simple-table-cell">单 Agent（ReAct / Tool-use）</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">一个 Agent 负责理解任务、调用工具、汇总结果</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">任务相对单一、工具数量可控、链路较短</div></td></tr><tr class="notion-simple-table-row notion-block-9a62e6e7755a4977b7a2f4db753719f9"><td class="" style="width:120px"><div class="notion-simple-table-cell">多 Agent 协作</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">多个 Agent 分工合作，例如规划、执行、审查分别由不同角色承担</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">复杂任务需要多角色、多专长或多层校验</div></td></tr><tr class="notion-simple-table-row notion-block-cfc9d03627874be1a3eadf28ad7bc001"><td class="" style="width:120px"><div class="notion-simple-table-cell">层级式（Orchestrator + Workers）</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">一个编排 Agent 负责任务拆解与调度，Workers 可以是工具、函数，或具备一定自主能力的子 Agent（subagent）</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">任务可拆解，子任务之间相对独立</div></td></tr><tr class="notion-simple-table-row notion-block-3b5d6f2c53594fba9d12dce0112837c1"><td class="" style="width:120px"><div class="notion-simple-table-cell">Workflow + LLM 节点</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">整体流程由工作流控制，LLM 只在个别节点负责分类、抽取、生成、判断</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">流程稳定但局部需要智能决策的业务系统</div></td></tr></tbody></table><div class="notion-text notion-block-6f5a9ae1725d44888294ba2aeb01236c"><b>先把单 Agent + 工具调用 + 状态流转做好，再考虑多 Agent，通常更稳。</b></div><hr class="notion-hr notion-block-d9bb474f01014679bb3115d8d1d69b75"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-a2c9184c87af43d7bc2b23afbe02ac31" data-id="a2c9184c87af43d7bc2b23afbe02ac31"><span><div id="a2c9184c87af43d7bc2b23afbe02ac31" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a2c9184c87af43d7bc2b23afbe02ac31" title="五、Prompt 工程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">五、Prompt 工程</span></span></h2><div class="notion-text notion-block-cfe7b3e1a36a42278d2b2bf34b2ac81a">系统指令（System Prompt）仍然是 Agent 行为的重要驱动力，但在生产环境中，重点已经不再只是“怎么写一个更厉害的 Prompt”，而是如何让模型在一个<b>受控框架</b>里工作。</div><div class="notion-text notion-block-19606abffd7549de89d3899b087216df">常见关注点包括：</div><ul class="notion-list notion-list-disc notion-block-30b0c5766baf43fa92cf14e8a2ca8099"><li><b>角色设定</b> — 明确 Agent 的身份、能力边界和行为风格</li></ul><ul class="notion-list notion-list-disc notion-block-0fe48e53b2fa4f4b827edf93ea877e20"><li><b>Few-shot 示例</b> — 提供典型输入输出样例，引导模型理解预期格式</li></ul><ul class="notion-list notion-list-disc notion-block-1226ecbddafa45f3a67f922811ebb6dd"><li><b>输出格式约束</b> — 指定 JSON、Markdown 等结构化输出格式</li></ul><ul class="notion-list notion-list-disc notion-block-6ec93668437f4ac4bf569eb90b5e92c5"><li><b>边界条件处理</b> — 明确当信息不足或遇到异常时的行为（如拒答、追问、降级）</li></ul><ul class="notion-list notion-list-disc notion-block-c580ad2b8a8d487186e691ddc31b34ea"><li><b>工具使用规则</b> — 明确哪些工具能用、何时能用、参数格式是什么、调用失败如何处理</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-e6df2a07682e4b518f5d57d88ea253ed" data-id="e6df2a07682e4b518f5d57d88ea253ed"><span><div id="e6df2a07682e4b518f5d57d88ea253ed" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e6df2a07682e4b518f5d57d88ea253ed" title="什么是推理过程控制？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是推理过程控制？</span></span></h3><div class="notion-text notion-block-5735c553ff6e4a4689d456d0f082ebbd">很多早期做法会强调让模型显式输出长篇 Chain-of-Thought，似乎只要“想得够多”，复杂任务就会更可靠。但工程上更常见的结论是：<b>稳定性更多来自任务拆解、状态管理和工具约束，而不是来自更长的自然语言思维过程。</b></div><div class="notion-text notion-block-68a362ac579e4e089e5138f452a26cb4">更推荐的做法通常包括：</div><ul class="notion-list notion-list-disc notion-block-cb6e2687c6d841e6a1406a2104ce6eda"><li><b>任务拆解</b>：把大任务拆成一系列目标明确的小步骤</li></ul><ul class="notion-list notion-list-disc notion-block-fd83d2379ff74747b410de40c63f46b8"><li><b>结构化中间结果</b>：让模型输出机器可读的中间结果，而不是大段随意文本</li></ul><ul class="notion-list notion-list-disc notion-block-b7d0eceab3ea4df2a65d07d1f534f3dc"><li><b>工具调用约束</b>：限制可调用工具、调用顺序和参数格式</li></ul><ul class="notion-list notion-list-disc notion-block-a4f1ba7a423d42a88a54dedc12026b27"><li><b>可检查的计划</b>：让计划本身可被系统校验、人工修改、失败恢复</li></ul><div class="notion-text notion-block-943f8f03edff45aba5b2f158a8e76fa0">生产环境通常更关注三件事：</div><ul class="notion-list notion-list-disc notion-block-86ec1ce343dc4f52a93c5161f59b14e6"><li><b>结果可验证</b>：不是“看起来像对的”，而是能通过规则、测试或工具结果验证</li></ul><ul class="notion-list notion-list-disc notion-block-8b9407dc0ca94056a2eb659ce01ad06e"><li><b>步骤可回放</b>：系统知道每一步做了什么，便于调试、审计和优化</li></ul><ul class="notion-list notion-list-disc notion-block-a8af6cc8c26d47afa76233f616342fc0"><li><b>失败可恢复</b>：某一步出错时，可以回到节点重试，而不是整条链路全部重来</li></ul><hr class="notion-hr notion-block-ab8275d3435c4ccdb3a32a7919d35a50"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-7caaf1498b374c729cb9b836632770b0" data-id="7caaf1498b374c729cb9b836632770b0"><span><div id="7caaf1498b374c729cb9b836632770b0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7caaf1498b374c729cb9b836632770b0" title="六、记忆与上下文管理：不是记得越多越好，而是拿到对的上下文"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">六、记忆与上下文管理：不是记得越多越好，而是拿到对的上下文</span></span></h2><div class="notion-text notion-block-ff8b54fd954c4bf78ae021c25a9952f3">很多早期文章会把 Agent 的“记忆”理解为把信息长期存起来，但在当前主流实践中，更重要的往往不是“记住更多”，而是<b>在合适的时机，把合适的信息放进当前上下文</b>。</div><div class="notion-text notion-block-b17350b25f47498d930cfdc515101a3e">因此，与其单独强调记忆，不如把这一层理解为：</div><div class="notion-text notion-block-2c67ddee23da42ff8804cdd130ad66ec"><b>上下文工程（Context Engineering）+ 状态管理（State Management）+ 检索增强（Retrieval）</b>。</div><div class="notion-text notion-block-2c14989b9c80440784d3110cddacffb6">更贴近实际落地的划分通常是：</div><ul class="notion-list notion-list-disc notion-block-625fb149264a468a8836a7657eca8f33"><li><b>会话上下文（Session Context）</b> — 当前轮对话、系统指令、最近几步工具调用结果，以及当前任务约束</li></ul><ul class="notion-list notion-list-disc notion-block-f61b13373796426298ae66922e42b10d"><li><b>任务状态（Task State）</b> — 当前任务的显式状态，例如计划、待办、子任务结果、失败记录、审批状态</li></ul><ul class="notion-list notion-list-disc notion-block-21402c7df2ef4e2096e5fe42249eacab"><li><b>外部知识（External Knowledge）</b> — 文档、知识库、工单、代码、网页等，通过检索系统按需取回</li></ul><ul class="notion-list notion-list-disc notion-block-7384d2ec39d04638a26bb937e7f3519c"><li><b>用户偏好 / 档案（Profile / Preferences）</b> — 少量稳定、结构化、可编辑的长期信息</li></ul><div class="notion-text notion-block-f9f9d85771324f0e85c0ec3a2bb7a87f">目前主流 Agent 更常见的是下面几种做法：</div><ol start="1" class="notion-list notion-list-numbered notion-block-b06d3704b2b3455dafb9283a751c957c" style="list-style-type:decimal"><li><b>滑动窗口 + 摘要压缩</b>：保留最近关键交互，对更早内容做摘要，但摘要要可回溯，否则容易累积偏差</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-0a973d730a684f5781dbcdcd258234fd" style="list-style-type:decimal"><li><b>RAG / 按需检索</b>：把“知道什么”交给检索系统，而不是全部塞进长期记忆</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-1a1c087d380a4a31a3a33c690255431a" style="list-style-type:decimal"><li><b>显式状态存储</b>：把任务进度、中间结果、工具输出、审批节点存到结构化状态中</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-89736a0dbadf4a33830bdc33f75ce679" style="list-style-type:decimal"><li><b>事件日志与可观测性</b>：记录每一步决策、工具调用和失败原因，便于调试、审计和恢复</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-3fc2c6d7961248819a98047d25bc7e93" style="list-style-type:decimal"><li><b>记忆写入门控</b>：长期记忆不是越多越好，需要去重、打分、时效控制和人工可编辑能力</li></ol><div class="notion-text notion-block-f7575f4a6c354050839a5286b2b4220d">因此，所谓“长期记忆”在很多生产系统里并不是默认核心能力。真正关键的是：<b>让 Agent 在当前步骤拿到完成任务所需的最小充分上下文，并用结构化状态保证流程稳定。</b></div><hr class="notion-hr notion-block-342d690ad6d180b8b8fac04d72b554f1"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-54a3b00ccae5473697c0cd2f7931e28c" data-id="54a3b00ccae5473697c0cd2f7931e28c"><span><div id="54a3b00ccae5473697c0cd2f7931e28c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#54a3b00ccae5473697c0cd2f7931e28c" title="七、多 Agent，不一定比单 Agent 更高级"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">七、多 Agent，不一定比单 Agent 更高级</span></span></h2><div class="notion-text notion-block-b3a846ff67794ff4bab0aeae82b95a93">多 Agent 是一个很容易被高估的方向。它适合某些复杂场景，但并不天然优于单 Agent。</div><div class="notion-text notion-block-b55f0a2f3067409a8c2327175c92f16c">适合引入多 Agent 的情况通常包括：</div><ul class="notion-list notion-list-disc notion-block-367dc38218324286912d633146d3d1fb"><li>任务天然可分治，不同子任务需要不同工具或专业能力</li></ul><ul class="notion-list notion-list-disc notion-block-d91c2911ef89477c8407e65ef4474f18"><li>需要明确的“规划—执行—校验”分层</li></ul><ul class="notion-list notion-list-disc notion-block-5b993bff863c441e8de383e3bfa44836"><li>不同角色之间需要相互制衡，例如生成、审查、审批</li></ul><div class="notion-text notion-block-b7e89ce68c6a49d995a81b55b3350aed">但多 Agent 也会引入新的成本：</div><ul class="notion-list notion-list-disc notion-block-f3ff270330ae4b97ae9a01892d142936"><li><b>上下文传递成本</b>：如果 Agent 之间主要依赖自然语言传递信息，容易造成信息漂移</li></ul><ul class="notion-list notion-list-disc notion-block-aa34d83b17e04e7088af4408d1ecd177"><li><b>状态同步成本</b>：多个 Agent 同时读写共享状态时，更容易出现冲突和重复执行</li></ul><ul class="notion-list notion-list-disc notion-block-a4c050fb4b704cb79697d529741af766"><li><b>调试复杂度</b>：问题可能来自提示词、路由逻辑、工具调用、协作协议中的任意一层</li></ul><div class="notion-text notion-block-5e8da50481084204b6e16d649b2e8b0b">所以一个更实用的经验是：<b>能用单 Agent + 明确工作流解决的问题，不必急着拆成多 Agent。</b></div><div class="notion-text notion-block-e1c7cb6c06c74ea5aa92e51d606ca2b4">很多“多 Agent 系统”最后稳定运行的关键，并不是 agent 数量，而是共享状态定义清楚、交接协议简单、失败路径可控。</div><hr class="notion-hr notion-block-8820d4ab19d04410b25b815a55653886"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-992b60ae96174e54b9a801aae3875d6a" data-id="992b60ae96174e54b9a801aae3875d6a"><span><div id="992b60ae96174e54b9a801aae3875d6a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#992b60ae96174e54b9a801aae3875d6a" title="八、安全与护栏"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">八、安全与护栏</span></span></h2><div class="notion-text notion-block-8d11830ff6cc4c6d90ae0d81d5c13cc6">Agent 的风险通常不只来自“说错话”，更来自它<b>能不能访问系统、能不能调用工具、会不会把错误决策放大成真实操作</b>。</div><div class="notion-text notion-block-075bbfba19f947f7ae870fe79db857e3">因此，安全与护栏至少要覆盖下面几个层面：</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-f5ab611fb3b0407e8bea31ca23388120" data-id="f5ab611fb3b0407e8bea31ca23388120"><span><div id="f5ab611fb3b0407e8bea31ca23388120" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f5ab611fb3b0407e8bea31ca23388120" title="1. 输入安全"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 输入安全</span></span></h3><ul class="notion-list notion-list-disc notion-block-e58738c10ce34b3fbe0576e42aaab6cd"><li><b>Prompt Injection 防护</b>：防止外部文本诱导模型忽略系统规则</li></ul><ul class="notion-list notion-list-disc notion-block-c58a571634204a14bc059df72ce5f8ef"><li><b>恶意内容识别</b>：识别越权请求、社会工程、敏感数据提取等风险输入</li></ul><ul class="notion-list notion-list-disc notion-block-22c1a3e5fdfb4d9e88640e013b6ae972"><li><b>上下文隔离</b>：避免不可信内容与高权限系统指令混在同一层级生效</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5b41b713d5db4de489114aaa99dbdaf7" data-id="5b41b713d5db4de489114aaa99dbdaf7"><span><div id="5b41b713d5db4de489114aaa99dbdaf7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5b41b713d5db4de489114aaa99dbdaf7" title="2. 输出安全"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 输出安全</span></span></h3><ul class="notion-list notion-list-disc notion-block-14779c232ffa4ceebb434a769e2f6366"><li><b>敏感信息过滤</b>：避免输出隐私数据、密钥、内部配置、商业机密</li></ul><ul class="notion-list notion-list-disc notion-block-7d06f4b1e49040c981e2c61cc953bae9"><li><b>合规检查</b>：对特定业务场景做内容审查，例如金融、医疗、法律等</li></ul><ul class="notion-list notion-list-disc notion-block-04e09cd63e834d28b3d0f806e8c2cf3b"><li><b>高风险操作前确认</b>：在给出执行建议和实际执行动作之间加一道确认或审批</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2a187c539fae46deb5328e8f301dce87" data-id="2a187c539fae46deb5328e8f301dce87"><span><div id="2a187c539fae46deb5328e8f301dce87" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2a187c539fae46deb5328e8f301dce87" title="3. 工具调用安全"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 工具调用安全</span></span></h3><ul class="notion-list notion-list-disc notion-block-c04b6c2889e747158ecb72810db18ade"><li><b>最小权限原则</b>：Agent 只拿到完成任务所需的最低权限</li></ul><ul class="notion-list notion-list-disc notion-block-6b9a8d54d20640d1added7663f0bce77"><li><b>工具白名单</b>：限制可调用工具范围，而不是默认全开</li></ul><ul class="notion-list notion-list-disc notion-block-9ce1fd612871449c90bcde7f1a281e02"><li><b>参数校验</b>：对工具调用参数做格式和范围检查</li></ul><ul class="notion-list notion-list-disc notion-block-10bf94d0c9614342b1ac60b6e5641ce1"><li><b>写操作分级</b>：读、写、删除、发布、转账等操作应该有不同等级的保护</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-072a05da17604db787786798220f8e6e" data-id="072a05da17604db787786798220f8e6e"><span><div id="072a05da17604db787786798220f8e6e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#072a05da17604db787786798220f8e6e" title="4. 执行过程护栏"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. 执行过程护栏</span></span></h3><ul class="notion-list notion-list-disc notion-block-acd622332a2c4892bf29d52fcde29e5e"><li><b>最大轮次 / 最大预算限制</b>：防止无限循环与成本失控</li></ul><ul class="notion-list notion-list-disc notion-block-d2b3810618084ce3b276d7cf13fb8d1c"><li><b>速率限制与熔断</b>：避免工具风暴、异常重试和外部系统被打爆</li></ul><ul class="notion-list notion-list-disc notion-block-a4502c83eee24271b956f4bc2cb49471"><li><b>人工介入点</b>：在关键节点支持人工审核、驳回或接管</li></ul><ul class="notion-list notion-list-disc notion-block-4707214e5b5c44e8b8faa9be600fc51a"><li><b>审计日志</b>：记录关键决策、工具调用、参数和结果，满足调试与追责需要</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-46f45de067af40ea94d12dd8a4cccd67" data-id="46f45de067af40ea94d12dd8a4cccd67"><span><div id="46f45de067af40ea94d12dd8a4cccd67" class="notion-header-anchor"></div><a class="notion-hash-link" href="#46f45de067af40ea94d12dd8a4cccd67" title="5. 记忆与数据安全"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5. 记忆与数据安全</span></span></h3><ul class="notion-list notion-list-disc notion-block-def3bfa5a1ba494492ac32b93c5c749f"><li><b>长期记忆可编辑、可删除、可追踪来源</b></li></ul><ul class="notion-list notion-list-disc notion-block-7a1be9a5ee3a415bae521485db9776b8"><li><b>避免把未清洗的原始对话直接长期保存并参与后续决策</b></li></ul><ul class="notion-list notion-list-disc notion-block-5d82e166e58941e998b051e32b32904b"><li><b>区分用户数据、系统数据和检索到的外部数据的信任等级</b></li></ul><hr class="notion-hr notion-block-d1ccb3774df94ff8930772c5b5109d4f"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6fb895d3002e493eac657877516a4b92" data-id="6fb895d3002e493eac657877516a4b92"><span><div id="6fb895d3002e493eac657877516a4b92" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6fb895d3002e493eac657877516a4b92" title="九、评估与测试"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">九、评估与测试</span></span></h2><div class="notion-text notion-block-7ac8027ed32843b48ca98d40b19d49ca">Agent 系统的难点在于，它不是一个只有固定输入输出的函数。你不仅要看最终结果，还要看过程是否稳定、工具调用是否正确、在异常情况下是否还能工作。</div><div class="notion-text notion-block-ef3a944088d04d1da566790243782cda">因此，评估与测试至少要分成几个层次来看：</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-65a161805837468c965cd5254d2e8269" data-id="65a161805837468c965cd5254d2e8269"><span><div id="65a161805837468c965cd5254d2e8269" class="notion-header-anchor"></div><a class="notion-hash-link" href="#65a161805837468c965cd5254d2e8269" title="1. 能力评测"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 能力评测</span></span></h3><div class="notion-text notion-block-91e24f0350b2457ba9fddddf4bed6f93">这部分关注 Agent“会不会做”。</div><div class="notion-text notion-block-341d690ad6d1803ebf1bebec6f63c10c">常见方式包括：</div><ul class="notion-list notion-list-disc notion-block-6c4e79a363e54d3abb3cbca6296ceb56"><li><b>基于 Benchmark 的自动评测</b> — 用标准数据集或内部题集量化分类、抽取、规划、工具使用等能力</li></ul><ul class="notion-list notion-list-disc notion-block-13ac524056074536b2e6c607ee31198a"><li><b>任务集评测</b> — 基于真实业务样本构造评测集，比通用 benchmark 更有价值</li></ul><ul class="notion-list notion-list-disc notion-block-7a52ef5aa98b4f5290b5d3fabf50858a"><li><b>人工评审</b> — 对开放性任务的质量、可用性、表达方式做主观打分</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5831d815fc8044ca8e03521c10d407f4" data-id="5831d815fc8044ca8e03521c10d407f4"><span><div id="5831d815fc8044ca8e03521c10d407f4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5831d815fc8044ca8e03521c10d407f4" title="2. 流程正确性测试"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 流程正确性测试</span></span></h3><div class="notion-text notion-block-bf61646619da418382719f999a048b79">这部分关注 Agent“是不是按预期流程工作”。</div><div class="notion-text notion-block-ec61d708362a49ff863c7ddf3aa521ce">需要重点看：</div><ul class="notion-list notion-list-disc notion-block-e76390e1b1f44f87953889580dc91677"><li>是否调用了不该调用的工具</li></ul><ul class="notion-list notion-list-disc notion-block-7c03a8e458ad49dbb629289b5f739f5a"><li>是否遗漏关键步骤</li></ul><ul class="notion-list notion-list-disc notion-block-7a8ce4d0d4ee408a84dd56bfc0fb2e5c"><li>是否在错误节点重复循环</li></ul><ul class="notion-list notion-list-disc notion-block-f800244896df4df38a2d082d3848a439"><li>是否正确遵守输出格式与约束</li></ul><ul class="notion-list notion-list-disc notion-block-88c7d25805a141dd811b0fb25ae4823a"><li>是否在需要审批时停下来</li></ul><div class="notion-text notion-block-b94063c8caad4a3dab1f61340333548f">这类测试往往比单纯看最终答案更重要，因为很多系统是“结果偶尔看着还行，但过程完全不可控”。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-11d6c026db7a4e8dba99bf320fb931fd" data-id="11d6c026db7a4e8dba99bf320fb931fd"><span><div id="11d6c026db7a4e8dba99bf320fb931fd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#11d6c026db7a4e8dba99bf320fb931fd" title="3. 端到端回归测试"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 端到端回归测试</span></span></h3><div class="notion-text notion-block-9da38c95d4cc4db69a6416f77e48c842">每次修改 Prompt、模型版本、工具定义、上下文拼接逻辑后，都可能引入新问题。</div><div class="notion-text notion-block-380273b83eab4a3592eba89d86c1901d">所以需要有一套端到端回归用例，用来验证：</div><ul class="notion-list notion-list-disc notion-block-4d79335415fc44a794570c8259a0ba12"><li>老问题有没有复发</li></ul><ul class="notion-list notion-list-disc notion-block-5d7130b4374e4ba19158a3ba0618013b"><li>原本能完成的任务有没有退化</li></ul><ul class="notion-list notion-list-disc notion-block-97ed5ee27a3a4108b13e3bb4f515151f"><li>工具链路有没有被新的改动破坏</li></ul><ul class="notion-list notion-list-disc notion-block-c8eea0784a554836b46a794259826bf7"><li>输出格式和系统接口是否仍兼容</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-c81d3f03ae514c23abcf570286b541f1" data-id="c81d3f03ae514c23abcf570286b541f1"><span><div id="c81d3f03ae514c23abcf570286b541f1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c81d3f03ae514c23abcf570286b541f1" title="4. 异常与对抗测试"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. 异常与对抗测试</span></span></h3><div class="notion-text notion-block-83b43083ae3445f5b8d9a9419578270d">很多问题并不会在正常样例里暴露出来，所以还需要专门测：</div><ul class="notion-list notion-list-disc notion-block-cc9382b9eb9c4d0f9143f84ebebe7d15"><li>工具超时 / 返回错误</li></ul><ul class="notion-list notion-list-disc notion-block-12a84211ed8f49a0b6a072f4e0183548"><li>检索不到结果</li></ul><ul class="notion-list notion-list-disc notion-block-6e904f557bfa4e8eb00ce57a168dd69b"><li>用户输入含歧义或恶意注入</li></ul><ul class="notion-list notion-list-disc notion-block-5d46a508ee1246768eb620e060dfdbc2"><li>上下文过长导致截断</li></ul><ul class="notion-list notion-list-disc notion-block-00d771f8ae7f46afb44687ee6c8eba24"><li>中间状态损坏或部分缺失</li></ul><div class="notion-text notion-block-7110f0e5cbef4c8190d2f19aabcd0eeb">一个真正可上线的 Agent，不只是“正常情况能做对”，还要在异常情况下<b>可降级、可恢复、可解释</b>。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-66591f90c847469aa6794c16d597b01b" data-id="66591f90c847469aa6794c16d597b01b"><span><div id="66591f90c847469aa6794c16d597b01b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#66591f90c847469aa6794c16d597b01b" title="5. 线上观测与持续评估"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5. 线上观测与持续评估</span></span></h3><div class="notion-text notion-block-88593f05c2c24c2e8722581672e0e1e6">上线之后，测试并没有结束。</div><div class="notion-text notion-block-287856cdc70f48989362a475e7d73833">还需要持续关注：</div><ul class="notion-list notion-list-disc notion-block-16fa052b81564f6183b10d174975942b"><li>成功率、失败率、平均轮次、工具调用次数</li></ul><ul class="notion-list notion-list-disc notion-block-e3284d26c6a34a5e865c15333b687b3f"><li>成本、耗时、重试次数、人工接管比例</li></ul><ul class="notion-list notion-list-disc notion-block-570ba2b07f654c4fbf734764b38a6449"><li>常见失败模式，例如规划错误、检索错误、工具参数错误、状态丢失</li></ul><ul class="notion-list notion-list-disc notion-block-55190f960bfb4e74b6d20e93051e56b7"><li>用户反馈中的高频抱怨点</li></ul><hr class="notion-hr notion-block-8cbbc92ded1946d0bc737a8016b11c6d"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-73e57135f06c47f3b03dff9cc9a9580a" data-id="73e57135f06c47f3b03dff9cc9a9580a"><span><div id="73e57135f06c47f3b03dff9cc9a9580a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#73e57135f06c47f3b03dff9cc9a9580a" title="十、总结精华"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">十、总结精华</span></span></h2><div class="notion-text notion-block-069c2c91e5cd4f809be3d7f92d697b70">如果把这篇文章压缩成几句最重要的话，大概是这样：</div><ul class="notion-list notion-list-disc notion-block-4f7ace76f9cc4b2ea514ccc3cda743dc"><li>不是所有问题都需要 Agent，很多时候 Workflow 更好</li></ul><ul class="notion-list notion-list-disc notion-block-1f979f0405c6483894a1cb4238ee0d61"><li>设计之前，先判断任务是自由探索型还是可枚举状态转换型</li></ul><ul class="notion-list notion-list-disc notion-block-67c4059c9390496ea8deab28e0066b16"><li>很多所谓 Agent 系统，本质上是带 LLM 节点的状态机</li></ul><ul class="notion-list notion-list-disc notion-block-8a2d5af5ec60434badc8f4b300881511"><li>复杂任务的稳定性，更多来自状态、约束、检索和流程，而不是更长的 Chain-of-Thought</li></ul><ul class="notion-list notion-list-disc notion-block-6db99dc890f04f07aaad7908a42a72e8"><li>记忆不是越多越好，很多系统真正需要的是把对的信息放进对的上下文</li></ul><ul class="notion-list notion-list-disc notion-block-811d948669914f0e9a7226e434b105cb"><li>多 Agent 不天然更高级，能不用就别滥用</li></ul><div class="notion-text notion-block-342d690ad6d1801885edd3f1a6dbd1a7">很多人说AI时代学得慢就可以不用学，对于普通人来说或许是对的，面向他们的AI应用一定是足够简单且不需要复杂的知识和操作。但对于程序员来说，即便不从事agent开发的工作，了解一些基本概念也是必要的，尽管很多东西都像是受限于模型能力而不得不暂时使用的“中间态”。</div><div class="notion-blank notion-block-342d690ad6d180638fedd3cb4c8c5c31"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NotionNext：重新定义写博客这件事]]></title>
            <link>https://www.junlin-233.top/article/notionnext</link>
            <guid>https://www.junlin-233.top/article/notionnext</guid>
            <pubDate>Sat, 18 Apr 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[无需服务器、无需懂代码，借助 Notion 笔记 + NotionNext + Vercel，几分钟即可搭建一个完全属于自己的独立博客。本文梳理 NotionNext 建站的大致流程与关键思路。]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-346d690ad6d18076b14bc86eb38f392e"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-ed9bae668c1f43efb8171a32c4455a81"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="💡">💡</span></div><div class="notion-callout-text"><div class="notion-text notion-block-60d0c9632f9b494487815ce23964a9de">如果你厌倦了传统的md文件写博客，想要一种更简便更高效的办法，那么我强烈推荐使用这套NotionNext部署博客，在notion里写的文章无感同步到你的网站，即便不懂代码也能快速上手。</div></div></div><div class="notion-blank notion-block-346d690ad6d180df98c8f45319e3f1cf"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-2d2809b5cba04e59996e0c5dd5bdd2f7" data-id="2d2809b5cba04e59996e0c5dd5bdd2f7"><span><div id="2d2809b5cba04e59996e0c5dd5bdd2f7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2d2809b5cba04e59996e0c5dd5bdd2f7" title="什么是 NotionNext"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">什么是 NotionNext</span></span></h2><div class="notion-text notion-block-1fece6e1d0b8455cab6ce8e445649e7a">NotionNext 是一个基于 Next.js 的开源 Notion 建站工具，它会把你的 Notion 笔记实时渲染成一个静态博客站点。</div><div class="notion-text notion-block-63963675ee054585b1d236f525fda7de">核心特点：</div><ul class="notion-list notion-list-disc notion-block-f8619ae27b4344c39fa8878dd173c7e2"><li><b>写作在 Notion</b>：所有文章都在 Notion 数据库里编辑，发布即同步。</li></ul><ul class="notion-list notion-list-disc notion-block-c9e05b63dad04d67ae3a573b67be2507"><li><b>免费开源</b>：源码托管在 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/tangly1024/NotionNext">GitHub</a>，可自行fork后修改。</li></ul><ul class="notion-list notion-list-disc notion-block-628cb272b8ee4d96bbfe0bdeeb8d6450"><li><b>无需服务器</b>：通常部署到 Vercel，免费额度足够个人博客使用。</li></ul><ul class="notion-list notion-list-disc notion-block-b52409cdf4dd47c39d32ab97c10f16c9"><li><b>多主题可选</b>：内置数十款主题，覆盖博客、文档、导航站、落地页、相册等场景。</li></ul><ul class="notion-list notion-list-disc notion-block-9467426ced724901a367a50957bf7c9d"><li><b>SEO 友好</b>：基于 Next.js 服务端渲染，有利于被搜索引擎收录。</li></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-406c920d224c4c70bb008cb004f51f06" data-id="406c920d224c4c70bb008cb004f51f06"><span><div id="406c920d224c4c70bb008cb004f51f06" class="notion-header-anchor"></div><a class="notion-hash-link" href="#406c920d224c4c70bb008cb004f51f06" title="搭建博客的大致流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">搭建博客的大致流程</span></span></h2><div class="notion-text notion-block-bb9c0c7474b74d92be9e66ec404cb91e">由于官方的教程文档写的足够详细，所以本文就简要带过。</div><div class="notion-text notion-block-346d690ad6d180f183d2c5626e03cc18">整体流程可以概括为下面这张图：</div><div class="notion-text notion-block-97aab50511bc457d819bedb3afcc7896">简要说明：</div><ol start="1" class="notion-list notion-list-numbered notion-block-c81cb1479a80493f8fb7023b00333f0e" style="list-style-type:decimal"><li><b>准备账号</b>：Notion、GitHub、Vercel，最好再加一个自己的域名。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-b3d9d3750d9f4740a2282d290199f49b" style="list-style-type:decimal"><li><b>复制模板 + 部署</b>：复制官方 Notion 模板拿到 Page ID，Fork NotionNext 仓库后在 Vercel 里导入，填入 <code class="notion-inline-code">NOTION_PAGE_ID</code>，点 Deploy 即可拿到一个 <code class="notion-inline-code">xxx.vercel.app</code> 的站点。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-1b807edf02154ebda62c978938523b72" style="list-style-type:decimal"><li><b>配置 + 域名</b>：在 Notion 的 Config 页和代码里的 <code class="notion-inline-code">blog.config.js</code> 改站点名、主题、菜单等；建议在 Vercel 里绑定自己的域名。</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-cdccdec06a2045248c6cf258128b7e28" style="list-style-type:decimal"><li><b>开始写作</b>：在 Notion 文章数据库里新建页面，把 <code class="notion-inline-code">type</code> 设为 <code class="notion-inline-code">Post</code>、<code class="notion-inline-code">status</code> 设为 <code class="notion-inline-code">Published</code>，保存后站点会自动同步。</li></ol><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-fcc5643cb8ab4df9a22afc15856fc490" data-id="fcc5643cb8ab4df9a22afc15856fc490"><span><div id="fcc5643cb8ab4df9a22afc15856fc490" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fcc5643cb8ab4df9a22afc15856fc490" title="进阶方向"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">进阶方向</span></span></h2><div class="notion-text notion-block-0895167e7cf1431b8bf8dd34c8ef63dd">在过去，折腾博客主题基本是技术爱好者的专利——普通人想在模板上改点东西不仅费时费力，还可能直接把站点改崩。但在 LLM 时代，这些都不是问题。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-d7ce56a206ff4adc80705ed18fbf3291" data-id="d7ce56a206ff4adc80705ed18fbf3291"><span><div id="d7ce56a206ff4adc80705ed18fbf3291" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d7ce56a206ff4adc80705ed18fbf3291" title="个性化你的博客"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">个性化你的博客</span></span></h3><div class="notion-text notion-block-d7ead00adfb7403885fafe3a39a20eb0">步骤其实很简单：你只需要把fork的项目存到本地，无论用<b>codex桌面版</b>（对无代码基础的同学更友好，强烈推荐），<b>claude code</b>还是<b>opencode</b>，只需告诉AI你的需求（相信我，现在的LLM水平足够创建出你想要的博客），等它工作完再推送到github仓库，就这么简单，唯一比较烧脑的部分是你需要让AI明白你的需求（你在提示词花费的时间绝对物超所值）。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-346d690ad6d180df86f8c26c272f8595" data-id="346d690ad6d180df86f8c26c272f8595"><span><div id="346d690ad6d180df86f8c26c272f8595" class="notion-header-anchor"></div><a class="notion-hash-link" href="#346d690ad6d180df86f8c26c272f8595" title="让 AI 帮你写文章"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">让 AI 帮你写文章</span></span></h3><div class="notion-text notion-block-23cf028c95544f50a83f361b1f09370f">此外如果你像我一样连文章都懒得全部手打了，无论是用notion内置的LLM还是用notion mcp（<b>codex桌面版</b>完美适配）都可以帮助你快速构建文章，当然，核心部分还是需要你打，不然就没有意义了，不是吗？</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-346d690ad6d1803a8ea4c61be2c7f663" data-id="346d690ad6d1803a8ea4c61be2c7f663"><span><div id="346d690ad6d1803a8ea4c61be2c7f663" class="notion-header-anchor"></div><a class="notion-hash-link" href="#346d690ad6d1803a8ea4c61be2c7f663" title="小结"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">小结</span></span></h2><div class="notion-text notion-block-a7bae055d5e54e63b4fa62ed9028dfba">回过头看，NotionNext 做的事情其实只有一件：<b>把 Notion 变成你博客的后台，把发布、渲染、部署这些脏活累活全部抽象掉</b>。你要做的，只是打开 Notion，写下今天想说的话。</div><div class="notion-text notion-block-083235e378c84719ae0a7d3b81bbd5a8">对我来说，它的价值不在于&quot;又多了一个博客系统&quot;，而在于<b>大幅降低了持续写作的门槛</b>：</div><ul class="notion-list notion-list-disc notion-block-835aae00ab5f42bc92a45d7fd6619b63"><li>不用切换编辑器，想到什么随手就能写；</li></ul><ul class="notion-list notion-list-disc notion-block-57dc04131f784bb98d3178d406c57f6a"><li>不用操心构建和部署，保存即发布；</li></ul><ul class="notion-list notion-list-disc notion-block-346d690ad6d1800cb47ccb6b9c4007f7"><li>配合 AI 工具，连主题魔改和选题灵感都能被加速。</li></ul><div class="notion-text notion-block-346d690ad6d18058b746dada70cfd5cb">但是工具再顺手，也只是放大器。真正决定这个博客能走多远的，是你愿不愿意<b>持续地写下去</b>。NotionNext 帮你把路铺平了，剩下的那一步，只能靠你自己了。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-346d690ad6d180f2b602c33ce0c5330a" data-id="346d690ad6d180f2b602c33ce0c5330a"><span><div id="346d690ad6d180f2b602c33ce0c5330a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#346d690ad6d180f2b602c33ce0c5330a" title="📎 参考链接"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📎 参考链接</span></span></h2><ul class="notion-list notion-list-disc notion-block-346d690ad6d18055b434f6995b298f32"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://docs.tangly1024.com/about">NotionNext 官方文档</a></li></ul><ul class="notion-list notion-list-disc notion-block-346d690ad6d180bfbdb7d0c8c3f9f493"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/tangly1024/NotionNext">NotionNext GitHub 仓库</a></li></ul><ul class="notion-list notion-list-disc notion-block-346d690ad6d180098250c05b849ed97c"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://docs.tangly1024.com/article/vercel-domain">Vercel 绑定自定义域名教程</a></li></ul><div class="notion-blank notion-block-346d690ad6d180ddbef1f42710edf350"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[一文讲透 mem0：结合官方文档与核心源码]]></title>
            <link>https://www.junlin-233.top/article/mem0-analysis</link>
            <guid>https://www.junlin-233.top/article/mem0-analysis</guid>
            <pubDate>Thu, 16 Apr 2026 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-344d690ad6d1806f88b8f4ade658d6bf"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-344d690ad6d1806585fefdeafd25e478">在agent领域，特别是针对agent的应用，memory是不可或缺的一环，有些时候memory带给用户的体验甚至大于llm本身，下面就让我们来了解一下mem0这个项目：</div><hr class="notion-hr notion-block-410ce5c1b6f141c086c13a39d32338f7"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-417bfb39b282439cb63fcab66d8c19b4" data-id="417bfb39b282439cb63fcab66d8c19b4"><span><div id="417bfb39b282439cb63fcab66d8c19b4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#417bfb39b282439cb63fcab66d8c19b4" title="1. 整体架构"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 整体架构</span></span></h2><div class="notion-text notion-block-344d690ad6d180c68484d9ddb0fc633b">分析mem0的源码，可以得出以下架构：</div><div class="notion-text notion-block-d75251bef09e4beb9c59c60d49b11df1">这个分层最重要的理解是：</div><ul class="notion-list notion-list-disc notion-block-e574689473c44330b06a1d223da725ff"><li><code class="notion-inline-code">configs/</code> 负责说明“怎么配”</li></ul><ul class="notion-list notion-list-disc notion-block-31bc663510b140dab7a18a04d527dca3"><li><code class="notion-inline-code">utils/factory.py</code> 负责“按配置造对象”</li></ul><ul class="notion-list notion-list-disc notion-block-d2845797580a4390a96c4bdc8c286f61"><li><code class="notion-inline-code">memory/main.py</code> 负责“把对象串成 add/search 的业务流水线”</li></ul><ul class="notion-list notion-list-disc notion-block-687b80ddaf214518a7e24a1385227b9a"><li><code class="notion-inline-code">llms/embeddings/vector_stores/reranker</code> 只是被插拔的能力模块</li></ul><hr class="notion-hr notion-block-e562d8f88b7d49888c2c3d94510abead"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-40a60c4752c44ee587071922afb08a52" data-id="40a60c4752c44ee587071922afb08a52"><span><div id="40a60c4752c44ee587071922afb08a52" class="notion-header-anchor"></div><a class="notion-hash-link" href="#40a60c4752c44ee587071922afb08a52" title="2. 顶层目录怎么理解"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 顶层目录怎么理解</span></span></h2><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-345d690ad6d180fcadbbd1849c39746c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:288px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Af49930c4-cf6c-4264-95d3-5186ee97333e%3Aimage.png?table=block&amp;id=345d690a-d6d1-80fc-adbb-d1849c39746c&amp;t=345d690a-d6d1-80fc-adbb-d1849c39746c" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-c1b43520aa304a1f82f26b5e849d86fe" data-id="c1b43520aa304a1f82f26b5e849d86fe"><span><div id="c1b43520aa304a1f82f26b5e849d86fe" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c1b43520aa304a1f82f26b5e849d86fe" title="2.1 embeddings/"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.1 <code class="notion-inline-code">embeddings/</code></span></span></h3><div class="notion-text notion-block-ef90dc5323cd4829a96763227c36ca13">本质上就是把不同厂商的 embedding 能力统一成一套标准接口。</div><div class="notion-text notion-block-95e0fd78921f4bdebaeb6c72ee1423c9">你可以把它理解成一个“统一插座”——上层不关心底层是 OpenAI、Gemini、HuggingFace 还是 Ollama，只关心有没有 <code class="notion-inline-code">embed()</code>。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-d620a060ab32441fb3aae1ef6a4c79f6" data-id="d620a060ab32441fb3aae1ef6a4c79f6"><span><div id="d620a060ab32441fb3aae1ef6a4c79f6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d620a060ab32441fb3aae1ef6a4c79f6" title="2.2 llms/"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.2 <code class="notion-inline-code">llms/</code></span></span></h3><div class="notion-text notion-block-3db4094461c04a95a56977a3b4a6fcde">和 <code class="notion-inline-code">embeddings/</code> 是同样的思路，只不过负责的是模型推理。</div><div class="notion-text notion-block-5fe6f954c68f412e9ba667c32324c7e0">在 mem0 里，LLM 不是可有可无的装饰，它直接参与：</div><ul class="notion-list notion-list-disc notion-block-283a725f6f194b73b8c06ff5803edc02"><li>fact extraction</li></ul><ul class="notion-list notion-list-disc notion-block-427ba6b5cb9444a09b355997c24da01d"><li>memory update decision</li></ul><ul class="notion-list notion-list-disc notion-block-72a7aa6bff334c89a07c9ed959930647"><li>graph relation extraction</li></ul><div class="notion-text notion-block-4394aff1af734b2d984d4d500da44c07">所以 <code class="notion-inline-code">llms/</code> 的地位其实很高。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-f60e1802bc1f40a3bdcc56c1502ad965" data-id="f60e1802bc1f40a3bdcc56c1502ad965"><span><div id="f60e1802bc1f40a3bdcc56c1502ad965" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f60e1802bc1f40a3bdcc56c1502ad965" title="2.3 vector_stores/"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.3 <code class="notion-inline-code">vector_stores/</code></span></span></h3><div class="notion-text notion-block-d70897a0c7aa4dd7b667b82262b298bf">负责统一不同向量库的 CRUD 与 search 接口。对上层来说，Qdrant、PgVector、Chroma、Pinecone 的区别应该被尽量屏蔽。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-a740300f797c4c7fb1c8dc139cba3ec7" data-id="a740300f797c4c7fb1c8dc139cba3ec7"><span><div id="a740300f797c4c7fb1c8dc139cba3ec7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a740300f797c4c7fb1c8dc139cba3ec7" title="2.4 reranker/"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.4 <code class="notion-inline-code">reranker/</code></span></span></h3><div class="notion-text notion-block-db92b475aa794dc2a3ba5387207d7791">只负责检索后的精排，不负责写入。</div><div class="notion-text notion-block-345d690ad6d180ecb145e63a26210a7a">rerank 主要不在 <code class="notion-inline-code">add()</code> 里，而在正式 <code class="notion-inline-code">search()</code> 里。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-c75f71a1eaa445d7a7056125cf06e8b8" data-id="c75f71a1eaa445d7a7056125cf06e8b8"><span><div id="c75f71a1eaa445d7a7056125cf06e8b8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c75f71a1eaa445d7a7056125cf06e8b8" title="2.5 utils/"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.5 <code class="notion-inline-code">utils/</code></span></span></h3><div class="notion-text notion-block-d55a0b407e6446bc870d16f42c680d5c">这个目录最容易被低估。</div><div class="notion-text notion-block-55f2b9d101894d859befd898ce95eee0">它其实有两类职责：</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-d8d66fe3ea784b158b41b04498f6f788" data-id="d8d66fe3ea784b158b41b04498f6f788"><span><div id="d8d66fe3ea784b158b41b04498f6f788" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d8d66fe3ea784b158b41b04498f6f788" title="第一类：装配工"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第一类：装配工</span></span></h4><div class="notion-text notion-block-8ae61bd83b534f7bba6d3c90c521266c">最关键的是 <code class="notion-inline-code">factory.py</code>。它根据配置创建：</div><ul class="notion-list notion-list-disc notion-block-55a677f826b44d62b0a07f723b2dc8c9"><li>LLM</li></ul><ul class="notion-list notion-list-disc notion-block-cc5481c7dcfb43b8afaee48715c53ded"><li>embedder</li></ul><ul class="notion-list notion-list-disc notion-block-3ae80d335c444a83b24248cafbeee51c"><li>vector store</li></ul><ul class="notion-list notion-list-disc notion-block-8c7127f7fd4648e1a6c8ba8a8a77bd2e"><li>reranker</li></ul><div class="notion-text notion-block-ac8dd0b3e1c74ae49e518384895840cd">如果 <code class="notion-inline-code">configs/</code> 是说明书，那 <code class="notion-inline-code">factory.py</code> 就是总装车间。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-70542c70eaa548249d43a9e361cb58ab" data-id="70542c70eaa548249d43a9e361cb58ab"><span><div id="70542c70eaa548249d43a9e361cb58ab" class="notion-header-anchor"></div><a class="notion-hash-link" href="#70542c70eaa548249d43a9e361cb58ab" title="第二类：算法和共享工具"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第二类：算法和共享工具</span></span></h4><div class="notion-text notion-block-28a7b26818af43f2a990a5b26fef707b">比如：</div><ul class="notion-list notion-list-disc notion-block-2c756168679a4a5e8939d2f561d06a5a"><li><code class="notion-inline-code">entity_extraction.py</code></li></ul><ul class="notion-list notion-list-disc notion-block-a53afe058cce4164aa708c5aa7b59a28"><li><code class="notion-inline-code">lemmatization.py</code></li></ul><ul class="notion-list notion-list-disc notion-block-beb50b4d5cfe44888a7706f8a8bac3ea"><li><code class="notion-inline-code">scoring.py</code></li></ul><ul class="notion-list notion-list-disc notion-block-de1dc205837948f5aae176cd23979531"><li><code class="notion-inline-code">spacy_models.py</code></li></ul><div class="notion-text notion-block-e88740a195fb42c0b6aea1701aa29931">这些东西不属于某一个 provider，但会被主链路反复调用。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-a50026cf834245239c5d2fe7b150b73e" data-id="a50026cf834245239c5d2fe7b150b73e"><span><div id="a50026cf834245239c5d2fe7b150b73e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a50026cf834245239c5d2fe7b150b73e" title="2.6 client/"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2.6 <code class="notion-inline-code">client/</code></span></span></h3><div class="notion-text notion-block-438e0587aa5948c09e7f5ed69ff8d934">它不是 memory engine 本体，而是平台 API 的 SDK。</div><ul class="notion-list notion-list-disc notion-block-66147699241c48b5a27cf942f2a76a78"><li><code class="notion-inline-code">Memory</code>：本地发动机</li></ul><ul class="notion-list notion-list-disc notion-block-5e5722ddfe944eac974d9a577b5a5aba"><li><code class="notion-inline-code">MemoryClient</code>：远程遥控器</li></ul><hr class="notion-hr notion-block-54d7bb0cb3dc4e1a84937669a29a9f69"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-afc3f5e931fd4aeba58a611f06ff5a43" data-id="afc3f5e931fd4aeba58a611f06ff5a43"><span><div id="afc3f5e931fd4aeba58a611f06ff5a43" class="notion-header-anchor"></div><a class="notion-hash-link" href="#afc3f5e931fd4aeba58a611f06ff5a43" title="3. memory/ 目录：真正的精华"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. <code class="notion-inline-code">memory/</code> 目录：真正的精华</span></span></h2><div class="notion-text notion-block-656afbc389f64b5bbc5acc2cd20ef7e5">如果只允许挑一个目录深入分析，那一定是 <code class="notion-inline-code">memory/</code>。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-345d690ad6d1805da737fba1a2318ac1"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:269.9999694824219px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Ab97f2169-c6af-40fa-9636-db3ae51e7b27%3Aimage.png?table=block&amp;id=345d690a-d6d1-805d-a737-fba1a2318ac1&amp;t=345d690a-d6d1-805d-a737-fba1a2318ac1" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-fdee8591203e43519a8ad247062892e7" data-id="fdee8591203e43519a8ad247062892e7"><span><div id="fdee8591203e43519a8ad247062892e7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fdee8591203e43519a8ad247062892e7" title="3.1 文件职责"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3.1 文件职责</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-692a9c3e5be44bab9586d167ce290a7b" data-id="692a9c3e5be44bab9586d167ce290a7b"><span><div id="692a9c3e5be44bab9586d167ce290a7b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#692a9c3e5be44bab9586d167ce290a7b" title="main.py"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><code class="notion-inline-code">main.py</code></span></span></h4><div class="notion-text notion-block-3d9c7771e5424c4595e34da7dc0a8ced">核心 orchestrator（协调者）</div><div class="notion-text notion-block-17f3efbb0d7249cabe5a803f03e68701">负责：</div><ul class="notion-list notion-list-disc notion-block-05ca529cf00a45dda0a22edb042c3720"><li>初始化 LLM / embedding / vector store / SQLite / reranker / graph</li></ul><ul class="notion-list notion-list-disc notion-block-dc537fc428d248cc9a76d95756139421"><li>对外暴露 <code class="notion-inline-code">add / search / get / update / delete / history / reset</code></li></ul><ul class="notion-list notion-list-disc notion-block-6b2e0571b7744c2c98c5d3b495c6eac2"><li>串联 vector memory 和 graph memory 两条链</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-29c20c567b634d8ebdd6152d6f0aab94" data-id="29c20c567b634d8ebdd6152d6f0aab94"><span><div id="29c20c567b634d8ebdd6152d6f0aab94" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29c20c567b634d8ebdd6152d6f0aab94" title="storage.py"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><code class="notion-inline-code">storage.py</code></span></span></h4><div class="notion-text notion-block-959f0471d62f4d36853dca4ec49115d0">SQLite 本地状态层。</div><div class="notion-text notion-block-3a053566427a47029f74056e520f911a">负责两张表：</div><ul class="notion-list notion-list-disc notion-block-db4877bcb60c457a82abd959c60d8bd7"><li><code class="notion-inline-code">history</code>：memory 的增删改轨迹</li></ul><ul class="notion-list notion-list-disc notion-block-e887ea6b56594d0ca1777939e683aeaf"><li><code class="notion-inline-code">messages</code>：某个 scope 最近的消息缓存</li></ul><div class="notion-text notion-block-e08bd1104cd2486e992b3f2824498c4b">这意味着 mem0 不是只有长期记忆，还显式维护了短期上下文和审计轨迹。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-94d46d80d6e84d769cde027fcaf0a36b" data-id="94d46d80d6e84d769cde027fcaf0a36b"><span><div id="94d46d80d6e84d769cde027fcaf0a36b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#94d46d80d6e84d769cde027fcaf0a36b" title="base.py"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><code class="notion-inline-code">base.py</code></span></span></h4><div class="notion-text notion-block-e8d428e9e3d64dd3a74d049f6fb8f9d8">抽象接口层。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-881227f1ecb74e4dac28f44118f381c2" data-id="881227f1ecb74e4dac28f44118f381c2"><span><div id="881227f1ecb74e4dac28f44118f381c2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#881227f1ecb74e4dac28f44118f381c2" title="utils.py"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><code class="notion-inline-code">utils.py</code></span></span></h4><div class="notion-text notion-block-bfdb1c3369474ab4954dc9e319054480">注意这是 <code class="notion-inline-code">memory/</code> 内部的 utils，不是顶层 <code class="notion-inline-code">utils/</code>。</div><div class="notion-text notion-block-134b3450c7d9489196f1bc19729fe2fa">主要负责：</div><ul class="notion-list notion-list-disc notion-block-a736a1fd1b1949d992588b7a01f583bb"><li>prompt 组装</li></ul><ul class="notion-list notion-list-disc notion-block-110e6bb7989a4c958aa825dbec98b41c"><li>message 解析</li></ul><ul class="notion-list notion-list-disc notion-block-20c0cfa252cc4cf7911e8fdd1e6ef3c8"><li>JSON 清洗</li></ul><ul class="notion-list notion-list-disc notion-block-17c11f3ea7c94fda9257b712a84500c1"><li>fact normalization</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-8afea29553ab44c5ac770b0a5f4d35d7" data-id="8afea29553ab44c5ac770b0a5f4d35d7"><span><div id="8afea29553ab44c5ac770b0a5f4d35d7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8afea29553ab44c5ac770b0a5f4d35d7" title="telemetry.py"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><code class="notion-inline-code">telemetry.py</code></span></span></h4><div class="notion-text notion-block-c4078b06e3354b198705650778c6d049">埋点。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-ab2107677cf54fa1879709897aba009c" data-id="ab2107677cf54fa1879709897aba009c"><span><div id="ab2107677cf54fa1879709897aba009c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ab2107677cf54fa1879709897aba009c" title="setup.py"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><code class="notion-inline-code">setup.py</code></span></span></h4><div class="notion-text notion-block-bffe783ae3994849b5f6f5da7fb01728">本地初始化脚手架。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-1ab6f1db833f4cefb4b65e838fe7653c" data-id="1ab6f1db833f4cefb4b65e838fe7653c"><span><div id="1ab6f1db833f4cefb4b65e838fe7653c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1ab6f1db833f4cefb4b65e838fe7653c" title="graph_memory.py / kuzu_memory.py / memgraph_memory.py / apache_age_memory.py"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><code class="notion-inline-code">graph_memory.py / kuzu_memory.py / memgraph_memory.py / apache_age_memory.py</code></span></span></h4><div class="notion-text notion-block-cf54be8d39fc4f27812e9953fa14aeac">不同图后端的实现。</div><hr class="notion-hr notion-block-5b9212b0e73b4c5097ddab4eeec59cb3"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-66691f9b57784ec3b154910707c49744" data-id="66691f9b57784ec3b154910707c49744"><span><div id="66691f9b57784ec3b154910707c49744" class="notion-header-anchor"></div><a class="notion-hash-link" href="#66691f9b57784ec3b154910707c49744" title="4. Memory ：整个系统的大脑"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. <code class="notion-inline-code">Memory</code> ：整个系统的大脑</span></span></h2><div class="notion-text notion-block-e25b08dbba424bc8bc46b82d0bf2a903">最值得看的是 <code class="notion-inline-code">memory/main.py</code> 里的 <code class="notion-inline-code">Memory</code>。</div><div class="notion-text notion-block-0724aca786694f30a0dcffcf03109eb2">原因很简单：它不是一个数据类，而是一个 runtime orchestrator。</div><div class="notion-text notion-block-ec450906061c4a2381943ea6a7f2e541">初始化的时候，它会把：</div><ul class="notion-list notion-list-disc notion-block-d4060ed8154b42d3aae8d6ca7b85d72a"><li>embedding model</li></ul><ul class="notion-list notion-list-disc notion-block-52461ad9f70f4ab0a9d9eb2f1b424d25"><li>vector store</li></ul><ul class="notion-list notion-list-disc notion-block-69f0e466d2cb4e02b44d4b4fc241a4e4"><li>llm</li></ul><ul class="notion-list notion-list-disc notion-block-54c7e0007556472790c0a9a926010add"><li>SQLiteManager</li></ul><ul class="notion-list notion-list-disc notion-block-b72f97f08c0747dba99115b33df1b34c"><li>可选 reranker</li></ul><ul class="notion-list notion-list-disc notion-block-78f855f1320f4003ba9e57a7555699c3"><li>可选 graph store</li></ul><div class="notion-text notion-block-f853a4dc29e0426baa2ad470bb5b441e">都装进同一个对象里。</div><div class="notion-text notion-block-175e2d1f029946d38355539dce368a7b">这意味着 mem0 的 memory 不是某一张表，也不是某一个集合，而是一条由多个组件共同驱动的流水线。</div><hr class="notion-hr notion-block-d0783d5a64f34066a43c3f6389d39a3f"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-b42a7861b01f4762ab7125fd83346012" data-id="b42a7861b01f4762ab7125fd83346012"><span><div id="b42a7861b01f4762ab7125fd83346012" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b42a7861b01f4762ab7125fd83346012" title="5. 关键源码：_add_to_vector_store()"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5. 关键源码：<code class="notion-inline-code">_add_to_vector_store()</code></span></span></h2><div class="notion-text notion-block-d00a839a100e43bcb32975ee2593e63c"><code class="notion-inline-code">_add_to_vector_store()</code>，基本就是 mem0 的灵魂所在。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-541be6817bd6484fa81f8f973231d0f0" data-id="541be6817bd6484fa81f8f973231d0f0"><span><div id="541be6817bd6484fa81f8f973231d0f0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#541be6817bd6484fa81f8f973231d0f0" title="5.1 总流程图"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5.1 总流程图</span></span></h3><hr class="notion-hr notion-block-c248a895d8ad4880825bb22aa0f18e1d"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-551a96f5e7664827a403e94cbf1efed1" data-id="551a96f5e7664827a403e94cbf1efed1"><span><div id="551a96f5e7664827a403e94cbf1efed1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#551a96f5e7664827a403e94cbf1efed1" title="6. 第一条分支：infer=False 是“原样写入模式”"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6. 第一条分支：<code class="notion-inline-code">infer=False</code> 是“原样写入模式”</span></span></h2><div class="notion-text notion-block-984a87f223304054aaae42d0ebbd7c91">我们先看源码第一段：</div><div class="notion-text notion-block-9c75e4385967438699afbd4d141f4fe3">这一段非常直白：</div><ul class="notion-list notion-list-disc notion-block-0521553bbcc14a7089210c06aa7443dc"><li>消息必须是合法 dict</li></ul><ul class="notion-list notion-list-disc notion-block-83ad95bd0bae4ae1aca51c9f1cd87689"><li>跳过 <code class="notion-inline-code">system</code> 消息</li></ul><ul class="notion-list notion-list-disc notion-block-6d3adec62cb249c89eace14b4281ba28"><li>把 <code class="notion-inline-code">role</code>、<code class="notion-inline-code">actor_id</code> 写进 metadata</li></ul><ul class="notion-list notion-list-disc notion-block-3a485ede300c4fd3bc5e6334083f5e11"><li>对原始 <code class="notion-inline-code">content</code> 做 embedding</li></ul><ul class="notion-list notion-list-disc notion-block-71a1929274d4449cb1bb79bbcff71478"><li>然后直接 <code class="notion-inline-code">_create_memory()</code></li></ul><div class="notion-text notion-block-7a718f4ea69441ab96d874b4fe67cfbb">它的本质是：</div><blockquote class="notion-quote notion-block-d9e77af61736409484bb49d5e2ad79df"><div><b>不做理解，只做存储。</b></div></blockquote><div class="notion-text notion-block-8bcf877f023843919a68c7b0df9148bc">适合这几类场景：</div><ul class="notion-list notion-list-disc notion-block-ee84c457ccff4f9fbb056e7cb54d7a8b"><li>审计日志</li></ul><ul class="notion-list notion-list-disc notion-block-09be0c7878e74481b6a2e4819447655b"><li>原始转录保存</li></ul><ul class="notion-list notion-list-disc notion-block-8393b71d8bd942f683e5aaf389c7cd8e"><li>法务/医疗等不希望被 LLM 改写的高风险文本</li></ul><div class="notion-text notion-block-2bc900a80b23463aa20d05044c787315">缺点也很明显：</div><ul class="notion-list notion-list-disc notion-block-37c9646d34854e338946e7869489df22"><li>冗余高</li></ul><ul class="notion-list notion-list-disc notion-block-6a613596109646669c5c405f2544d130"><li>容易重复</li></ul><ul class="notion-list notion-list-disc notion-block-784e3ed661b2421aa145c410a01ce318"><li>不会自动处理冲突</li></ul><div class="notion-text notion-block-0d2e79f7b4c5431597a672295aa7b9c9">所以 <code class="notion-inline-code">infer=False</code> 更像 <b>raw ingest</b>。</div><hr class="notion-hr notion-block-f9018110b0f4419198c6dc55794845ad"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-52284617d502465f8fb143a988740ef6" data-id="52284617d502465f8fb143a988740ef6"><span><div id="52284617d502465f8fb143a988740ef6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#52284617d502465f8fb143a988740ef6" title="7. 第二条分支：infer=True 才是 mem0 的真正价值"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7. 第二条分支：<code class="notion-inline-code">infer=True</code> 才是 mem0 的真正价值</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-b9dd7b9a0212431fbbbe668f5bcbfae6" data-id="b9dd7b9a0212431fbbbe668f5bcbfae6"><span><div id="b9dd7b9a0212431fbbbe668f5bcbfae6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b9dd7b9a0212431fbbbe668f5bcbfae6" title="7.1 第一阶段：先从消息里抽 facts"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.1 第一阶段：先从消息里抽 facts</span></span></h3><div class="notion-text notion-block-109e873e54af424faa3d2e71c823f066">源码这一段是：</div><div class="notion-text notion-block-6ffe41333cc64fa2bd3c41c8a9266c2a">这段代码有三个关键点。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-fad0ce4f957944ae8b7a01fee2627872" data-id="fad0ce4f957944ae8b7a01fee2627872"><span><div id="fad0ce4f957944ae8b7a01fee2627872" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fad0ce4f957944ae8b7a01fee2627872" title="关键点 1：custom_instructions ：抽取规则覆盖层"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">关键点 1：<code class="notion-inline-code">custom_instructions</code> ：抽取规则覆盖层</span></span></h4><div class="notion-text notion-block-526427a968234a6ab12a1caa7458ef2b">一旦配置了 <code class="notion-inline-code">custom_instructions</code>，默认的 <code class="notion-inline-code">get_fact_retrieval_messages(...)</code> 就不会再走。</div><div class="notion-text notion-block-932ab90ece9b46858f0adce3d9e70ffc">也就是说：</div><blockquote class="notion-quote notion-block-288a42d05d534efc81df172e7a37def3"><div><code class="notion-inline-code">custom_instructions</code> 本质上是在定义“哪些内容值得被记住”。</div></blockquote><div class="notion-text notion-block-4699e0cec58d4249a4d9445ac08069d4">这正是业务定制最重要的抓手。</div><div class="notion-text notion-block-56e85ff204f04714bc4a39e23b51ef24">例如：</div><ul class="notion-list notion-list-disc notion-block-e972408b5c27419692f1c70eb2e0508a"><li>客服：只抽订单、地址、售后诉求</li></ul><ul class="notion-list notion-list-disc notion-block-7aa31259caa249818030257c3acac501"><li>IDE Agent：只抽 repo 约定、工具偏好、失败经验</li></ul><ul class="notion-list notion-list-disc notion-block-31c364780b704af7a1c21d35d9d857e2"><li>医疗：只抽过敏史、既往病史、诊疗偏好</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-8bd89300b74e4f8d9588d634316cf8e0" data-id="8bd89300b74e4f8d9588d634316cf8e0"><span><div id="8bd89300b74e4f8d9588d634316cf8e0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8bd89300b74e4f8d9588d634316cf8e0" title="关键点 2：agent memory 和 user memory 的分流发生在“抽取阶段”"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">关键点 2：agent memory 和 user memory 的分流发生在“抽取阶段”</span></span></h4><div class="notion-text notion-block-6bc808fd89e64f5da6e0a7a48f89199f">如果没有 <code class="notion-inline-code">custom_instructions</code>，源码会先判断：</div><div class="notion-text notion-block-19df073e723c414bac046ecd21faa43d">这意味着 agent memory 与 user memory 的区别，首先不是底层存储，而是：</div><ul class="notion-list notion-list-disc notion-block-5316af089bd54b10a0ba8f2a65f9b482"><li>抽取 prompt 不同</li></ul><ul class="notion-list notion-list-disc notion-block-083a9692bafd43349a598634b5e1646f"><li>抽取视角不同</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-ed415592a6874a5da157dd1e876ea985" data-id="ed415592a6874a5da157dd1e876ea985"><span><div id="ed415592a6874a5da157dd1e876ea985" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ed415592a6874a5da157dd1e876ea985" title="关键点 3：这里是第一轮 LLM，不是最终写入决策"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">关键点 3：这里是第一轮 LLM，不是最终写入决策</span></span></h4><div class="notion-text notion-block-ce59603f73794c3fb95b491c66b80032">这次 <code class="notion-inline-code">generate_response()</code> 的目标只有一个：</div><blockquote class="notion-quote notion-block-ea53fa78ac9442a5891fcd3ccbe2b02e"><div><b>从当前对话里抽取 facts</b></div></blockquote><div class="notion-text notion-block-fca1f0949ff940b8a1c4322871d5c665">不是直接返回增删改动作。</div><hr class="notion-hr notion-block-5f2c07f2b1f647a19bffcc74a78b46ff"/><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-3b4b3a0b0a7c44d497a9f8bad928d3b5" data-id="3b4b3a0b0a7c44d497a9f8bad928d3b5"><span><div id="3b4b3a0b0a7c44d497a9f8bad928d3b5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3b4b3a0b0a7c44d497a9f8bad928d3b5" title="7.2 清洗 LLM 输出：这一步体现了很强的工程意识"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.2 清洗 LLM 输出：这一步体现了很强的工程意识</span></span></h3><div class="notion-text notion-block-e9ed8a1c5edb4cfda0fbb04f3a9eae75">接下来是解析响应：</div><div class="notion-text notion-block-701dee73ab73453f9f75db94c203656a">这里可以看出 mem0 处理 LLM 输出的三个策略：</div><ol start="1" class="notion-list notion-list-numbered notion-block-d9325b33421d4c65be3d10b19ca1f9da" style="list-style-type:decimal"><li>先去掉代码块</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-c928d9c1b02d4e4e901239b87c35cfa2" style="list-style-type:decimal"><li>先尝试直接解析 JSON</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-b0a285d76b154dba97c032a6d749004f" style="list-style-type:decimal"><li>失败后再做 JSON 提取</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-b4f32ee49470422aacf45a029c97e6d8" style="list-style-type:decimal"><li>最后统一做 facts 归一化</li></ol><div class="notion-text notion-block-a0d11f0b6be340408313d31615f57619">这说明作者非常清楚：</div><blockquote class="notion-quote notion-block-5f55d3c37faa468b91b2d309a16df124"><div>LLM 即使被要求输出 JSON，也并不总是干净可靠。</div></blockquote><div class="notion-text notion-block-0dbb19b377684a6799aa2b3c20b5b84f">所以这段代码不是“锦上添花”，而是 LLM 系统工程里非常必要的一层容错。</div><hr class="notion-hr notion-block-b7185ddc30f244de8a34a4244b05f965"/><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-313881b5d60e487e89696f313811c46c" data-id="313881b5d60e487e89696f313811c46c"><span><div id="313881b5d60e487e89696f313811c46c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#313881b5d60e487e89696f313811c46c" title="7.3 如果没抽出 facts，后面还会继续吗？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7.3 如果没抽出 facts，后面还会继续吗？</span></span></h3><div class="notion-text notion-block-8e887c5f87ca43cf910692daf99d2d2d">源码这里有一句很关键：</div><div class="notion-text notion-block-6547c4e0ee68427d87c7751e5f7c4435">这句话意味着：</div><ul class="notion-list notion-list-disc notion-block-87a1cfcbd7474426aca2bc4bbec8f145"><li>整个函数不会报错退出</li></ul><ul class="notion-list notion-list-disc notion-block-b1c67c666c844fe6b28ddafe6f813439"><li>但第二轮 memory update LLM 会被跳过</li></ul><ul class="notion-list notion-list-disc notion-block-21e602cefd794204a15d27aa0efc9a88"><li>最终大概率不会产生新的 memory action</li></ul><div class="notion-text notion-block-50cea0ce55d747898715698ee4c45323">所以更准确地说：</div><blockquote class="notion-quote notion-block-d3599c06591b4af7b77f440c6c4ed996"><div>如果 <code class="notion-inline-code">custom_instructions</code> 或默认抽取规则判断“这段内容没有值得记住的 facts”，那后续的 memory lifecycle 决策基本不会发生。</div></blockquote><div class="notion-text notion-block-d07783a56413444bbddcebddb67db60a">这正是 mem0 的实用价值之一：</div><div class="notion-text notion-block-d0ea0433d90049e0a4b8f1750671610c"><b>把“不相关内容”挡在长期记忆之外。</b></div><hr class="notion-hr notion-block-d5f8ef29a15a46499d1f0318804fb90f"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-653caa222c934e6e8505e913703b23f4" data-id="653caa222c934e6e8505e913703b23f4"><span><div id="653caa222c934e6e8505e913703b23f4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#653caa222c934e6e8505e913703b23f4" title="8. 最关键的一步：不是抽完就存，而是先搜旧 memory"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">8. 最关键的一步：不是抽完就存，而是先搜旧 memory</span></span></h2><div class="notion-text notion-block-3f6129ecbeac49029fd7338d1913f559">这部分是 mem0 和“普通向量库存文本”的根本分界线。</div><div class="notion-text notion-block-04231b28ad224fcabfc6454460c9270f">源码如下：</div><div class="notion-text notion-block-db494461eaac4e46a4a50cdf29735892">这段代码说明了三件事。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-85b5b605d8cb40d59c8bcfe366082b52" data-id="85b5b605d8cb40d59c8bcfe366082b52"><span><div id="85b5b605d8cb40d59c8bcfe366082b52" class="notion-header-anchor"></div><a class="notion-hash-link" href="#85b5b605d8cb40d59c8bcfe366082b52" title="8.1 memory write 不是 append-only，而是 retrieval-assisted"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">8.1 memory write 不是 append-only，而是 retrieval-assisted</span></span></h3><div class="notion-text notion-block-2db3f7b2dfc94a2d9a124c44594cc8a8">新的 fact 不是抽出来就写，而是先去搜旧 memories。</div><div class="notion-text notion-block-ef4aea51da7f47f6ac8c4f64147e0a81">这个设计特别重要，因为现实里的长期记忆一定会遇到：</div><ul class="notion-list notion-list-disc notion-block-6b25ffe7513b4f39af9860a908cccf75"><li>偏好变化</li></ul><ul class="notion-list notion-list-disc notion-block-e52f31bf15a84921b9770b7423234481"><li>地址更新</li></ul><ul class="notion-list notion-list-disc notion-block-162c741ef8104861a8bafa1402486e51"><li>以前的说法被推翻</li></ul><ul class="notion-list notion-list-disc notion-block-b293f39307714a848f1ca2d045a000b3"><li>同一事实被不同表达重复提到</li></ul><div class="notion-text notion-block-193ddd5fde8b438c8fa20d610349f010">所以 mem0 的设计思路是：</div><blockquote class="notion-quote notion-block-28756524ab9f4983b185e93d3ce609c3"><div><b>先检索旧记忆，再决定这条新信息到底是新增、覆盖、删除还是忽略。</b></div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-370e47cc619f4173b7e4f1a4e4439d70" data-id="370e47cc619f4173b7e4f1a4e4439d70"><span><div id="370e47cc619f4173b7e4f1a4e4439d70" class="notion-header-anchor"></div><a class="notion-hash-link" href="#370e47cc619f4173b7e4f1a4e4439d70" title="8.2 作用域控制靠 user_id / agent_id / run_id"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">8.2 作用域控制靠 <code class="notion-inline-code">user_id / agent_id / run_id</code></span></span></h3><div class="notion-text notion-block-b1ab6e1b58db47a98c17662018274fc9">这里的 <code class="notion-inline-code">search_filters</code> 明确把：</div><ul class="notion-list notion-list-disc notion-block-f1a54df169ef45af9bf6d92112f5202b"><li><code class="notion-inline-code">user_id</code></li></ul><ul class="notion-list notion-list-disc notion-block-f2d35c6a2839461c852d247897d60406"><li><code class="notion-inline-code">agent_id</code></li></ul><ul class="notion-list notion-list-disc notion-block-14775b3b0f1f4465999bcdf4b2e0a22f"><li><code class="notion-inline-code">run_id</code></li></ul><div class="notion-text notion-block-4073904a7ba744d292afe5119330f081">都作为检索范围条件。</div><div class="notion-text notion-block-8bc7bddf80624cbab870514a0af854fa">这说明 mem0 不是两套独立的 user memory / agent memory 系统，而是：</div><blockquote class="notion-quote notion-block-25d05b23b4bc44f3b785b589a92a20b6"><div>同一个 memory engine，用 metadata 和 filters 做多维 scope 管理。</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-13195d89b88d43f3901906639af7f8be" data-id="13195d89b88d43f3901906639af7f8be"><span><div id="13195d89b88d43f3901906639af7f8be" class="notion-header-anchor"></div><a class="notion-hash-link" href="#13195d89b88d43f3901906639af7f8be" title="8.3 user memory 和 agent memory"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">8.3 user memory 和 agent memory</span></span></h3><div class="notion-text notion-block-bd2ea590947b4909bc80408ebd5bbe26">底层存储几乎一样：</div><ul class="notion-list notion-list-disc notion-block-c6f3693abf964a47b7aa5bd5c9d264ce"><li>同一个 vector store</li></ul><ul class="notion-list notion-list-disc notion-block-ebed135357094365ae206e9ab1d70d15"><li>同一个 SQLite history/messages</li></ul><ul class="notion-list notion-list-disc notion-block-72be8729984a4b47aaa0587bfabe615b"><li>同一套 create/update/delete 逻辑</li></ul><div class="notion-text notion-block-81b659c5eaf24e5fae039501afee351d">真正的区别主要体现在：</div><ul class="notion-list notion-list-disc notion-block-6e242d14b96540cc9c488dfe641e5b9d"><li>写入时 metadata 不同</li></ul><ul class="notion-list notion-list-disc notion-block-f20e64db035144c280ec2cd9d07b1d47"><li>检索时 filters 不同</li></ul><ul class="notion-list notion-list-disc notion-block-1ec1b1e071bb43a78ea603a1459d6c34"><li>抽取时 prompt 视角不同</li></ul><div class="notion-text notion-block-4fef56c6d84d4edeb6e37da55c286954">一句话概括：</div><blockquote class="notion-quote notion-block-651f3cff8f6643b8b0d5bf7c62def87d"><div>user memory 是“记住这个人”，agent memory 是“记住这个 agent”，run memory 是“记住这次任务”。</div></blockquote><hr class="notion-hr notion-block-be9c770b41524808bcbf325ddb2b0c96"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-840fd59e1b584620a4f7d78962a7fdcd" data-id="840fd59e1b584620a4f7d78962a7fdcd"><span><div id="840fd59e1b584620a4f7d78962a7fdcd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#840fd59e1b584620a4f7d78962a7fdcd" title="9. 一个特别好的工程细节：为什么要把 UUID 映射成整数"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">9. 一个特别好的工程细节：为什么要把 UUID 映射成整数</span></span></h2><div class="notion-text notion-block-e97b4ffc7f6646bba75efa0b99409c68">源码这一段我非常喜欢：</div><div class="notion-text notion-block-954284055bd9456695a87979fe60380f">作者在注释里已经把原因写出来了：</div><blockquote class="notion-quote notion-block-a5ab697cfb7f4262830b33f685f05313"><div>为了处理 UUID hallucination。</div></blockquote><div class="notion-text notion-block-fb5d178f2b734416bbebbfbdf0deb210">意思非常直接：</div><ul class="notion-list notion-list-disc notion-block-6030fb537727452183e51b5e6a553efe"><li>如果把真实 UUID 给 LLM</li></ul><ul class="notion-list notion-list-disc notion-block-d66ed38bd284433dab8b5e4a3b92ea93"><li>LLM 很容易记错、拼错、瞎编</li></ul><ul class="notion-list notion-list-disc notion-block-2efdc318802d4694b0f2f8bd50db3435"><li>所以先给旧 memories 编成 <code class="notion-inline-code">0/1/2/...</code></li></ul><ul class="notion-list notion-list-disc notion-block-42bfe1ecbe444ef5937fe159654599ed"><li>LLM 返回动作时只引用这些短编号</li></ul><ul class="notion-list notion-list-disc notion-block-9d341082a5664ada85294969658bbf37"><li>最后再映射回真实 id</li></ul><div class="notion-text notion-block-927a4ab63ecd4901b0379c8d37427301">这件事虽然小，但特别能体现系统工程意识：</div><blockquote class="notion-quote notion-block-40ef0b9dae7842c4a43b7cd430e45a8d"><div>不要让 LLM 直接处理长而脆弱的主键。</div></blockquote><div class="notion-text notion-block-067dea554a9446f1a8ef87fc9b7e1512">这是很典型的“不是算法多先进，而是工程经验很到位”。</div><hr class="notion-hr notion-block-8f85ba633e3947ed9c57855783b42199"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-f01b493000df42e185ddef12039dc8ab" data-id="f01b493000df42e185ddef12039dc8ab"><span><div id="f01b493000df42e185ddef12039dc8ab" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f01b493000df42e185ddef12039dc8ab" title="10. 第二轮 LLM：真正的 memory lifecycle"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">10. 第二轮 LLM：真正的 memory lifecycle</span></span></h2><div class="notion-text notion-block-f5405de93786443db263a6503343a19a">在拿到：</div><ul class="notion-list notion-list-disc notion-block-f1864d723d534c2f94148f085b4a6b8d"><li>新 facts</li></ul><ul class="notion-list notion-list-disc notion-block-4aa8674a580145e280345c9d6f2ad6cd"><li>旧 memories</li></ul><ul class="notion-list notion-list-disc notion-block-9a96d4f08cfd434b9bac9fea2b175134"><li>可选的 custom update memory prompt</li></ul><div class="notion-text notion-block-9ab9b77ab48442469486dc1edf24a33a">之后，代码会再次调用 LLM：</div><div class="notion-text notion-block-b3b5c0960d384b8798264763dc2d84a9">这一轮和第一轮的区别一定要讲清楚：</div><ul class="notion-list notion-list-disc notion-block-1cb72bbbbfdf45bb894d879778d3d7a8"><li>第一轮：抽 facts</li></ul><ul class="notion-list notion-list-disc notion-block-300f935876fb4b12a105e26b6b84aacb"><li>第二轮：决定动作</li></ul><div class="notion-text notion-block-8fc2807a85c54c869e49104827ecce95">也就是说，mem0 把“理解内容”和“更新状态”拆成了两次 LLM 调用。</div><div class="notion-text notion-block-1da114edf5ac4022a8ae37dbec3cbf67">这是个很聪明的设计，因为：</div><ul class="notion-list notion-list-disc notion-block-bc9ccc8f056b4976b432811fa628f067"><li>先抽事实，更容易控制 recall</li></ul><ul class="notion-list notion-list-disc notion-block-c7148f7766e84640acd4cb6b1b8f9340"><li>再做动作，更容易处理冲突和覆盖</li></ul><ul class="notion-list notion-list-disc notion-block-763e809344eb493380aa08c779695cd8"><li>两步拆开后，prompt 更清晰，可调性也更强</li></ul><hr class="notion-hr notion-block-5c4ef6a9a5134402ab1ee479712e57b0"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-ed1da2a97b3747cdaf96bbe4ccef02a2" data-id="ed1da2a97b3747cdaf96bbe4ccef02a2"><span><div id="ed1da2a97b3747cdaf96bbe4ccef02a2" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ed1da2a97b3747cdaf96bbe4ccef02a2" title="11. ADD / UPDATE / DELETE / NONE 四种动作到底意味着什么"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">11. <code class="notion-inline-code">ADD / UPDATE / DELETE / NONE</code> 四种动作到底意味着什么</span></span></h2><div class="notion-text notion-block-bb13868bc60c41dfa9f65abf243361be">源码里对四种动作分别做了处理。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0f24dbe9989a434a98248fe17e55159d" data-id="0f24dbe9989a434a98248fe17e55159d"><span><div id="0f24dbe9989a434a98248fe17e55159d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0f24dbe9989a434a98248fe17e55159d" title="11.1 ADD"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">11.1 <code class="notion-inline-code">ADD</code></span></span></h3><div class="notion-text notion-block-ce94cd29e35d49c6a03b0d1f590ad77d">含义很简单：</div><blockquote class="notion-quote notion-block-1abf58b27174435aaecc91323127e850"><div>这是一条新的长期记忆，应该新增。</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-3d00c3b7f6204a0a935e4e99d8aa0c35" data-id="3d00c3b7f6204a0a935e4e99d8aa0c35"><span><div id="3d00c3b7f6204a0a935e4e99d8aa0c35" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3d00c3b7f6204a0a935e4e99d8aa0c35" title="11.2 UPDATE"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">11.2 <code class="notion-inline-code">UPDATE</code></span></span></h3><div class="notion-text notion-block-0cbac8c5e28d43eda5ae12dc611330c7">这里不是 delete+add，而是显式 <code class="notion-inline-code">update</code>。</div><div class="notion-text notion-block-7a46cb611f9d4220be4812083c74c8eb">这个设计特别适合：</div><ul class="notion-list notion-list-disc notion-block-035cc03a239249658ae935645636397e"><li>地址变更</li></ul><ul class="notion-list notion-list-disc notion-block-1d403bd181e946abad70d38b6336e4bf"><li>偏好变化</li></ul><ul class="notion-list notion-list-disc notion-block-a61d144967824eafb30c02e7a30324eb"><li>配置覆盖</li></ul><ul class="notion-list notion-list-disc notion-block-a3ac073b4fe744ab9b07ef80e1e6c008"><li>用户画像更新</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-d2e60052f1144de1acb652464b459c7f" data-id="d2e60052f1144de1acb652464b459c7f"><span><div id="d2e60052f1144de1acb652464b459c7f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d2e60052f1144de1acb652464b459c7f" title="11.3 DELETE"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">11.3 <code class="notion-inline-code">DELETE</code></span></span></h3><div class="notion-text notion-block-ca38d1ca1ee342e3bfb508e9410bab06">说明 mem0 接受这样一种事实：</div><blockquote class="notion-quote notion-block-fcb8f86a11e349fdb34553c2fffb206d"><div>新信息可能让旧记忆失效。</div></blockquote><div class="notion-text notion-block-73c58e1bd1004f9d81df8dee3801e536">这也是长期记忆和聊天日志最大的不同之一。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-1b000a77ea6e41d0a5c93b47f415f8af" data-id="1b000a77ea6e41d0a5c93b47f415f8af"><span><div id="1b000a77ea6e41d0a5c93b47f415f8af" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1b000a77ea6e41d0a5c93b47f415f8af" title="11.4 NONE"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">11.4 <code class="notion-inline-code">NONE</code></span></span></h3><div class="notion-text notion-block-0c41afe0fb43445baff14777e29afcdf">这一支最有意思。</div><div class="notion-text notion-block-c2b8a6a7ac7f45e484f09c252c596d6a">如果内容不需要更新，但有新的 <code class="notion-inline-code">agent_id</code> 或 <code class="notion-inline-code">run_id</code>，源码仍然会更新 metadata，而不改文本和 embedding。</div><div class="notion-text notion-block-d39d9b4136fe4015817a27ddd8d796a4">这意味着：</div><blockquote class="notion-quote notion-block-b16c90b3b6bf4ccb943bac9580cb2fb4"><div>在 mem0 的设计里，“记忆内容”和“记忆归属范围”是两个独立维度。</div></blockquote><hr class="notion-hr notion-block-9a50ba589cc64fffb26d95f39d6a70d7"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-f99071ddf74a40cdb3962f6db2af8521" data-id="f99071ddf74a40cdb3962f6db2af8521"><span><div id="f99071ddf74a40cdb3962f6db2af8521" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f99071ddf74a40cdb3962f6db2af8521" title="12. 代码到底体现了哪些设计思想"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">12. 代码到底体现了哪些设计思想</span></span></h2><div class="notion-text notion-block-0a615f389cdd4669a4ae75566d609cea">基于 <code class="notion-inline-code">_add_to_vector_store()</code>，可以把 mem0 的 memory write 设计总结成 5 个关键词。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-8a4211ff75aa4290a5ccb1b8caf3a25b" data-id="8a4211ff75aa4290a5ccb1b8caf3a25b"><span><div id="8a4211ff75aa4290a5ccb1b8caf3a25b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8a4211ff75aa4290a5ccb1b8caf3a25b" title="12.1 Retrieval-assisted writing"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">12.1 Retrieval-assisted writing</span></span></h3><div class="notion-text notion-block-94d60ed6ff15435187547ebd7f8f2e52">不是抽出来就存，而是：</div><ul class="notion-list notion-list-disc notion-block-4971b06a02c04ef5a8e52c68e223a3c7"><li>先抽 facts</li></ul><ul class="notion-list notion-list-disc notion-block-f6fcc5a19acf4389916c1cbd8ea0d3c2"><li>再搜旧 memories</li></ul><ul class="notion-list notion-list-disc notion-block-2a5209d23d82408b8bf6100925f6376a"><li>再决定动作</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-bdbb4087817d40299e0e77117c870cb0" data-id="bdbb4087817d40299e0e77117c870cb0"><span><div id="bdbb4087817d40299e0e77117c870cb0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bdbb4087817d40299e0e77117c870cb0" title="12.2 Stateful memory"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">12.2 Stateful memory</span></span></h3><div class="notion-text notion-block-41295855e2244691b6d05c76305db724">记忆不是一条条孤立文本，而是有状态、有冲突、有演化的对象。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-f58fb2081be04769b1627ad49780e6ba" data-id="f58fb2081be04769b1627ad49780e6ba"><span><div id="f58fb2081be04769b1627ad49780e6ba" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f58fb2081be04769b1627ad49780e6ba" title="12.3 Scope-aware"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">12.3 Scope-aware</span></span></h3><div class="notion-text notion-block-bb16f265e25b4b4d98050b33a22375de">旧 memory 检索总是带着：</div><ul class="notion-list notion-list-disc notion-block-359d48ee283f443c979a5d2b07a3e8a3"><li><code class="notion-inline-code">user_id</code></li></ul><ul class="notion-list notion-list-disc notion-block-71cfe550b0764f9bb8b09f4f1e485826"><li><code class="notion-inline-code">agent_id</code></li></ul><ul class="notion-list notion-list-disc notion-block-c4e053e573b64f4c99dba49bf13a946e"><li><code class="notion-inline-code">run_id</code></li></ul><div class="notion-text notion-block-b02a199d48134b3d9473002d2bd831c5">这使得 mem0 天然支持多用户、多 agent、多任务隔离。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-52e3089e184c49cbb6554f5fe59d4dee" data-id="52e3089e184c49cbb6554f5fe59d4dee"><span><div id="52e3089e184c49cbb6554f5fe59d4dee" class="notion-header-anchor"></div><a class="notion-hash-link" href="#52e3089e184c49cbb6554f5fe59d4dee" title="12.4 Prompt-driven"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">12.4 Prompt-driven</span></span></h3><div class="notion-text notion-block-0ff69752667446d48ec5a4a8d822ea79"><code class="notion-inline-code">custom_instructions</code> 和 <code class="notion-inline-code">custom_update_memory_prompt</code> 让“记什么”“怎么更新”都变成可配置规则，而不是硬编码。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-9fb2ad5ede6945f0bd60964a8996480d" data-id="9fb2ad5ede6945f0bd60964a8996480d"><span><div id="9fb2ad5ede6945f0bd60964a8996480d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9fb2ad5ede6945f0bd60964a8996480d" title="12.5 LLM-aware engineering"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">12.5 LLM-aware engineering</span></span></h3><div class="notion-text notion-block-ee6944b77a124b4fa3bf629d00b59c4d">像 UUID 映射成整数这种细节，说明源码非常了解 LLM 的脆弱点，并且为此做了工程优化。</div><hr class="notion-hr notion-block-91aac8ef61fe45c0b0739359789182b1"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-90276a345df745cca9c9a2626db72dda" data-id="90276a345df745cca9c9a2626db72dda"><span><div id="90276a345df745cca9c9a2626db72dda" class="notion-header-anchor"></div><a class="notion-hash-link" href="#90276a345df745cca9c9a2626db72dda" title="13. Graph memory：和 vector memory 是什么关系"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">13. Graph memory：和 vector memory 是什么关系</span></span></h2><div class="notion-text notion-block-64ce77e6ad7449f1b55fe34c911235b4">这一节不只停留在 <code class="notion-inline-code">main.py</code> 的 <code class="notion-inline-code">_add_to_graph()</code> 包装层，而是要继续下钻到 <code class="notion-inline-code">graph_memory.py</code>。因为真正的 graph 逻辑，不是在 orchestrator 里，而是在 graph backend 的 <code class="notion-inline-code">add()</code> 里。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-09a22ced90be41bdb2af7ccd68a3f29a" data-id="09a22ced90be41bdb2af7ccd68a3f29a"><span><div id="09a22ced90be41bdb2af7ccd68a3f29a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#09a22ced90be41bdb2af7ccd68a3f29a" title="13.1 直接看 graph_memory.py：add() 怎么做 graph 写入"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">13.1 直接看 <code class="notion-inline-code">graph_memory.py</code>：<code class="notion-inline-code">add()</code> 怎么做 graph 写入</span></span></h3><div class="notion-text notion-block-54dd1f92dc1843b5bced51f5a62e0e13">官方仓库里，<code class="notion-inline-code">graph_memory.py</code> 的 <code class="notion-inline-code">add()</code> 主体调用链可以概括成下面这段：</div><div class="notion-text notion-block-9d964e8ab527458684189d28a21314b6">这段代码非常关键，因为它直接暴露了 graph memory 的完整写入流程。它不是“收到一段文本就落图”，而是分成了五步：</div><ol start="1" class="notion-list notion-list-numbered notion-block-54b4969ca8aa4fdeb42977f2f446f3f5" style="list-style-type:decimal"><li><code class="notion-inline-code">_retrieve_nodes_from_data(...)</code>：先从文本里抽实体，并建立 <code class="notion-inline-code">entity_type_map</code></li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-034f7514c8ee43309c89951d0d8ee423" style="list-style-type:decimal"><li><code class="notion-inline-code">_establish_nodes_relations_from_data(...)</code>：再基于实体去抽关系，形成待新增关系集合</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-3d967efdf996419b875c7a6bf1efc18d" style="list-style-type:decimal"><li><code class="notion-inline-code">_search_graph_db(...)</code>：去现有图里搜索这些实体相关的旧关系</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-624dad7ee3ae45c4b1d5244c6368081e" style="list-style-type:decimal"><li><code class="notion-inline-code">_get_delete_entities_from_search_output(...)</code>：判断旧关系里哪些应该被删除</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-40d70ae00c5642f4a096930d3f598874" style="list-style-type:decimal"><li><code class="notion-inline-code">_delete_entities(...)</code> + <code class="notion-inline-code">_add_entities(...)</code>：最后真正执行图里的删除和新增</li></ol><div class="notion-text notion-block-190aaa0db01b40e98facb2361661380a">所以从这段 <code class="notion-inline-code">add()</code> 本身就能看出来：</div><blockquote class="notion-quote notion-block-31dcbdd53e104e68874a8f867d3f7e33"><div>graph memory 不是简单存储，而是一个“抽实体 → 抽关系 → 对齐旧图 → 删除旧关系 → 新增新关系”的图生命周期管理流程。</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-8426a6a6f23144dab373c71268e6ae02" data-id="8426a6a6f23144dab373c71268e6ae02"><span><div id="8426a6a6f23144dab373c71268e6ae02" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8426a6a6f23144dab373c71268e6ae02" title="13.2 graph 里 LLM 到底参与在什么地方"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">13.2 graph 里 LLM 到底参与在什么地方</span></span></h3><div class="notion-text notion-block-25e4a96a3ebf4d1bbe2349d6a65b866a">答案就在 <code class="notion-inline-code">graph_memory.py</code> 的内部函数里。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-e168eecaa3154345985eed660a976578" data-id="e168eecaa3154345985eed660a976578"><span><div id="e168eecaa3154345985eed660a976578" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e168eecaa3154345985eed660a976578" title="1. 抽实体：_retrieve_nodes_from_data() 里直接调用了 LLM"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 抽实体：<code class="notion-inline-code">_retrieve_nodes_from_data()</code> 里直接调用了 LLM</span></span></h4><div class="notion-text notion-block-63fc6089fbca4438b98d456cfdf63cd8">源码里，实体抽取函数会直接调用：</div><div class="notion-text notion-block-ccc9160f51984f8e88ecee8fd9e85bfd">这一步的目标不是聊天，而是：</div><ul class="notion-list notion-list-disc notion-block-ec06faa5952641cb992d6554d9f15c78"><li>从原始文本里抽取实体</li></ul><ul class="notion-list notion-list-disc notion-block-d3ee20bc7a17423593ce5cd7fe82d9bd"><li>给每个实体分配类型</li></ul><ul class="notion-list notion-list-disc notion-block-6ebc5bbf52914a2580c85e75e208b95c"><li>最后形成 <code class="notion-inline-code">entity_type_map</code></li></ul><div class="notion-text notion-block-db4c8ca64cf9429b934b2d90933e8bbc">后面它还会解析 tool call，把实体结果整理成映射表。也就是说：</div><blockquote class="notion-quote notion-block-bc3b666081d1445c8e08ab639e0be01c"><div>graph memory 的第一步不是存文本，而是先让 LLM 把文本理解成“实体集合”。</div></blockquote><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-f3dad91af1fd43199a329daffc332c60" data-id="f3dad91af1fd43199a329daffc332c60"><span><div id="f3dad91af1fd43199a329daffc332c60" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f3dad91af1fd43199a329daffc332c60" title="2. 抽关系：_establish_nodes_relations_from_data() 再调用一次 LLM"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 抽关系：<code class="notion-inline-code">_establish_nodes_relations_from_data()</code> 再调用一次 LLM</span></span></h4><div class="notion-text notion-block-4c81676eadee430da2bd91acf6f64da5">接下来 graph 不是直接把实体写成节点就结束了，而是还要继续抽关系。对应逻辑会再次调用：</div><div class="notion-text notion-block-70cf122655e4449a8a0ccb98f11dd6ee">这一步不是抽实体，而是：</div><ul class="notion-list notion-list-disc notion-block-c4edbe5442da448ea2becf285bd5b03d"><li>基于已经抽出来的实体集合</li></ul><ul class="notion-list notion-list-disc notion-block-80588363b95f4e59b968c754b64fe9a7"><li>再结合原始文本</li></ul><ul class="notion-list notion-list-disc notion-block-4f8a679f142944d3b901404e7a186aba"><li>让模型建立实体之间的关系</li></ul><ul class="notion-list notion-list-disc notion-block-2ec14fa26230470db142cec5ddd097dc"><li>最后形成待写入图数据库的关系三元组</li></ul><div class="notion-text notion-block-f774a0458a6c4b4db4b8914483b3ac79">所以 graph memory 的写入至少包含两轮语义抽取：</div><ul class="notion-list notion-list-disc notion-block-7ac7097d535844f5bf4369636e3a3c37"><li>第一轮：抽实体</li></ul><ul class="notion-list notion-list-disc notion-block-c2c71702cafe4499b51e9be571c5145d"><li>第二轮：抽关系</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-c6ba0d605db944b9819db7d293ff5f09" data-id="c6ba0d605db944b9819db7d293ff5f09"><span><div id="c6ba0d605db944b9819db7d293ff5f09" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c6ba0d605db944b9819db7d293ff5f09" title="3. 删除旧关系：graph 里连“删什么”都交给 LLM 决策"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 删除旧关系：graph 里连“删什么”都交给 LLM 决策</span></span></h4><div class="notion-text notion-block-9557c332b2794be3aa287b3b18495d7b">还有一个特别容易被忽略的点：graph memory 不只是抽实体和关系，它连“哪些旧关系该删”也会让 LLM 参与决策。</div><div class="notion-text notion-block-93df427842c34eea9578d6012979aba0">对应函数 <code class="notion-inline-code">_get_delete_entities_from_search_output(...)</code> 里也会调用：</div><div class="notion-text notion-block-cb3ec0fe7e794be58a42b0fbabcc4dd4">这一步的目标是：</div><ul class="notion-list notion-list-disc notion-block-2028445d2c3c4844a04c51203d137ee8"><li>先拿到旧图里的关系</li></ul><ul class="notion-list notion-list-disc notion-block-491d4fa4aa57496e8574d83d3031674b"><li>再结合当前输入文本</li></ul><ul class="notion-list notion-list-disc notion-block-961f375ab8b14b358dcd3c411b590f25"><li>让模型判断哪些旧关系已经过时或冲突</li></ul><ul class="notion-list notion-list-disc notion-block-a02513ca8a7e427291e21286353be805"><li>然后再执行删除</li></ul><div class="notion-text notion-block-5ac7f9e51c2649d3b0ec9d808e535b6a">所以 graph memory 的完整生命周期其实很清晰：</div><ul class="notion-list notion-list-disc notion-block-a28ebf436f94448dbf0a4d4eb47bcb57"><li>抽实体</li></ul><ul class="notion-list notion-list-disc notion-block-6540583da09c4b02b1c3c6e697665f9d"><li>抽关系</li></ul><ul class="notion-list notion-list-disc notion-block-1f3a02275f9741a5a22659129008ab19"><li>查旧图</li></ul><ul class="notion-list notion-list-disc notion-block-3801300dbf784ae39f002b1c7656e569"><li>判定删除</li></ul><ul class="notion-list notion-list-disc notion-block-2357a4505d084ed0abc5060c8c7ba0bb"><li>新增新关系</li></ul><div class="notion-text notion-block-9d86de36eee341ac82bd862d63eeb06e">换句话说：</div><blockquote class="notion-quote notion-block-59a1ab7cac7e47489bbe3f377bb991c2"><div>graph memory 不是 append-only，而是一个由 LLM 驱动的关系图重写流程。</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5456c0711c8144c197db9d556b197520" data-id="5456c0711c8144c197db9d556b197520"><span><div id="5456c0711c8144c197db9d556b197520" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5456c0711c8144c197db9d556b197520" title="13.3 所以 graph memory 和 vector memory 到底哪里像，哪里不像"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">13.3 所以 graph memory 和 vector memory 到底哪里像，哪里不像</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-65b476a81f5241ab8a1cbb2b8dfcf00e" data-id="65b476a81f5241ab8a1cbb2b8dfcf00e"><span><div id="65b476a81f5241ab8a1cbb2b8dfcf00e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#65b476a81f5241ab8a1cbb2b8dfcf00e" title="相似点：都不是“原文直接入库”"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">相似点：都不是“原文直接入库”</span></span></h4><div class="notion-text notion-block-4b5573d30fa04ca8b7ab79428e94bb4e">不管是 vector memory 还是 graph memory，它们都不是简单把原始文本塞进存储层。</div><ul class="notion-list notion-list-disc notion-block-411af72622c84dfbaadfd19164437094"><li>vector memory：抽 facts，再做 <code class="notion-inline-code">ADD / UPDATE / DELETE / NONE</code></li></ul><ul class="notion-list notion-list-disc notion-block-a5665c8fa08d4dfaa87749a3cf67aaea"><li>graph memory：抽 entities，再抽 relations，再决定删什么、加什么</li></ul><div class="notion-text notion-block-0ac144f2bf5b47c78d49a49d4685d9b6">从系统设计角度看，这两者都属于“语义先行，再持久化”的 memory pipeline。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-1894ffb71cb24382830d92f7e2054d9d" data-id="1894ffb71cb24382830d92f7e2054d9d"><span><div id="1894ffb71cb24382830d92f7e2054d9d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1894ffb71cb24382830d92f7e2054d9d" title="不同点：两者处理的对象完全不同"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">不同点：两者处理的对象完全不同</span></span></h4><h5 class="notion-h notion-h4 notion-h-indent-3 notion-block-362cf5757f684c53990699ba38333f8b" data-id="362cf5757f684c53990699ba38333f8b"><span><div id="362cf5757f684c53990699ba38333f8b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#362cf5757f684c53990699ba38333f8b" title="vector memory 处理的是 fact / memory item"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">vector memory 处理的是 <b>fact / memory item</b></span></span></h5><div class="notion-text notion-block-d20fa9284cdc4c73b0be76f0f3b516a4">vector 更关心的是：</div><ul class="notion-list notion-list-disc notion-block-25d61c03030246078edc58f56334b82a"><li>这句话里有什么事实值得记住</li></ul><ul class="notion-list notion-list-disc notion-block-7aaea5d8f8684605b076578eed49ebc8"><li>这条事实是新增、覆盖、删除还是忽略</li></ul><h5 class="notion-h notion-h4 notion-h-indent-3 notion-block-21d5f088ab22417892b7809a66db5456" data-id="21d5f088ab22417892b7809a66db5456"><span><div id="21d5f088ab22417892b7809a66db5456" class="notion-header-anchor"></div><a class="notion-hash-link" href="#21d5f088ab22417892b7809a66db5456" title="graph memory 处理的是 entity / relation / node / edge"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">graph memory 处理的是 <b>entity / relation / node / edge</b></span></span></h5><div class="notion-text notion-block-63bbe29f8c8440d29d6e4c1b5d18d55e">graph 更关心的是：</div><ul class="notion-list notion-list-disc notion-block-580ea8706bef41109f269ba90f353617"><li>这段文本里出现了哪些实体</li></ul><ul class="notion-list notion-list-disc notion-block-aff5dea8d463499b98ca1d8f6d121f14"><li>实体之间是什么关系</li></ul><ul class="notion-list notion-list-disc notion-block-85009e207a0b43efaecdd90cffeb88f7"><li>旧关系哪些需要失效</li></ul><ul class="notion-list notion-list-disc notion-block-83918097fb1d4c3a8175a06b3a6ef723"><li>新关系哪些需要写入</li></ul><div class="notion-text notion-block-a24ac59cb71a4098b0eba8cdaad4e86a">所以一句话概括：</div><blockquote class="notion-quote notion-block-423ae9b494bb41ed8ed9f4f666291a33"><div>vector memory 更像“记住一句有用的话”，graph memory 更像“把这句话拆成实体和关系网络”。</div></blockquote><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-75fad508659a43739dbf29de5c0a2296" data-id="75fad508659a43739dbf29de5c0a2296"><span><div id="75fad508659a43739dbf29de5c0a2296" class="notion-header-anchor"></div><a class="notion-hash-link" href="#75fad508659a43739dbf29de5c0a2296" title="13.4 graph 的 CRUD 怎么理解"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">13.4 graph 的 CRUD 怎么理解</span></span></h3><div class="notion-text notion-block-4a87644edb504aefaf4dfdb2126906b8">从 <code class="notion-inline-code">graph_memory.py</code> 这套实现来看，graph memory 至少有比较清晰的生命周期：</div><ul class="notion-list notion-list-disc notion-block-0d9a828b686d4c0da815c73603cb764a"><li>Create：<code class="notion-inline-code">_add_entities(...)</code> 新增 node / edge</li></ul><ul class="notion-list notion-list-disc notion-block-53d7114c84ec4dd5a32e00e0d4ce134f"><li>Read：<code class="notion-inline-code">search()</code> 返回 relations 相关结果</li></ul><ul class="notion-list notion-list-disc notion-block-431e061b2d0541c19d2e9ec4a46b7584"><li>Delete：<code class="notion-inline-code">_delete_entities(...)</code> 删除或失效旧关系</li></ul><ul class="notion-list notion-list-disc notion-block-093f1497edef45dfb0cc73103f0e9452"><li>Update：更像通过一次新的 <code class="notion-inline-code">add()</code> 流程触发“旧关系删除 + 新关系新增”来完成重写，而不是暴露一个单独的 <code class="notion-inline-code">graph.update()</code> 公共接口</li></ul><div class="notion-text notion-block-4fdd7dfdb1804f19a509f0edf7e68ed5">这一点和 vector memory 的区别也很明显：</div><ul class="notion-list notion-list-disc notion-block-7f013fc837574f1aaaffa98636a906d2"><li>vector memory 强调单条 fact 的生命周期管理</li></ul><ul class="notion-list notion-list-disc notion-block-7e4b8a269b094cccb4662d8ccd9b949c"><li>graph memory 更强调关系网络的维护与重构</li></ul><div class="notion-text notion-block-e834b53ac84a4c549b23836807865e79">也就是说，vector 更像“对象级记忆”，graph 更像“关系级记忆”。</div><hr class="notion-hr notion-block-c12c5f731f3d4b8c873e0dc9ce0d60c6"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-0a2c7ada2a7049e7b2c0163cd6167875" data-id="0a2c7ada2a7049e7b2c0163cd6167875"><span><div id="0a2c7ada2a7049e7b2c0163cd6167875" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0a2c7ada2a7049e7b2c0163cd6167875" title="14. Rerank 与业务设计：mem0 真正值钱的地方是什么"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">14. Rerank 与业务设计：mem0 真正值钱的地方是什么</span></span></h2><div class="notion-text notion-block-ae2ac3d283264bbe86e571542164d885">很多人会把 mem0 的价值理解成“能记住用户偏好”，但这其实只看到了表面。真正有业务价值的是，它把“长期记忆”拆成了几层可运营、可调规则的策略。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-a8daca1b447147d9b3063850e23eecae" data-id="a8daca1b447147d9b3063850e23eecae"><span><div id="a8daca1b447147d9b3063850e23eecae" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a8daca1b447147d9b3063850e23eecae" title="14.1 rerank 体现在哪里，为什么不放在 add 阶段"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">14.1 rerank 体现在哪里，为什么不放在 add 阶段</span></span></h3><div class="notion-text notion-block-333b5c2cc1324db0b0a4a65344c41652">这个问题很容易被问到。</div><div class="notion-text notion-block-8eb75e246e7e445ba7b6835f1a0caaa6">结论是：</div><blockquote class="notion-quote notion-block-95af4770bb754594a8cc8a2d713ed66e"><div><b>rerank 主要体现在 </b><code class="notion-inline-code"><b>search()</b></code><b>，而不是 </b><code class="notion-inline-code"><b>add()</b></code><b> 的旧 memory 搜索阶段。</b></div></blockquote><div class="notion-text notion-block-f4ec67a55f594f7cb76f756b0c64168e">原因并不复杂。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-c88e41531405415d8c05a135e3635f89" data-id="c88e41531405415d8c05a135e3635f89"><span><div id="c88e41531405415d8c05a135e3635f89" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c88e41531405415d8c05a135e3635f89" title="add 阶段搜旧 memories，目标是“判断状态”"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">add 阶段搜旧 memories，目标是“判断状态”</span></span></h4><div class="notion-text notion-block-c107a7b936bd4d2e8b065084d512f2f2">在 <code class="notion-inline-code">_add_to_vector_store()</code> 里，旧 memory 搜索的目的是：</div><ul class="notion-list notion-list-disc notion-block-d813aa5ec17f416abda3735475a9f647"><li>判断是否重复</li></ul><ul class="notion-list notion-list-disc notion-block-d80d34f9793342e9ae98066d3e009560"><li>判断是否冲突</li></ul><ul class="notion-list notion-list-disc notion-block-996db2c3bceb4b6bba05aeb82651c4d6"><li>判断应该 <code class="notion-inline-code">ADD / UPDATE / DELETE / NONE</code></li></ul><div class="notion-text notion-block-e8a241bdf6324c0898bc2ede39a1aedb">这一步要求的是：</div><ul class="notion-list notion-list-disc notion-block-bc20f81b02d04410860eed5dee5f1283"><li>足够快</li></ul><ul class="notion-list notion-list-disc notion-block-41aa205437444226900c4c68121b59e0"><li>足够稳</li></ul><ul class="notion-list notion-list-disc notion-block-2e0405c15e374fa6a2d1722c6c891de7"><li>能提供大致相关的旧 memory 即可</li></ul><div class="notion-text notion-block-366b8da2b04b44708172f49efcb9db96">所以这里通常不需要再加一层昂贵的 rerank。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-8499835f462644398b1d61c2903c8655" data-id="8499835f462644398b1d61c2903c8655"><span><div id="8499835f462644398b1d61c2903c8655" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8499835f462644398b1d61c2903c8655" title="search 阶段面向的是“对外召回质量”"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">search 阶段面向的是“对外召回质量”</span></span></h4><div class="notion-text notion-block-d29e490d2f694284b0a9fe19795ecc6c">而正式的 <code class="notion-inline-code">search()</code> 则完全不同。它的目标是：</div><ul class="notion-list notion-list-disc notion-block-82d88a1e57c544a5a96b9ece2e045be7"><li>给 agent 注入更高质量上下文</li></ul><ul class="notion-list notion-list-disc notion-block-8ab6cd9c16a0492b9a61d1272bdf9ed5"><li>给用户返回更准确的 memory</li></ul><ul class="notion-list notion-list-disc notion-block-b3fc0e62e38642c9884ab073607bd792"><li>把 semantic search、keyword search、entity boost 之后的结果再精排</li></ul><div class="notion-text notion-block-292c697ccb7047848989f2061240802f">所以 rerank 更适合放在这里。</div><div class="notion-text notion-block-84f1ee5982654535bc44d906397024af">这其实是个很合理的分层：</div><ul class="notion-list notion-list-disc notion-block-ebcd825befb34305b960264d01532b1e"><li><code class="notion-inline-code">add()</code>：偏写入决策，关注状态判断</li></ul><ul class="notion-list notion-list-disc notion-block-8265b9237d694769b121b1d2c5543ac9"><li><code class="notion-inline-code">search()</code>：偏对外召回，关注结果质量</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-9c6521a4d0c0477684ff6f9bdfc719c4" data-id="9c6521a4d0c0477684ff6f9bdfc719c4"><span><div id="9c6521a4d0c0477684ff6f9bdfc719c4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9c6521a4d0c0477684ff6f9bdfc719c4" title="14.2 业务上真正值钱的是四层策略"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">14.2 业务上真正值钱的是四层策略</span></span></h3><div class="notion-text notion-block-fafed2a494b145fd9dcc3d39bd37d34e">如果站在业务设计视角看，mem0 真正有价值的不是“支持很多模型和很多库”，而是把长期记忆拆成了四层可运营策略。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-8390cdaeabf94c9caf846bd41d9506a6" data-id="8390cdaeabf94c9caf846bd41d9506a6"><span><div id="8390cdaeabf94c9caf846bd41d9506a6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8390cdaeabf94c9caf846bd41d9506a6" title="第一层：写入策略——什么值得记"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第一层：写入策略——什么值得记</span></span></h4><div class="notion-text notion-block-3c8a175ed8954198a3c24b6bb86dea03">通过 <code class="notion-inline-code">custom_instructions</code> 定义。</div><div class="notion-text notion-block-99072b91ce194725b157831e8bf68bd1">这决定了：</div><ul class="notion-list notion-list-disc notion-block-29fec14a665948b9b6d0d60aeb4d176c"><li>什么内容允许进入长期记忆</li></ul><ul class="notion-list notion-list-disc notion-block-a64fd3e0a3f74670b9674d12f6b8bbd4"><li>什么内容必须被过滤掉</li></ul><div class="notion-text notion-block-adccdad4f2114d489cf95df2e83bde28">这对真实业务特别重要。因为业务通常不需要“尽可能多地记忆”，而是需要“只记高价值信息”。</div><div class="notion-text notion-block-274d1796cd914dc5af972ad1c18de677">例如：</div><ul class="notion-list notion-list-disc notion-block-a477f3dc45664d22a751299339066ece"><li>客服：只记订单、地址、售后诉求</li></ul><ul class="notion-list notion-list-disc notion-block-0964eb5b77f44fb48f9bd029b78161c2"><li>医疗：只记过敏史、既往病史、诊疗偏好</li></ul><ul class="notion-list notion-list-disc notion-block-1de35f3bae0449c4b371f5e206ebd41d"><li>IDE Agent：只记 repo 约定、工具偏好、失败经验</li></ul><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-b16b55b98f004a9ea8e595cbaa59b38a" data-id="b16b55b98f004a9ea8e595cbaa59b38a"><span><div id="b16b55b98f004a9ea8e595cbaa59b38a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b16b55b98f004a9ea8e595cbaa59b38a" title="第二层：更新策略——新旧事实冲突时怎么办"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第二层：更新策略——新旧事实冲突时怎么办</span></span></h4><div class="notion-text notion-block-c96b9ce465bf4fe783af13de62d4c391">通过 <code class="notion-inline-code">custom_update_memory_prompt</code> 定义。</div><div class="notion-text notion-block-0ce62e4aca60410f8320e059bf65435b">这决定了：</div><ul class="notion-list notion-list-disc notion-block-aabc70c678734a92a1c8e5a7298bb6e6"><li>什么情况应该新增</li></ul><ul class="notion-list notion-list-disc notion-block-a6a608691094409ca6cd1389b9736354"><li>什么情况应该覆盖</li></ul><ul class="notion-list notion-list-disc notion-block-1c40d32dc9504c8c8168430daf7138ef"><li>什么情况应该删除</li></ul><ul class="notion-list notion-list-disc notion-block-374213dc931840a69b5a27154be398b2"><li>什么情况应该保持 <code class="notion-inline-code">NONE</code></li></ul><div class="notion-text notion-block-822810d72391487c9d8632793a3f39a1">这一步直接决定 memory system 是“日志堆积”，还是“有状态、可演化的长期记忆”。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-eedcedd92f244f5498a89feb5a47a93b" data-id="eedcedd92f244f5498a89feb5a47a93b"><span><div id="eedcedd92f244f5498a89feb5a47a93b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#eedcedd92f244f5498a89feb5a47a93b" title="第三层：作用域策略——这条 memory 属于谁"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第三层：作用域策略——这条 memory 属于谁</span></span></h4><div class="notion-text notion-block-54b6a57e47224e4aa65df7bb06939827">通过：</div><ul class="notion-list notion-list-disc notion-block-231f93e0a2e44fd8a4acf591041549c0"><li><code class="notion-inline-code">user_id</code></li></ul><ul class="notion-list notion-list-disc notion-block-c4a0d567a45d40c1a2e8505d5805ed56"><li><code class="notion-inline-code">agent_id</code></li></ul><ul class="notion-list notion-list-disc notion-block-de56e64e0c0c4bea95a76b3e7505ddbd"><li><code class="notion-inline-code">run_id</code></li></ul><div class="notion-text notion-block-d215aa655c914ab283ee0c288509f0b1">定义。</div><div class="notion-text notion-block-0dba9f2bfe3b4b8a80f4c9640d3f6033">这意味着你可以把记忆清晰地分成：</div><ul class="notion-list notion-list-disc notion-block-d115a215fa2948fc9335f8baf70bee58"><li>属于某个用户的长期偏好</li></ul><ul class="notion-list notion-list-disc notion-block-77f1797112004402ac6026eea3478a3b"><li>属于某个 agent 的经验或专属上下文</li></ul><ul class="notion-list notion-list-disc notion-block-daa6a4bcbd5d40f9a856e0deab12261a"><li>属于某次 run 的短期任务信息</li></ul><div class="notion-text notion-block-6d8fffbd0fd343a79f03d404a2b22bf8">这也是 mem0 可以支撑多用户、多 agent、多任务系统的核心原因。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-c57be81a8897415a8c782ef0cf409469" data-id="c57be81a8897415a8c782ef0cf409469"><span><div id="c57be81a8897415a8c782ef0cf409469" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c57be81a8897415a8c782ef0cf409469" title="第四层：检索质量策略——怎么把相关 memory 找准"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">第四层：检索质量策略——怎么把相关 memory 找准</span></span></h4><div class="notion-text notion-block-2888da1e20ab4c8da17e002fc74e5721">这一层由多个模块共同决定：</div><ul class="notion-list notion-list-disc notion-block-fd45ab55848645b4b42cb12f25610775"><li>vector search</li></ul><ul class="notion-list notion-list-disc notion-block-53e2303da0064708a88c9cc80759aced"><li>keyword search</li></ul><ul class="notion-list notion-list-disc notion-block-f931b84404124faea988f00fd2a1c716"><li>entity boost</li></ul><ul class="notion-list notion-list-disc notion-block-7909467b9eeb4628aad3d2755a13e6eb"><li>rerank</li></ul><ul class="notion-list notion-list-disc notion-block-0e51c6cf7a1a414abca88707874c8ea8"><li>graph relations</li></ul><div class="notion-text notion-block-245eaa57f9bd46cbad076aca132ec558">从系统角度看，mem0 并不是简单的 ANN 检索，而是在逐步把 search 做成一套多路增强的召回与精排系统。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5d092a38a2f94fb3a4360b4e24f591a5" data-id="5d092a38a2f94fb3a4360b4e24f591a5"><span><div id="5d092a38a2f94fb3a4360b4e24f591a5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5d092a38a2f94fb3a4360b4e24f591a5" title="14.3 所以 mem0 真正值钱的地方到底是什么"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">14.3 所以 mem0 真正值钱的地方到底是什么</span></span></h3><div class="notion-text notion-block-a4e9dd5f49284e4f97a0792c5261fef5">如果只从“它能记住用户偏好”来看 mem0，其实低估它了。</div><div class="notion-text notion-block-d09b7133c80443b78b7f19c3eb1e03f2">我更倾向于把它总结成一句话：</div><blockquote class="notion-quote notion-block-48f468a25d7f41439b72fb038651eb0c"><div>mem0 的真正价值，不是“它支持很多向量库”，而是“它把 memory 变成了一套可运营的业务系统”。</div></blockquote><div class="notion-text notion-block-ea16f65d2af24b39a6f0f083df0b0f08">也就是说，mem0 最有价值的地方，不是某一个 provider，也不是某一个 graph backend，而是它把长期记忆拆成了：</div><ul class="notion-list notion-list-disc notion-block-b790283ed58741bd849b4b4b0c47f5f7"><li>可以控制写什么</li></ul><ul class="notion-list notion-list-disc notion-block-8eec4f47e82344d4a849e91b3735d05a"><li>可以控制怎么改</li></ul><ul class="notion-list notion-list-disc notion-block-f324749a73114424bd1f4a150f50db57"><li>可以控制记给谁</li></ul><ul class="notion-list notion-list-disc notion-block-1d9c0b24513b47c2ab03d0c635d5409a"><li>可以控制怎么找</li></ul><div class="notion-text notion-block-3748ee0df6f74d678b6960b812f1875a">这四层策略。</div><div class="notion-text notion-block-629b0ee9bebc40f7848787de8814e1a0">这才是它和“自己手搓一个向量库 + embedding + search”最大的差别。</div><hr class="notion-hr notion-block-752eaf0bc0df4ebba7a2b5b26349aa8b"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-5b29551c57c24a809cc09a5d900ee3ef" data-id="5b29551c57c24a809cc09a5d900ee3ef"><span><div id="5b29551c57c24a809cc09a5d900ee3ef" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5b29551c57c24a809cc09a5d900ee3ef" title="参考资料"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">参考资料</span></span></h2><div class="notion-text notion-block-344d690ad6d18041b8b2ee8829d46a60"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/mem0ai/mem0">mem0ai/mem0: Universal memory layer for AI Agents</a></div><div class="notion-text notion-block-344d690ad6d180d1b81ee51f204a432f"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.cnblogs.com/wylrcx/p/19842964">Mem0 源码解析系列（一）：记忆是如何被添加的 - 肥肥旭手记 - 博客园</a></div><div class="notion-blank notion-block-344d690ad6d180178e73c01466077c45"> </div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>