<?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>Thu, 10 Sep 2026 08:59:45 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[半年度总结]]></title>
            <link>https://www.junlin-233.top/article/37cd690a-d6d1-8049-aeec-ef1826a57ed0</link>
            <guid>https://www.junlin-233.top/article/37cd690a-d6d1-8049-aeec-ef1826a57ed0</guid>
            <pubDate>Thu, 11 Jun 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-37cd690ad6d18049aeecef1826a57ed0"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-37cd690ad6d180fe8ffce971de5cb807" data-id="37cd690ad6d180fe8ffce971de5cb807"><span><div id="37cd690ad6d180fe8ffce971de5cb807" class="notion-header-anchor"></div><a class="notion-hash-link" href="#37cd690ad6d180fe8ffce971de5cb807" 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-37cd690ad6d18034a44de9954d5ef935">先感谢企鹅给我这次实习机会，一路下来都很流畅，跟每个面试官聊的都很开心，有鹅选鹅！</div><div class="notion-text notion-block-37cd690ad6d1809e85b8f52dfc04570c">回头看这半年，可谓波澜起伏，虽然有些日子很难熬，也充满迷茫，但是一路下来成长了许多，有时候也不得不感概是命运推动了你的一步又一步，一月份的我绝对不会想到六月能拿到腾讯的offer，收到了很多好友的祝福，其实在这里也想跟大家澄清一下我说幸运真的也不是谦辞，找工作和相亲没啥区别，有时候你觉得无比合适但是人家就是看不上你，有时候你觉得没戏了但是人家偏偏就中意你，所以正在看这段文字的朋友们，面试挂是正常的，多面，多提升自己，总会有守得云开见月明的一天。当然，在幸运女神眷顾你之前，先做好准备。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-37cd690ad6d18029aa3eddebe85cfd14" data-id="37cd690ad6d18029aa3eddebe85cfd14"><span><div id="37cd690ad6d18029aa3eddebe85cfd14" class="notion-header-anchor"></div><a class="notion-hash-link" href="#37cd690ad6d18029aa3eddebe85cfd14" title="1月~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">1月~4月</span></span></h2><div class="notion-text notion-block-37cd690ad6d1806bacabda5bc2507cb0">说实话，我一开始没打算认真准备实习，就想着这次寒假有点长（快50天了），能不能随便投个公司看看，这个时候只有大创的项目，其它啥也没有，题目没刷，八股也没背，甚至还对安全行业抱有幻想。然后海投一通，越投越心凉，越投越觉得安全完蛋了（我水平不够，这个是基于我的水平得出的结论，大佬勿cue），那个时候也很焦虑，一开始以为自己有学历有项目就可以有恃无恐，经过真实的就业市场拷打，发现自己真的是困在信息茧房里，还活在华南第一学府的幻想里。越急投的就越杂，一开始还自视清高看不起小厂，后面直接老实了，啥都投，总算是有几个面试邀约了：</div><div class="notion-text notion-block-37cd690ad6d180d4b45cd277112a8d5d">小厂，Linux开发，一面挂</div><div class="notion-text notion-block-37cd690ad6d180c5825ff3cddcf784f1">vivo，互联网安全算法工程师（实际jd和算法关系不大应该是做风控的），一面挂（聊了五十多分钟，本来人家都不考我算法题，结果脑子一抽让人家来了一道，判断循环链表，结果啥也没写出来/(ㄒoㄒ)/~~）</div><div class="notion-text notion-block-37cd690ad6d180f696c4fb2e9ebd43f7">小厂，全栈开发远程，一面挂</div><div class="notion-text notion-block-37cd690ad6d1804db87edf6356086a2a">初创公司， 游戏开发（实则全栈），入职</div><div class="notion-text notion-block-37cd690ad6d180aeac97f6ebf300388d">出于隐私考虑就不透露前司信息了。当时是boss上老板直接找我，我想着试试也不亏就加了v，面试过程很轻松，就聊了聊项目，了解了一下他想要做的ai游戏，不得不说，前老板还是很有口才的，直接把我忽悠来了，就这样子稀里糊涂的，入职前司。</div><div class="notion-text notion-block-37cd690ad6d180eea0b9e29cfd8881b2">第一个月是在A8音乐大厦工作，办公室很小，但是氛围很好，前老板的招人有一手，同事基本上都是名校，性格也都很好，那时候真的是嘻嘻哈哈的办公，早9：30晚6：30，没什么工作压力。入职之后才知道所谓的ai游戏只有一个demo，一切从0开始，0.0。不过也好，从0到1也是一个很有成就的过程。我在第一个月负责的是游戏地图的开发，偏前端，同时也参与了许多玩法的讨论，除了每天来回通勤三个小时，这段日子真的是无忧无虑，也很有盼头，那时候是真想把游戏做出来，希望陪着公司壮大。</div><div class="notion-text notion-block-37cd690ad6d180bd9ec3e6a00b9328c9">可惜现实不是小说，时间不会定格在那一秒。过完年回来后，办公室换到金融科技大厦，和同事合租在丹华公馆，本以为百废俱兴，没想到新的彻彻底底，在“激烈”的大讨论后，前老板决定全力做一款ai游戏社区，游戏本体开发先放一边，然后就是不断开发，测试，重构，开发的循环，对于这个决策，毕竟所有东西都还没上线，好坏的结果我也不知，只是觉得以前在A8那会的气氛好像慢慢溜走了，没有以前那么快乐了。故事的转折点在一个同事的离开（下面简称s），前老板辞退s的消息像深水炸弹，炸开了我们平淡不经的生活，也抛下了一些不切实际的幻想。</div><div class="notion-text notion-block-37cd690ad6d1803b97cfe866e8f70613">s是哈工深的大四，这段实习是转正实习，尽管s本人不怎么在意，但是在4月份春招过半的时候辞退一个大四的学生还是让我们心里感觉到不舒服，诚然，对我个人而言前老板待我不薄，对我包括其它人是没得说的。具体辞退的原因暂且不知，没准是我们总开玩笑地说s啥都不干，说者无意听者有心，让前老板心里记了一笔。</div><div class="notion-text notion-block-37cd690ad6d18089b8f7ee7ba618974f">有人走就有人来，替代s的是一个正职，之前在字节工作，比起大学生来说更多了几分在社会上的成熟稳重，有经验的人在，项目也慢慢步入正轨，但是离开的种子在我们的心里悄然埋下。在前司，100%的开发都是vibe coding，人总是有惰性的，等待的时间大部分都用来摸鱼了，感觉学不到技术，项目也看不到光明的前景，加上s的离开，种种原因之下，在拿到了一个远程agent开发的实习时，我提出了离职。</div><div class="notion-text notion-block-37cd690ad6d1800e81e9d531fef04e79">说实话，离职很冲动，现在回过头来看，很多自以为是的原因，都是给离开找补，离开就是离开，哪需要那么多原因呢？我总是会想当然的觉得一些事，就像我想当然的觉得远程的氛围会和前司一样，结果没干两周就受不了了，一方面是和自己想找远程的初衷不符（轻松自在），另一方面是觉得这个公司提出来的东西总是很没理头的（一百块一天的工资，让我一天半写个测试平台？我呸），之前说好前三周是200一天，没想到最后结算的公司是100一天，现在想想也是气愤无比，有些东西失去了才懂得珍惜，前司的自由自在，或许很难在别的公司复刻了。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-37cd690ad6d180f9930ce2c1345bf7af" data-id="37cd690ad6d180f9930ce2c1345bf7af"><span><div id="37cd690ad6d180f9930ce2c1345bf7af" class="notion-header-anchor"></div><a class="notion-hash-link" href="#37cd690ad6d180f9930ce2c1345bf7af" title="5月~6月"><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月~6月</span></span></h2><div class="notion-text notion-block-37cd690ad6d18095803bf582e3e8beb8">把工作都辞之后，不得不面对一个现实的问题，合租的房子还要不要继续呢？舍不得合租的生活，加上s的建议，正式开始了我的投递之旅：</div><div class="notion-text notion-block-37cd690ad6d1801eb6e1c5a733f750c7">字节，ai全栈开发，二面挂</div><div class="notion-text notion-block-37cd690ad6d180ed8584e23d12c88a5f">编程猫，ai产品经理，一面没去</div><div class="notion-text notion-block-37cd690ad6d1806981b0d750a741f57a">第六大道，agent开发，一面挂</div><div class="notion-text notion-block-37cd690ad6d180bc9980dfaa02993dc3">以及无数个知名厂的简历挂</div><div class="notion-text notion-block-37cd690ad6d180c3a690dc0e17c1b54f">腾讯，产品策划，offer</div><div class="notion-text notion-block-37cd690ad6d180dba60be11f9cf3fd23">投递的日子真的很难熬，比起寒假那会更加内耗，之前还可以安慰自己没啥东西，现在有了实习经历和含金量尚可的项目，结果还是海投一通没啥结果，那会真是不断的自我怀疑，质疑自己的学历，自己的能力，特别是字节二面，明明感觉自己表现的很好，但还是挂了，特别委屈，也无可奈何，好在最后腾讯收留了我，我知道这和我的努力离不开关系，我的面试表现也很从容不迫，但是，比我能力强的大有人在，还是感谢幸运女神，也感谢一直坚持不懈的自己！！！</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-37cd690ad6d180069dfcde075ccf75c5" data-id="37cd690ad6d180069dfcde075ccf75c5"><span><div id="37cd690ad6d180069dfcde075ccf75c5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#37cd690ad6d180069dfcde075ccf75c5" 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-37cd690ad6d1808a9612d3c33d086527">说实话，从技术岗到产品岗需要很大的决心（虽然腾讯这个本质上是ai产品），但是针对我个人来说，也是深思熟虑之后的结果，以下是我对一些岗位的看法：</div><div class="notion-text notion-block-37cd690ad6d1802b8e31e38efbee61af">agent开发，今年的热门，前景尚可，本质上是agent＋后端，热度过去之后不会像现在这样子的高需求，对于27届实习26届校招来说是不错的选择，也正是红利期。但是投递下来针对28届的岗位很少，是我喜欢的岗位，可惜没机会。</div><div class="notion-text notion-block-37cd690ad6d1800bb419cef50867452a">普通开发，ai时代开发的需求是增加的，但是很大一部分的工作都会交给ai了，开发工程师更多的是对项目的全局把控，架构评估，说人话就是开发岗暂时不会被ai取代，但是岗位数量会减少，门槛会提高。至于我的话，我这个臭学python，没用过redis，mq，纯纯被卡在门外。前端客户端这种我不熟悉，但是对于后端开发的话，学习go或java才是出路（尽管语言没有以前那么重要），最好实际设计一个有redis，mq这种后端八股常问的技术栈的项目，做过和背过，还是有本质区别的。</div><div class="notion-text notion-block-37cd690ad6d180ce88fcead14a3935a4">最后就是产品了，觉得自己适合产品的原因是感觉对技术的热情没有那么大，更喜欢做一些东西，而不是研究怎么做，也觉得在ai时代和业务贴合的岗不会那么容易被替代。当然有优点就会有缺点，产品对学历的门槛很高，据我在小红书的观察来看，文科基本上需要硕士加几段中大厂实习，技术背景的工科本科或许够用，实习也需要两三段，本质上产品不像技术岗有硬性门槛，需要卷学历，卷实习来证明自己的能力（目前的拙见，入职以后会有更清晰的看法）</div><div class="notion-text notion-block-37cd690ad6d180cead47ea79053986bd">对于实习来说，技术岗更看重技术的熟练程度，我的建议是针对想投的岗位多做项目，多实践。产品岗更看重为什么的问题，平时多思辨一下，也锻炼一下个人的表达能力。不管什么岗，自信都很重要，要让面试官觉得你能够胜任这个岗位。此外，牛客和小红书有许多面经，也可以参考参考。</div><div class="notion-text notion-block-37cd690ad6d18001873de9d4abf96243">有些时候想多了全是问题，做多了都是答案，很多东西在你做的时候会明白。</div><div class="notion-text notion-block-37cd690ad6d18044a38ccdfa82d009a2">最后打个广，推荐一下腾讯二面面试官感兴趣的我的基于opencode的多agent编排插件：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/junlin-233/oh-my-lite-openagent">junlin-233/oh-my-lite-openagent: Lite subagent plugin, compatible with OpenCode.</a></div><div class="notion-text notion-block-37cd690ad6d1809fb25eecf3e24d6e4a">记得打个星标噢</div><div class="notion-blank notion-block-37cd690ad6d180019db3c462f76b6579"> </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>
        <item>
            <title><![CDATA[我的工作流推荐—oh my openagent]]></title>
            <link>https://www.junlin-233.top/article/oh-my-openagent-recommend</link>
            <guid>https://www.junlin-233.top/article/oh-my-openagent-recommend</guid>
            <pubDate>Mon, 20 Apr 2026 00:00:00 GMT</pubDate>
            <description><![CDATA[最近发现一个特别顺手的 AI coding 神器——Oh My OpenAgent。本文从 subagent 规划、提示词编写、工作流、角色功能、以及与普通开发模式的优劣几个维度大拆解，帮你快速看懂它为什么值得被称为「the best agent harness」。]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-348d690ad6d180928082c749dee316e6"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-orange_background_co notion-block-27c852e952f0446fa5799cc338607c0d"><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-95130731981a4c81bdbc34c7e41d157e">无论LLM发展的如何,subagent注定是现在乃至未来的开发主流，下文就带你了解我的开发工作流，subagent的最佳实践（个人看法）—oh my openagent（下文简称omo）</div></div></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-917925575f9c4fd29977884072c4322d" data-id="917925575f9c4fd29977884072c4322d"><span><div id="917925575f9c4fd29977884072c4322d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#917925575f9c4fd29977884072c4322d" title="Oh My OpenAgent 是什么"><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">Oh My OpenAgent 是什么</span></span></h2><div class="notion-text notion-block-e8592c2cf19447c0b31a077c49eb3aae"><b>omo</b> 是 OpenCode 生态下的一个第三方 plugin，GitHub Star 52k+，累计下载 2M+，作者是 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/code-yeongyu">code-yeongyu</a>。它的优势在于——<b>不绑定任何一家模型厂商，</b>Claude、GPT、Gemini、Kimi、GLM、MiniMax等等全部能接，按<b>任务挑模型</b>，让每个模型在自己擅长的领域发挥最大潜力。同时它还有内置专业化agent、MCP、LSP等等，开箱即用，你只需要导入你的订阅，为每个角色配置模型（如果你懒让agent自己配置也可以），就可以开始omo之旅。</div><div class="notion-text notion-block-3741be7263b443138dee3e19cca5a5f7">之前我在agent入门一文讲到，agent开发应该遵循最简原则避免过度复杂设计，这在我们开发工作流的选择也是适用的，我并不推荐所有人都使用omo，它的设计太“重”了，如果你日常的开发并不只局限于单个功能的迭代实现或者你的任务更倾向于一人即一个部门的模式（这听起来其实有些悲观），那么<b>omo基本就是为你量身定制的</b>。</div><div class="notion-blank notion-block-348d690ad6d18086a80fc178f9934d35"> </div><hr class="notion-hr notion-block-c8c6a361e9384fe2ad3affc215547039"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-7b1f44fd8d5c44a293cf9aa2e62f59e1" data-id="7b1f44fd8d5c44a293cf9aa2e62f59e1"><span><div id="7b1f44fd8d5c44a293cf9aa2e62f59e1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7b1f44fd8d5c44a293cf9aa2e62f59e1" 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-965236020c314fc68c2f9378f866ce24">这是我觉得 omo 最有洞见的地方。</div><blockquote class="notion-quote notion-default notion-block-75795bc476904ae7ab833ed292cede05"><div><b>你不能用同一套提示词去驱动所有模型。</b></div></blockquote><div class="notion-text notion-block-5bb739234a0f4d6a8de967e1d78e3385">作者观察到，Claude / GPT / Gemini 这三大家族的思考方式其实差异很大。</div><table class="notion-simple-table notion-block-fc75a79d56184d58a78463fb800fa66d"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-6a79627e17e6446393432b465d81e095"><td class="" style="width:120px"><div class="notion-simple-table-cell">模型家族</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">个性标签</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">喜欢的 prompt</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">擅长</div></td></tr><tr class="notion-simple-table-row notion-block-919aab285deb4ea193c02d2d73f85da3"><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>Claude 系</b>（含 Kimi、GLM）</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">清单工匠</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">机制驱动、分步 SOP、规则越细越好</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">长指令链、高遵循度任务</div></td></tr><tr class="notion-simple-table-row notion-block-97fcb545cccf415dbc106c0822393c9f"><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>GPT 系</b>（5.2+）</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">原则派</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">简洁 XML、给标准不给菜谱</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">自主探索、硬逻辑推理</div></td></tr><tr class="notion-simple-table-row notion-block-74521838cfaa4345affcf0e4473d6819"><td class="" style="width:120px"><div class="notion-simple-table-cell"><b>Gemini 系</b></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">视觉型选手</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">混合输入、多模态描述</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">前端、UI、创意、视觉理解</div></td></tr></tbody></table><div class="notion-text notion-block-c1ddaab1f4364da7885306fbaca4bc92">所以 omo 的做法是：<b>同一个agent角色，在不同模型下用完全不同的系统提示词</b>。</div><div class="notion-text notion-block-b0cecfd0e1dd4b2988df7d0fce399be7">举个例，规划 <b>agent</b> <b>Prometheus</b>：</div><ul class="notion-list notion-list-disc notion-block-2fdc3b2eb1bd4a6ca1de23551ab87ef4"><li>Claude 版： <b>约 1100 行</b>，流程拆解到牢，SOP 一步一步把你牵着走</li></ul><ul class="notion-list notion-list-disc notion-block-a82fd88555154ff18d64efe5a952fe18"><li>GPT 版： <b>约 121 行</b>，只给原则和决策标准，剩下的交给模型自己发挥</li></ul><div class="notion-text notion-block-c94c141c2a5241cfa47b566f36b69956">运行时用 <code class="notion-inline-code">isGptModel()</code> 自动判断并切换，<b>用户完全无感</b>。</div><div class="notion-blank notion-block-b53bd7165d7b47a48121d6ec5cbd7b66"> </div><hr class="notion-hr notion-block-6076748330674fefba33033712b943f7"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4edf13acb6cd42a6a7b97989830b4176" data-id="4edf13acb6cd42a6a7b97989830b4176"><span><div id="4edf13acb6cd42a6a7b97989830b4176" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4edf13acb6cd42a6a7b97989830b4176" 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-ae4f2d64b5f24489b1bef89772e2112a">可以把 omo 理解成<b>一家小型 AI 公司</b>：</div><div class="notion-blank notion-block-59c951012fc2421a85ace3aa9ddace74"> </div><hr class="notion-hr notion-block-511220bc2dbc4370b1cb57b739ee3a13"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-de5b8bcdb51f407b9f4e98d9ff7d7eed" data-id="de5b8bcdb51f407b9f4e98d9ff7d7eed"><span><div id="de5b8bcdb51f407b9f4e98d9ff7d7eed" class="notion-header-anchor"></div><a class="notion-hash-link" href="#de5b8bcdb51f407b9f4e98d9ff7d7eed" title="Subagent 规划"><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">Subagent 规划</span></span></h2><div class="notion-text notion-block-135f2973dc7342c98bfa6b2c23354cef">作者把所有 agent 按<b>模型家族 + 角色功能</b>分成了四组。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-c66580639b584f9c8f9ff5cbd4c95245" data-id="c66580639b584f9c8f9ff5cbd4c95245"><span><div id="c66580639b584f9c8f9ff5cbd4c95245" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c66580639b584f9c8f9ff5cbd4c95245" title="Group 1：Communicators（编排层）"><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">Group 1：Communicators（编排层）</span></span></h3><div class="notion-text notion-block-0bff276608bd43b6944f7d4cd89e5771">面对用户的一线角色，默认跑 Claude Opus / Kimi K2.5 / GLM-5.1(实际体验下来GPT-5.4也能胜任，模型型号请以你现在的情况为准)。</div><ul class="notion-list notion-list-disc notion-block-52a9243e476b4753a49e21e41c7ef8c4"><li><b>Sisyphus</b>：CTO。<b>约 1100 行的提示词</b>，负责总体规划和最终验证。</li></ul><ul class="notion-list notion-list-disc notion-block-348d690ad6d180c59ee2d93f97bbe1cf"><li><b>Metis</b>：搭档。<b>高温度</b>采样，鼓励发散，专门在计划定稿前问一句：「我们还漏了什么？」</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-3fedaf9b421743308c279df283a6ac32" data-id="3fedaf9b421743308c279df283a6ac32"><span><div id="3fedaf9b421743308c279df283a6ac32" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3fedaf9b421743308c279df283a6ac32" title="Group 2：Dual-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">Group 2：Dual-Prompt（规划层）</span></span></h3><div class="notion-text notion-block-ae3bc62b46fc4fe29bd84e30e55ae17d">同一个 agent，为不同模型家族写了两套提示词。</div><ul class="notion-list notion-list-disc notion-block-c0be878cd71a4a25a137b5cf66b5f7d9"><li><b>Prometheus</b>：战略规划师。像真工程师一样跟你做访谈——范围、约束、验收标准、不能碰的红线，一条条对齐。这是我最喜欢的角色，AI时代，你应该在文档上多花费工夫，而不是在代码上。</li></ul><ul class="notion-list notion-list-disc notion-block-8d659d0572ac4b9a8094758a01b923f7"><li><b>Atlas</b>：执行指挥。接过 Prometheus 的计划，拆成 todo 并行分派给各路 agent，逐项打勾。跨任务累积「经验值」，之前学到的约定下次不用再教。</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-acebc66b385a420f88b5945c62816a17" data-id="acebc66b385a420f88b5945c62816a17"><span><div id="acebc66b385a420f88b5945c62816a17" class="notion-header-anchor"></div><a class="notion-hash-link" href="#acebc66b385a420f88b5945c62816a17" title="Group 3：GPT-Native（深度执行层）"><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">Group 3：GPT-Native（深度执行层）</span></span></h3><div class="notion-text notion-block-ebe75e21309c450faed27e75528680ce">为 GPT 系列量身打造。</div><ul class="notion-list notion-list-disc notion-block-fd2e1b6bd9fa4db1adc094cd2cbf6c30"><li><b>Hephaestus</b>：独立深度工匠（强烈推荐codex系列），<b>给目标不给菜谱</b>风格。封闭流程：<b>EXPLORE → PLAN → DECIDE → EXECUTE → VERIFY</b>，开工前先派 2–5 个并行 explore 摸地形。无 fallback，没 GPT 权限直接用不了。</li></ul><ul class="notion-list notion-list-disc notion-block-e52eb02e61084d32825fa35dc5e12aef"><li><b>Oracle</b>：只读的架构顾问。不动代码，只在关键决策、反复失败、安全性问题时提问。</li></ul><ul class="notion-list notion-list-disc notion-block-3583217e6ed84f978ec56be43f93891a"><li><b>Momus</b>：毒舌评审。针对<b>Prometheus的计划</b>只给「<b>通过</b>」或「<b>打回</b>」两种分，工具权限被砍到只剩 review。</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-335f591ad5264ac19f1433eb51edbcf6" data-id="335f591ad5264ac19f1433eb51edbcf6"><span><div id="335f591ad5264ac19f1433eb51edbcf6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#335f591ad5264ac19f1433eb51edbcf6" title="Group 4：Utility Runners（工具层）"><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">Group 4：Utility Runners（工具层）</span></span></h3><div class="notion-text notion-block-e038d1c6b4134d80ae9c4139ba0054cf">打工仔小队，<b>务必选速度快、成本低</b>的模型。</div><ul class="notion-list notion-list-disc notion-block-120f89d3f8ac47c08ca7abfd15b8ebc2"><li><b>Explore</b>：代码搜索</li></ul><ul class="notion-list notion-list-disc notion-block-f504bb1057384a2da76ed3bac08e1404"><li><b>Librarian</b>：外部文档与 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://Grep.app">Grep.app</a> 检索</li></ul><ul class="notion-list notion-list-disc notion-block-54a7d60a2fc14661a27adfe8be634d41"><li><b>Multimodal Looker</b>：截图 / PDF 视觉分享</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-c714474568574f108bbae23a13a5b33e" data-id="c714474568574f108bbae23a13a5b33e"><span><div id="c714474568574f108bbae23a13a5b33e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c714474568574f108bbae23a13a5b33e" title="Dynamic：Sisyphus-Junior"><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">Dynamic：Sisyphus-Junior</span></span></h3><div class="notion-text notion-block-bc860460baa44c2998b165a750fe16f8">动态生成的子包工队队长。当 Sisyphus 遇到需要专科能力的子任务时，会“招幕”一个 Junior（专业模型由Category决定），把该任务包给它去带小分队搞定。</div><div class="notion-blank notion-block-3eea159c074b4b98b37a3436c754f9f2"> </div><hr class="notion-hr notion-block-592992d85bf640e2827210d238ce842c"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-54cb15e2dcd84ea3a32bd95dcba2e0dd" data-id="54cb15e2dcd84ea3a32bd95dcba2e0dd"><span><div id="54cb15e2dcd84ea3a32bd95dcba2e0dd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#54cb15e2dcd84ea3a32bd95dcba2e0dd" title="Category 路由：把模型选择藏起来"><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">Category 路由：把模型选择藏起来</span></span></h2><div class="notion-text notion-block-0d83640166764a229c151787d86317d7">这是 omo 最值得抄的抽象。<b>你给它一个任务类别，它给你最适合的模型</b>。</div><table class="notion-simple-table notion-block-c7379af383ab48c58083ba23b0b8001a"><tbody><tr class="notion-simple-table-row notion-simple-table-header-row notion-block-df26662c9f9341909e7d7cdbb16bd8a6"><td class="" style="width:120px"><div class="notion-simple-table-cell">类别</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">适用场景</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">默认模型</div></td></tr><tr class="notion-simple-table-row notion-block-c82fb90446b042099574491fadf1a209"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">visual-engineering</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">前端 / UI / CSS / 视觉设计</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Gemini 3.1 Pro</div></td></tr><tr class="notion-simple-table-row notion-block-5718c079acff43f7bc3ff9ef7723d89f"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">artistry</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">创意方案、探索性设计</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Gemini / Claude Opus</div></td></tr><tr class="notion-simple-table-row notion-block-b2ec1cebe28b4a9b9e6c65a670a1baa4"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">ultrabrain</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">架构决策、硬逻辑</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">GPT-5.4 xhigh</div></td></tr><tr class="notion-simple-table-row notion-block-866893b15df44ddc88435d71d2f7c276"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">deep</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">多文件复杂编码</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">GPT-5.3 Codex</div></td></tr><tr class="notion-simple-table-row notion-block-1100d0539b2e4873ad3d619e4b75fa26"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">quick</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">单文件、简单任务</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Claude Haiku / Gemini Flash</div></td></tr><tr class="notion-simple-table-row notion-block-6a0ff8ac431740c79be5feef9f6b47c9"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">writing</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">文档 / 文案</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Gemini Flash / Claude Sonnet</div></td></tr><tr class="notion-simple-table-row notion-block-b7e5c8aada1546cfaae7b60c6443fb70"><td class="" style="width:120px"><div class="notion-simple-table-cell"><code class="notion-inline-code">unspecified-low</code> / <code class="notion-inline-code">-high</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">一般任务兼底</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">默认级联模型</div></td></tr></tbody></table><div class="notion-text notion-block-886de91de5154c14b23084a204f07ec4">配置文件（<code class="notion-inline-code">oh-my-openagent.json</code>）示例：</div><div class="notion-blank notion-block-17246df0bc2f43ae8c9bd8c0831ff896"> </div><hr class="notion-hr notion-block-d13c1f6330834191b5791b5003dcf75c"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-5efb6b6dd4f24184bc9b09757d21523c" data-id="5efb6b6dd4f24184bc9b09757d21523c"><span><div id="5efb6b6dd4f24184bc9b09757d21523c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5efb6b6dd4f24184bc9b09757d21523c" 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-d76b067f9408484a81685f15b79b988a">作者在 prompt 工程上下了远比普通 agent 框架多的功夫。下面的每个细节我都尽量贴上<b>官方仓库里的原文片段</b>。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0139fb1cc08e406680ef021fccfbfd79" data-id="0139fb1cc08e406680ef021fccfbfd79"><span><div id="0139fb1cc08e406680ef021fccfbfd79" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0139fb1cc08e406680ef021fccfbfd79" 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-7cefb03d3ffe48efb6245084cab872b1">前面说过了：同一个 agent，帮不同家族写不同版本的 prompt。<b>这是整个 omo 的前提假设</b>。这一点在代码里体现得非常直接——以 Prometheus 为例，源文件 <code class="notion-inline-code">src/agents/prometheus/system-prompt.ts</code> 中根据模型动态选 prompt：</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-d4fea04308614764a0be6da5240b3b72" data-id="d4fea04308614764a0be6da5240b3b72"><span><div id="d4fea04308614764a0be6da5240b3b72" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d4fea04308614764a0be6da5240b3b72" title="模块化组装：Prometheus 的「六段式」"><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">模块化组装：Prometheus 的「六段式」</span></span></h3><div class="notion-text notion-block-babd2785e25147eabc342cc843602f37">Prometheus 把一份战略规划 prompt 拆成<b>六个互相独立的模块</b>拼起来：</div><div class="notion-text notion-block-0bf67f7dbccf4d1bbac0b3ae2554fb60">这种写法的好处是<b>单点可改</b>：嫌计划模板太啰嗦，就只动 <code class="notion-inline-code">plan-template.ts</code>；想给 Interview 加一条「必须确认数据库迁移策略」，就只动 <code class="notion-inline-code">interview-mode.ts</code>。不会一碰牵动整个 prompt。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-98b75ad412504ec299811168076684a6" data-id="98b75ad412504ec299811168076684a6"><span><div id="98b75ad412504ec299811168076684a6" class="notion-header-anchor"></div><a class="notion-hash-link" href="#98b75ad412504ec299811168076684a6" title="Hephaestus 的「给目标不给菜谱」"><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">Hephaestus 的「给目标不给菜谱」</span></span></h3><div class="notion-text notion-block-a6698352c1884079a573b5af1024eae1">GPT 系模型喜欢<b>原则驱动</b>——你给它标准，它自己想办法。Hephaestus 的 prompt 风格就是这样，下面这段是 <code class="notion-inline-code">src/agents/hephaestus/gpt.ts</code> 的原文开头：</div><div class="notion-text notion-block-cc5f619e5801458482c0ea0a11e5c2fc">然后它用一段非常硬核的「<b>Do NOT Ask - Just Do</b>」把 GPT 的摇摆倾向直接摁死：</div><div class="notion-text notion-block-b261653844cc479faa00d84ed15a5692">最关键的执行闭环写得非常干脆：</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5bf0aba325ee4bacac6815bf37db5a80" data-id="5bf0aba325ee4bacac6815bf37db5a80"><span><div id="5bf0aba325ee4bacac6815bf37db5a80" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5bf0aba325ee4bacac6815bf37db5a80" title="Intent Gate：让意图先行"><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">Intent Gate：让意图先行</span></span></h3><div class="notion-text notion-block-ba27bf83502c4bb98a7120f84c2f031c">在所有执行层之上加一层<b>意图分类器</b>，避免 agent 解错题。你说「看一下这段代码」，它不会直接给你改代码。在 Hephaestus 的 prompt 里，这一段叫 <b>Phase 0</b>：</div><div class="notion-text notion-block-382a7487ac63423b9f893330509937b4">Sisyphus 作为总调度也有对应的四阶段：<b>Intent Gate → Codebase Assessment → Smart Delegation → Independent Verification（受限于篇幅这里就不介绍了）</b>。两层 Intent Gate 叠加，基本能把误解的概率压到很低。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-85f33eae1e3d4d919cf2665f87f5a66a" data-id="85f33eae1e3d4d919cf2665f87f5a66a"><span><div id="85f33eae1e3d4d919cf2665f87f5a66a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#85f33eae1e3d4d919cf2665f87f5a66a" title="纪律 hooks：用程序替 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">纪律 hooks：用程序替 AI 自律</span></span></h3><div class="notion-text notion-block-ed6d31c4331a4212916cf163aa281e3d">prompt 再严，也顶不住模型自己「走神」。omo 干脆用外部程序兜底：</div><ul class="notion-list notion-list-disc notion-block-25c1a0d81a1541e086fe1ee2252fc1d7"><li><b>Todo 强制器</b>：走神的 agent 被拉回待办队列；Hephaestus 的 prompt 里直接放了一整段 <code class="notion-inline-code">${todoDiscipline}</code> 占位符，运行时注入待办纪律规则</li></ul><ul class="notion-list notion-list-disc notion-block-72781ec0e0714e90a37f597c0b7c8ebf"><li><b>Comment Checker</b>：AI 生成的废话注释自动删除</li></ul><ul class="notion-list notion-list-disc notion-block-88e8850dc1b34612a9815985a9a98c0e"><li><b>Ralph Loop</b>：任务不到 100% 完成不让收工，对应 prompt 原文是那句 <b>&quot;100% OR NOTHING&quot;</b></li></ul><ul class="notion-list notion-list-disc notion-block-9a3f645b047b439eb88caf04b5ea0980"><li><b>Prometheus md-only hook</b>：Prometheus 只能写 <code class="notion-inline-code">.md</code> 计划文件，写代码直接被 hook 拦截——保证规划师<b>只规划不动手</b></li></ul><div class="notion-callout notion-purple_background_co notion-block-083549b4bfe34e5ea19499c62f5612a9"><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-db12ba1a4ed4446bbb5a6cf477fb84c0">想看更多原文？直接读：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/code-yeongyu/oh-my-openagent/blob/dev/src/agents/prometheus/system-prompt.ts">src/agents/prometheus/system-prompt.ts</a> 和 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/code-yeongyu/oh-my-openagent/blob/dev/src/agents/hephaestus/gpt.ts">src/agents/hephaestus/gpt.ts</a>。每个 agent 文件夹下都有 <code class="notion-inline-code">system-prompt.ts</code> + 若干模块文件，结构非常清晰。</div></div></div><div class="notion-blank notion-block-1874501047a04388ade261b04a96f368"> </div><hr class="notion-hr notion-block-40165458a63f4a579fa211b17f02b372"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-7f8f2c90a0774e3c80abc4b1ebc50569" data-id="7f8f2c90a0774e3c80abc4b1ebc50569"><span><div id="7f8f2c90a0774e3c80abc4b1ebc50569" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7f8f2c90a0774e3c80abc4b1ebc50569" 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><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2b064e1eb66b414fa35fc1593df6c236" data-id="2b064e1eb66b414fa35fc1593df6c236"><span><div id="2b064e1eb66b414fa35fc1593df6c236" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2b064e1eb66b414fa35fc1593df6c236" title="Ultrawork（ulw） — 一键闭环"><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">Ultrawork（<code class="notion-inline-code">ulw</code>） — 一键闭环</span></span></h3><div class="notion-text notion-block-964effa03ac845b9aca6284fad5b621e">键入三个字母 <code class="notion-inline-code"><b>ulw</b></code>，输入你的需求，去泡杯咖啡就行。</div><div class="notion-text notion-block-87761cf4a7d442408c7a8baa4ce2c96d"><b>适用场景</b>：任务边界清晰、但代码要改一堆地方。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-1390486c4b064aae814d62848fc33797" data-id="1390486c4b064aae814d62848fc33797"><span><div id="1390486c4b064aae814d62848fc33797" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1390486c4b064aae814d62848fc33797" title="Prometheus 模式 — 严谨版"><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">Prometheus 模式 — 严谨版</span></span></h3><div class="notion-text notion-block-9919d2abb26e4fa69a8b824665abd290">按 <b>Tab</b> 进入面谈模式：</div><ol start="1" class="notion-list notion-list-numbered notion-block-6eade88ae84045049bce7f6c4cf1dd4e" style="list-style-type:decimal"><li><b>Prometheus</b> 与你讨论需求、范围、验收标准</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-7372789681ab40f7ae0e1fff6843142c" style="list-style-type:decimal"><li><b>Metis</b> 问：漏了什么？</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-f39a32b347904f47b3a874ee6d37ece5" style="list-style-type:decimal"><li><b>Momus</b> 审计划：通过 or 打回</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-ae18eacaec7e497796d5d004f753afaf" style="list-style-type:decimal"><li>输入 <code class="notion-inline-code">/start-work</code></li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-e81c4d2cade74e69a29fbc4da507f89b" style="list-style-type:decimal"><li><b>Atlas</b> 接手拆 todo 并分派</li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-d7b65ca37ca949c3bc312c289c79aab8" style="list-style-type:decimal"><li><b>Boulder 系统</b>把进度写到 <code class="notion-inline-code">boulder.json</code>，<b>中间崩溃可以从原地续跑</b></li></ol><div class="notion-text notion-block-30dad67812fd42fabc528d38735f2be6"><b>适用场景</b>：多天才能搞完的项目、架构调整、生产变更、或希望留下决策记录的改动。由于实际模型效果受限于目前的上下文（超过200k效果会大打折扣），所以这种方式在我写下这段话的时候还不是很适用，有时候光计划写完就用掉100k了，需要新开一个窗口再按照计划进行，希望你读到这段话的时候模型已经不局限于200k上下文以下的最佳效果。</div><div class="notion-blank notion-block-04b3595231874fa29e75c65adaefd4c3"> </div><hr class="notion-hr notion-block-5f27e5583e174bf5be7ddfc35cfc1cb0"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-492cdd3a08c24e9193f3c6fdc4cfdd3e" data-id="492cdd3a08c24e9193f3c6fdc4cfdd3e"><span><div id="492cdd3a08c24e9193f3c6fdc4cfdd3e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#492cdd3a08c24e9193f3c6fdc4cfdd3e" 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><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-2b79e54f55d940238fb2b07108b641ca" data-id="2b79e54f55d940238fb2b07108b641ca"><span><div id="2b79e54f55d940238fb2b07108b641ca" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2b79e54f55d940238fb2b07108b641ca" 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><ul class="notion-list notion-list-disc notion-block-874f0045d8f64213b087159ae6dad1e1"><li><b>天生并行</b>。主流的agent开发基本还是串行，omo 可以同时起好几个 background agent，一个写代码、一个查文档、一个跑验证。大改动场景体感差别巨大。</li></ul><ul class="notion-list notion-list-disc notion-block-9b31dbf456774d0498b24a2a94a45584"><li><b>任务↔模型 自动匹配</b>。前端自动走 Gemini、架构自动走 GPT、琐事自动走 Haiku，用户不用管。</li></ul><ul class="notion-list notion-list-disc notion-block-fb5b194637154e3c9b20d465e240c86c"><li><b>Hashline 的编辑稳定性</b>。弱模型也能稳稳改代码，edit 失败率断崖下降。</li></ul><ul class="notion-list notion-list-disc notion-block-a92f967b6a1243e4a1143370ba01840c"><li><b>IDE 级能力</b>。LSP + AST 内置，workspace rename、go-to-definition、find-references、构建前诊断全部可用，原生 Claude Code 做不到。</li></ul><ul class="notion-list notion-list-disc notion-block-61edc053989e4873b53486020e3a7cc2"><li><b>不绑厂商</b>。Anthropic 下架、OpenAI 限流、Gemini 涨价？换底层就行，workflow 一行代码不用改。</li></ul><ul class="notion-list notion-list-disc notion-block-bd521779d7cf477eb9f7c22c4c4014ab"><li><b>Boulder 断点续跑</b>。会话崩了、电脑重启了、大动作做到一半注意力断了？没关系，<code class="notion-inline-code">boulder.json</code>为你记着。</li></ul><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-86ae7f001ea64e94b37083d2d300743a" data-id="86ae7f001ea64e94b37083d2d300743a"><span><div id="86ae7f001ea64e94b37083d2d300743a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#86ae7f001ea64e94b37083d2d300743a" 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><ul class="notion-list notion-list-disc notion-block-77cb285a2abc42408f9f942cbe7f4957"><li><b>学习曲线陡</b>。agent / category / skill / hook 这些概念得先理解一波，虽然不理解也能使用，作者已经把门槛降到最低。</li></ul><ul class="notion-list notion-list-disc notion-block-f8e7baca38534974ba0736d662b9a544"><li><b>默认成本不低</b>。尽管subagent的理想设计下token的消耗是比正常效果低的，但是正如我所说—omo太“重”了，在同等任务下它的花费比正常高30%左右（体感上），至于效果？因人而异了，所以我并不推荐每个人都去使用它。</li></ul><ul class="notion-list notion-list-disc notion-block-738c6f4fb8804e4596835911cebd4080"><li><b>Hephaestus 与 GPT 强绑定</b>。没 OpenAI / GitHub Copilot 就用不了，本地模型目前顶不上。</li></ul><ul class="notion-list notion-list-disc notion-block-187125a923734b1a9448ac589a1d0ca2"><li><b>prompt 与模型家族高度耦合</b>。不要随手乱换模型，换错了质量会断崖下降，先尊重默认配置再谈定制。</li></ul><div class="notion-blank notion-block-47a2a6c1f6b74522b75ea82de33effb6"> </div><hr class="notion-hr notion-block-c7dff511549f46efb0bd393a3ed6ace2"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-398a3da3e41041a1a7afe637312ba0f7" data-id="398a3da3e41041a1a7afe637312ba0f7"><span><div id="398a3da3e41041a1a7afe637312ba0f7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#398a3da3e41041a1a7afe637312ba0f7" 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-e0b2e218246846739b937d3685b92c9e">对我而言，尽管omo在有些情况下太“重”，甚至token的花销也不小，但是我已经无法再抛下它，subagent的优雅只有用过的人才能真切体会。同时 <b>omo</b> 给我带来的最大冲击不是某个具体功能，而是它让我重新思考了 <b>AI coding 的未来形态：</b></div><blockquote class="notion-quote notion-default notion-block-de33fc71f2d34d9bb86a851007df8dc3"><div><b>一个人 + 一个超强模型搞定一切？或许不是。
一支各有所长、互相 review、自我纠错的 agent 团队？可能更接近工程团队本来的样子。</b></div></blockquote><div class="notion-text notion-block-348d690ad6d18071b219dc1ddb83fd63">omo 在这条路上已经走得挺远。如果你在用 OpenCode，<b>强烈建议花 10 分钟装一下试试</b>——不喜欢也能随时卸。下面贴一段作者的原话，或许有些嚣张，但我很喜欢：</div><hr class="notion-hr notion-block-46123e90acb64219b18d6e48c3ea3a54"/><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-87cf2ae0266345d4bacea25c18964860" data-id="87cf2ae0266345d4bacea25c18964860"><span><div id="87cf2ae0266345d4bacea25c18964860" class="notion-header-anchor"></div><a class="notion-hash-link" href="#87cf2ae0266345d4bacea25c18964860" 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-348d690ad6d1807685fed29fc53287ba"><li>📂 项目仓库：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/code-yeongyu/oh-my-openagent">code-yeongyu/oh-my-openagent</a></li></ul><ul class="notion-list notion-list-disc notion-block-348d690ad6d18064a693d4775e262740"><li>🌐 官方站点：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://ohmyopenagent.com">ohmyopenagent.com</a></li></ul><ul class="notion-list notion-list-disc notion-block-348d690ad6d18012894dd17eba7b669b"><li>📖 官方文档：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://ohmyopenagent.com/docs">Oh My OpenAgent Docs</a></li></ul><ul class="notion-list notion-list-disc notion-block-348d690ad6d18032b1efc692b7b5fc79"><li>📜 Overview 源文档：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/code-yeongyu/oh-my-openagent/blob/dev/docs/guide/overview.md">docs/guide/</a><a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://overview.md">overview.md</a></li></ul><ul class="notion-list notion-list-disc notion-block-348d690ad6d180ac9e10d583fc22410a"><li>🔬 深度评测：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.glukhov.org/ai-devtools/opencode/oh-my-opencode-agents/">Rost Glukhov – Oh My Opencode Specialised Agents Deep Dive</a></li></ul></main></div>]]></content:encoded>
        </item>
        <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>
    </channel>
</rss>