{"id":101694,"date":"2026-09-07T08:41:07","date_gmt":"2026-09-07T00:41:07","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/101694.html"},"modified":"2026-09-07T08:41:07","modified_gmt":"2026-09-07T00:41:07","slug":"agent-%e8%ae%b0%e5%bf%86%e4%bc%9a%e6%bb%a1%e5%90%97%ef%bc%9f%e9%87%8d%e8%a6%81%e6%80%a7x%e6%97%b6%e6%95%88%e6%80%a7x%e7%99%bd%e5%90%8d%e5%8d%95%ef%bc%8c%e7%bb%99%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/101694.html","title":{"rendered":"Agent \u8bb0\u5fc6\u4f1a\u201c\u6ee1\u201c\u5417\uff1f\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355\uff0c\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7"},"content":{"rendered":"<h2>Agent \u8bb0\u5fc6\u4f1a&#034;\u6ee1&#034;\u5417&#xff1f;\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355&#xff0c;\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7<\/h2>\n<p>\u672c\u6587\u662f\u300cAgent \u5e94\u7528\u5f00\u53d1\u5de5\u7a0b\u5e08\u300d\u7cfb\u5217\u7b2c\u2464\u7bc7 \u00b7 \u4e0a\u4e0b\u6587\u662f\u9884\u7b97&#xff0c;\u7f13\u5b58\u662f\u7b2c\u4e00\u5200&#xff0c;\u8bb0\u5fc6\u6dd8\u6c70\u662f\u7b2c\u4e8c\u5200\u2014\u2014\u628a\u6700\u503c\u5f97\u8bb0\u4f4f\u7684\u7559\u4e0b\u3002<\/p>\n<hr \/>\n<p>\u26a1 TL;DR \u00b7 \u5148\u770b\u7ed3\u8bba<\/p>\n<ul>\n<li>Agent \u8bb0\u5fc6\u4e0d\u662f\u65e0\u9650\u4ed3\u5e93&#xff0c;\u4e0a\u4e0b\u6587\u7a97\u53e3\u6ee1\u4e86\u5c31\u5f97\u6dd8\u6c70&#xff0c;\u6dd8\u6c70\u4e0d\u80fd\u9760&#034;\u5148\u8fdb\u5148\u51fa&#034;\u2014\u2014\u91cd\u8981\u8bb0\u5fc6\u521a\u8bf4\u5b8c\u5c31\u88ab\u6254\u4e86\u3002<\/li>\n<li>\u672c\u6587\u7ed9\u51fa\u4e00\u4e2a\u4e09\u7ef4\u8bc4\u5206\u516c\u5f0f&#xff1a;score &#061; importance \u00d7 recency \u00d7 whitelist&#xff0c;\u7528 Redis \u6709\u5e8f\u96c6\u5408&#xff08;Sorted Set&#xff09;\u505a\u4f18\u5148\u7ea7\u6dd8\u6c70\u3002<\/li>\n<li>\u767d\u540d\u5355\u673a\u5236\u4fdd\u62a4\u5173\u952e\u8bb0\u5fc6\u4e0d\u88ab\u8bef\u6740&#xff1b;TTL &#043; \u51b7\u70ed\u5206\u5c42\u9632\u6b62&#034;\u521a\u8bb0\u4f4f\u5c31\u88ab\u6254&#034;\u3002<\/li>\n<li>\u6240\u6709\u6743\u91cd\/\u9608\u503c\u90fd\u662f\u9aa8\u67b6&#xff0c;\u5f97\u4f60\u81ea\u5df1\u6309\u573a\u666f\u8c03\u53c2&#xff0c;\u522b\u5199\u6b7b&#034;\u6700\u4f73\u503c&#034;\u3002<\/li>\n<\/ul>\n<hr \/>\n<p>\u524d\u4e24\u7bc7\u6211\u4eec\u8bb2\u4e86&#034;\u9884\u7b97&#034;&#xff08;Context Engineering&#xff09;\u548c&#034;\u7f13\u5b58&#034;&#xff08;Prompt Caching&#xff09;\u3002\u8fd9\u4e00\u7bc7\u63a5\u7740\u8bb2\u9884\u7b97\u7684\u53e6\u4e00\u534a\u2014\u2014\u8bb0\u5fc6\u6dd8\u6c70\u3002<\/p>\n<p>Cache \u7ba1\u7684\u662f&#034;\u7cfb\u7edf\u63d0\u793a\u548c\u5de5\u5177\u5b9a\u4e49\u53cd\u590d\u7b97&#034;&#xff0c;Memory \u7ba1\u7684\u662f&#034;\u7528\u6237\u8bf4\u4e86\u4ec0\u4e48\u3001Agent \u53d1\u73b0\u8fc7\u4ec0\u4e48&#034;\u3002\u4f46\u7a97\u53e3\u5c31\u90a3\u4e48\u5927&#xff0c;\u6ee1\u4e86\u4e4b\u540e\u6254\u4ec0\u4e48&#xff0c;\u6bd4&#034;\u7528\u4ec0\u4e48\u65b9\u5f0f\u5b58&#034;\u66f4\u503c\u5f97\u60f3\u6e05\u695a\u3002<\/p>\n<p>\u8fd9\u7bc7\u4e0d\u8bb2&#034;\u600e\u4e48\u7528\u5411\u91cf\u5e93\u5b58\u4f4f\u6240\u6709\u8bb0\u5fc6&#034;\u2014\u2014\u90a3\u662f\u5b58\u50a8\u5c42\u7684\u4e8b\u3002\u6211\u4eec\u8bb2\u6ee1\u4e86\u4e4b\u540e\u600e\u4e48\u6254&#xff1a;\u4e09\u7ef4\u8bc4\u5206\u516c\u5f0f\u3001Redis \u6392\u5e8f\u96c6\u5b9e\u73b0\u3001\u767d\u540d\u5355\u4fdd\u62a4\u3001\u51b7\u70ed\u5206\u5c42&#xff0c;\u4ee5\u53ca\u8c03\u53c2\u4e0d\u8be5\u8e29\u7684\u5751\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u5148\u7acb\u6807\u51c6&#xff1a;\u4e3a\u4ec0\u4e48&#034;\u5148\u8fdb\u5148\u51fa&#034;\u4e0d\u9002\u5408 Agent<\/h3>\n<p>\u5148\u8fdb\u5148\u51fa&#xff08;FIFO&#xff09;\u662f\u6700\u7b80\u5355\u7684\u6dd8\u6c70\u7b56\u7565\u2014\u2014\u8c01\u5148\u6765\u8c01\u5148\u8d70\u3002\u4f46\u5728 Agent \u573a\u666f\u91cc&#xff0c;\u5b83\u5927\u6982\u7387\u4f1a\u505a\u9519\u4e8b&#xff1a;<\/p>\n<ul>\n<li>\u7528\u6237\u521a\u8bf4\u4e86\u4e00\u53e5&#034;\u6211\u7684\u9879\u76ee\u5bc6\u7801\u662f XXXX&#034;&#xff0c;FIFO \u53ef\u80fd\u56e0\u4e3a\u524d\u9762\u6392\u4e86\u592a\u591a\u8f6e\u5bf9\u8bdd&#xff0c;\u76f4\u63a5\u628a\u5b83\u6324\u51fa\u53bb\u3002\u4e0b\u6b21 Agent \u5c31\u5fd8\u4e86\u5bc6\u7801\u3002<\/li>\n<li>Agent \u521a\u53d1\u73b0\u4e86\u4e00\u4e2a\u5173\u952e\u5de5\u5177\u8c03\u7528\u7ed3\u679c&#xff0c;FIFO \u53ef\u80fd\u56e0\u4e3a\u8fd9\u6761\u6d88\u606f\u5728\u7a97\u53e3\u91cc\u4f4d\u7f6e\u9760\u524d&#xff0c;\u4f18\u5148\u6dd8\u6c70\u5b83\u3002<\/li>\n<\/ul>\n<p>\u6240\u4ee5 Agent \u8bb0\u5fc6\u6dd8\u6c70\u9700\u8981\u6309&#034;\u4ef7\u503c&#034;\u6392\u4f18\u5148\u7ea7&#xff0c;\u800c\u4e0d\u662f\u6309\u65f6\u95f4\u987a\u5e8f\u3002<\/p>\n<p>&#x1f4a1; \u4e00\u4e2a\u53cd\u76f4\u89c9\u7684\u4e8b\u5b9e&#xff1a;\u957f\u5bf9\u8bdd\u91cc&#xff0c;\u6700\u91cd\u8981\u7684\u4fe1\u606f\u5f80\u5f80\u51fa\u73b0\u5728\u4e2d\u95f4\u2014\u2014\u65e2\u4e0d\u662f\u6700\u65e9&#xff08;\u5f00\u573a\u5bd2\u6684&#xff09;&#xff0c;\u4e5f\u4e0d\u662f\u6700\u665a&#xff08;\u5f53\u524d\u95ee\u9898&#xff09;\u3002FIFO \u548c LRU \u5728\u8fd9\u79cd\u573a\u666f\u4e0b\u90fd\u4e0d\u597d\u7528\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u4e09\u7ef4\u8bc4\u5206\u516c\u5f0f&#xff1a;\u91cd\u8981\u6027 \u00d7 \u65f6\u6548\u6027 \u00d7 \u767d\u540d\u5355<\/h3>\n<p>\u4e00\u4e2a\u53ef\u843d\u5730\u7684\u65b9\u6848\u662f\u7ed9\u6bcf\u6761\u8bb0\u5fc6\u6253\u4e00\u4e2a\u7efc\u5408\u5206&#xff0c;\u6309\u5206\u6dd8\u6c70\u2014\u2014\u5206\u6700\u4f4e\u7684\u5148\u8d70\u3002<\/p>\n<p>score &#061; importance \u00d7 recency_weight \u00d7 whitelist_boost<\/p>\n<table>\n<tr>\u7ef4\u5ea6\u542b\u4e49\u8bc4\u5206\u601d\u8def<\/tr>\n<tbody>\n<tr>\n<td>\u91cd\u8981\u6027 (importance)<\/td>\n<td>\u8fd9\u6761\u8bb0\u5fc6&#034;\u503c\u591a\u5c11\u94b1&#034;<\/td>\n<td>\u7528\u6237\u660e\u786e\u6807\u6ce8\u7684&#xff08;\u201c\u8bb0\u4f4f\u8fd9\u4e2a\u201d&#xff09;\u3001\u5de5\u5177\u8fd4\u56de\u7684\u9519\u8bef\/\u544a\u8b66\u3001\u6d89\u53ca\u5b89\u5168\/\u914d\u7f6e\u7684\u4fe1\u606f \u2192 \u9ad8\u5206&#xff1b;\u65e5\u5e38\u95f2\u804a \u2192 \u4f4e\u5206<\/td>\n<\/tr>\n<tr>\n<td>\u65f6\u6548\u6027 (recency)<\/td>\n<td>\u8fd9\u6761\u8bb0\u5fc6&#034;\u591a\u65b0\u9c9c&#034;<\/td>\n<td>\u521a\u53d1\u751f\u7684 \u2192 \u5206\u9ad8&#xff1b;\u534a\u5c0f\u65f6\u524d\u7684 \u2192 \u5206\u9010\u6e10\u964d\u4f4e\u3002\u53ef\u7528\u6307\u6570\u8870\u51cf weight &#061; e^(-\u03bb\u00b7\u0394t)<\/td>\n<\/tr>\n<tr>\n<td>\u767d\u540d\u5355 (whitelist)<\/td>\n<td>\u8fd9\u6761\u8bb0\u5fc6&#034;\u80fd\u4e0d\u80fd\u78b0&#034;<\/td>\n<td>\u767d\u540d\u5355\u5185\u7684 \u2192 \u4e58\u4e00\u4e2a\u5927\u7cfb\u6570&#xff08;\u5982 10&#xff09;&#xff0c;\u6c38\u4e0d\u6dd8\u6c70&#xff1b;\u4e0d\u5728\u767d\u540d\u5355 \u2192 \u4e58 1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u2696\ufe0f \u6743\u91cd\u4e0d\u8bf4\u6b7b&#xff1a;\u03bb&#xff08;\u8870\u51cf\u7cfb\u6570&#xff09;\u3001importance \u5206\u6863\u3001whitelist \u4e58\u6570\u2014\u2014\u5168\u90fd\u5f97\u6309\u4f60\u7684\u573a\u666f\u8c03\u3002\u6b63\u6587\u7ed9\u516c\u5f0f\u548c\u601d\u8def&#xff0c;\u4e0d\u7ed9&#034;\u6700\u4f73\u503c&#034;\u3002<\/p>\n<h4>\u91cd\u8981\u6027\u5206\u6863&#xff08;\u793a\u4f8b&#xff0c;\u975e\u56fa\u5b9a&#xff09;<\/h4>\n<table>\n<tr>\u7c7b\u522b\u5206\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u7528\u6237\u660e\u786e\u6307\u4ee4\/\u914d\u7f6e<\/td>\n<td>10<\/td>\n<td>\u201c\u8bb0\u4f4f\u8fd9\u4e2a\u5bc6\u7801\u201d\u201c\u628a\u8fd9\u6761\u89c4\u5219\u8bb0\u4e0b\u6765\u201d<\/td>\n<\/tr>\n<tr>\n<td>\u5de5\u5177\u8fd4\u56de\u9519\u8bef\/\u544a\u8b66<\/td>\n<td>8<\/td>\n<td>API \u8c03\u7528\u5931\u8d25\u3001\u6743\u9650\u4e0d\u8db3<\/td>\n<\/tr>\n<tr>\n<td>\u5173\u952e\u4e1a\u52a1\u6570\u636e<\/td>\n<td>7<\/td>\n<td>\u8ba2\u5355\u53f7\u3001\u9879\u76ee ID\u3001\u914d\u7f6e\u9879<\/td>\n<\/tr>\n<tr>\n<td>Agent \u53d1\u73b0\u7684\u91cd\u8981\u7ed3\u8bba<\/td>\n<td>5<\/td>\n<td>\u7ecf\u8fc7\u63a8\u7406\u5f97\u51fa\u7684\u4e8b\u5b9e<\/td>\n<\/tr>\n<tr>\n<td>\u4e00\u822c\u5bf9\u8bdd\u4e0a\u4e0b\u6587<\/td>\n<td>3<\/td>\n<td>\u65e5\u5e38\u95ee\u7b54<\/td>\n<\/tr>\n<tr>\n<td>\u95ee\u5019\/\u95f2\u804a<\/td>\n<td>1<\/td>\n<td>\u5f00\u573a\u767d\u3001\u5bd2\u6684<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e09\u3001\u7528 Redis \u6709\u5e8f\u96c6\u5408\u505a\u4f18\u5148\u7ea7\u6dd8\u6c70<\/h3>\n<p>Redis \u7684 Sorted Set&#xff08;\u6709\u5e8f\u96c6\u5408&#xff09; \u5929\u7136\u9002\u5408\u8fd9\u4e2a\u573a\u666f&#xff1a;ZADD \u628a\u8bb0\u5fc6 ID \u548c score \u5199\u8fdb\u53bb&#xff0c;ZRANK \u67e5\u6392\u540d&#xff0c;ZREMRANGEBYSCORE \u6309\u5206\u6dd8\u6c70\u2014\u2014\u4e0d\u5b58\u5728&#034;\u904d\u5386\u6240\u6709\u8bb0\u5fc6\u627e\u6700\u4e0d\u91cd\u8981\u7684&#034;\u3002<\/p>\n<p><span class=\"token comment\"># \u26a0\ufe0f \u9aa8\u67b6\u793a\u4f8b&#xff1a;Redis \u6392\u5e8f\u96c6\u505a\u8bb0\u5fc6\u6dd8\u6c70&#xff0c;\u4ee5\u4f60\u5b9e\u9645 Redis \u7248\u672c\u4e3a\u51c6<\/span><br \/>\n<span class=\"token keyword\">import<\/span> redis<span class=\"token punctuation\">,<\/span> time<span class=\"token punctuation\">,<\/span> json<\/p>\n<p>r <span class=\"token operator\">&#061;<\/span> redis<span class=\"token punctuation\">.<\/span>Redis<span class=\"token punctuation\">(<\/span>host<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;localhost&#034;<\/span><span class=\"token punctuation\">,<\/span> port<span class=\"token operator\">&#061;<\/span><span class=\"token number\">6379<\/span><span class=\"token punctuation\">,<\/span> db<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\nMEMORY_KEY <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;agent:memory:priority&#034;<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">remember<\/span><span class=\"token punctuation\">(<\/span>memory_id<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> importance<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">float<\/span><span class=\"token punctuation\">,<\/span> is_whitelisted<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">bool<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">False<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u5199\u5165\u4e00\u6761\u8bb0\u5fc6\u53ca\u5176\u8bc4\u5206&#034;&#034;&#034;<\/span><br \/>\n    recency <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1.0<\/span>  <span class=\"token comment\"># \u521a\u53d1\u751f\u7684&#xff0c;\u65f6\u6548\u6027\u6ee1\u5206<\/span><br \/>\n    whitelist <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">10.0<\/span> <span class=\"token keyword\">if<\/span> is_whitelisted <span class=\"token keyword\">else<\/span> <span class=\"token number\">1.0<\/span><br \/>\n    score <span class=\"token operator\">&#061;<\/span> importance <span class=\"token operator\">*<\/span> recency <span class=\"token operator\">*<\/span> whitelist<br \/>\n    r<span class=\"token punctuation\">.<\/span>zadd<span class=\"token punctuation\">(<\/span>MEMORY_KEY<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span>memory_id<span class=\"token punctuation\">:<\/span> score<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">decay_memories<\/span><span class=\"token punctuation\">(<\/span>decay_rate<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">float<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0.95<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u7ed9\u6240\u6709\u8bb0\u5fc6\u7684\u65f6\u6548\u6027\u4e58\u4e00\u4e2a\u8870\u51cf\u7cfb\u6570&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> mem_id <span class=\"token keyword\">in<\/span> r<span class=\"token punctuation\">.<\/span>zrange<span class=\"token punctuation\">(<\/span>MEMORY_KEY<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        mem_id <span class=\"token operator\">&#061;<\/span> mem_id<span class=\"token punctuation\">.<\/span>decode<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        current <span class=\"token operator\">&#061;<\/span> r<span class=\"token punctuation\">.<\/span>zscore<span class=\"token punctuation\">(<\/span>MEMORY_KEY<span class=\"token punctuation\">,<\/span> mem_id<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token comment\"># \u767d\u540d\u5355\u8bb0\u5fc6\u4e0d\u8870\u51cf<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> current <span class=\"token keyword\">and<\/span> current <span class=\"token operator\">&gt;&#061;<\/span> <span class=\"token number\">10.0<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">continue<\/span><br \/>\n        <span class=\"token comment\"># \u975e\u767d\u540d\u5355&#xff1a;\u65f6\u6548\u6027\u8870\u51cf<\/span><br \/>\n        new_score <span class=\"token operator\">&#061;<\/span> current <span class=\"token operator\">*<\/span> decay_rate <span class=\"token keyword\">if<\/span> current <span class=\"token keyword\">else<\/span> <span class=\"token number\">0<\/span><br \/>\n        r<span class=\"token punctuation\">.<\/span>zadd<span class=\"token punctuation\">(<\/span>MEMORY_KEY<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span>mem_id<span class=\"token punctuation\">:<\/span> new_score<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">evict_if_full<\/span><span class=\"token punctuation\">(<\/span>max_size<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">,<\/span> evict_count<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u5982\u679c\u8bb0\u5fc6\u8d85\u8fc7\u4e0a\u9650&#xff0c;\u6dd8\u6c70\u8bc4\u5206\u6700\u4f4e\u7684 evict_count \u6761&#034;&#034;&#034;<\/span><br \/>\n    current <span class=\"token operator\">&#061;<\/span> r<span class=\"token punctuation\">.<\/span>zcard<span class=\"token punctuation\">(<\/span>MEMORY_KEY<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> current <span class=\"token operator\">&gt;<\/span> max_size<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># \u6dd8\u6c70\u5206\u6700\u4f4e\u7684<\/span><br \/>\n        to_evict <span class=\"token operator\">&#061;<\/span> current <span class=\"token operator\">&#8211;<\/span> max_size <span class=\"token operator\">&#043;<\/span> evict_count<br \/>\n        <span class=\"token comment\"># \u627e\u5230\u6700\u4f4e\u5206\u7684\u8bb0\u5fc6<\/span><br \/>\n        lowest <span class=\"token operator\">&#061;<\/span> r<span class=\"token punctuation\">.<\/span>zrange<span class=\"token punctuation\">(<\/span>MEMORY_KEY<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> to_evict <span class=\"token operator\">&#8211;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token comment\"># \u5220\u9664\u5b83\u4eec<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> mem_id <span class=\"token keyword\">in<\/span> lowest<span class=\"token punctuation\">:<\/span><br \/>\n            r<span class=\"token punctuation\">.<\/span>zrem<span class=\"token punctuation\">(<\/span>MEMORY_KEY<span class=\"token punctuation\">,<\/span> mem_id<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Evicted <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span><span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>lowest<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> memories&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>&#x1f9ed; \u4e3a\u4ec0\u4e48\u7528 Sorted Set \u800c\u4e0d\u662f List&#xff1a;List \u53ea\u80fd\u6309\u63d2\u5165\u987a\u5e8f&#034;\u5148\u8fdb\u5148\u51fa&#034;&#xff0c;Sorted Set \u53ef\u4ee5\u6309\u5206\u6392\u5e8f&#xff0c;\u53d6\u6700\u4f4e\u5206\u3001\u6309\u8303\u56f4\u5220\u9664\u90fd\u662f O(log N)\u2014\u2014\u8fd9\u5728\u8bb0\u5fc6\u91cf\u5927\u7684\u65f6\u5019\u662f\u8d28\u7684\u533a\u522b\u3002<\/p>\n<h4>\u4e09\u4e2a\u8981\u547d\u7684\u8fb9\u754c<\/h4>\n<li>\u522b\u8ba9\u767d\u540d\u5355\u81a8\u80c0&#xff1a;\u767d\u540d\u5355\u8bb0\u5fc6\u4e0d\u4f1a\u88ab\u6dd8\u6c70&#xff0c;\u4e0d\u52a0\u63a7\u5236\u5c31\u4f1a\u628a\u7a97\u53e3\u585e\u6ee1\u3002\u5efa\u8bae\u8bbe\u767d\u540d\u5355\u4e0a\u9650&#xff08;\u6bd4\u5982 20 \u6761&#xff09;&#xff0c;\u8d85\u9650\u65f6\u6309 importance \u00d7 recency \u5728\u767d\u540d\u5355\u5185\u518d\u6392\u4e00\u6b21\u3002<\/li>\n<li>\u8870\u51cf\u9700\u8981\u5b9a\u65f6\u89e6\u53d1&#xff1a;decay_memories \u4e0d\u662f\u81ea\u52a8\u7684\u3002\u53ef\u4ee5\u653e\u5728\u6bcf\u6b21 remember() \u8c03\u7528\u65f6\u987a\u5e26\u6267\u884c&#xff0c;\u6216\u8005\u7528\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1&#xff08;\u5982 schedule \u5e93&#xff09;\u5468\u671f\u6027\u89e6\u53d1\u3002<\/li>\n<li>\u5206\u6570\u78b0\u649e&#xff1a;\u5982\u679c\u591a\u6761\u8bb0\u5fc6\u5206\u6570\u76f8\u540c&#xff0c;ZREMRANGEBYSCORE \u4f1a\u5168\u5220\u3002\u5efa\u8bae score \u52a0\u4e00\u4e2a\u5fae\u5c0f\u7684\u968f\u673a\u6270\u52a8&#xff08;importance * recency * whitelist &#043; random() * 0.001&#xff09;\u907f\u514d\u540c\u5206\u6279\u91cf\u8bef\u6740\u3002<\/li>\n<hr \/>\n<h3>\u56db\u3001\u767d\u540d\u5355\u673a\u5236&#xff1a;\u6709\u4e9b\u8bb0\u5fc6\u4e0d\u80fd\u88ab\u6dd8\u6c70<\/h3>\n<p>\u767d\u540d\u5355\u662f\u5173\u952e\u8bbe\u8ba1\u3002\u4e0d\u662f\u6240\u6709\u8bb0\u5fc6\u90fd\u8be5\u53c2\u4e0e\u6dd8\u6c70\u2014\u2014\u6709\u4e9b\u662f&#034;\u6b7b\u4e86\u4e5f\u4e0d\u80fd\u4e22&#034;\u7684&#xff1a;<\/p>\n<ul>\n<li>\u7528\u6237\u8eab\u4efd\u4fe1\u606f&#xff08;\u201c\u6211\u662f\u5f20\u4e09\u201d&#xff09;<\/li>\n<li>\u7cfb\u7edf\u914d\u7f6e\/\u504f\u597d&#xff08;\u201c\u7528\u4e2d\u6587\u56de\u590d\u201d&#xff09;<\/li>\n<li>\u5b89\u5168\u51ed\u8bc1&#xff08;\u201c\u6211\u7684 API key \u5728\u73af\u5883\u53d8\u91cf\u91cc\u201d&#xff09;<\/li>\n<li>\u957f\u4efb\u52a1\u4e0a\u4e0b\u6587&#xff08;\u201c\u6211\u4eec\u6b63\u5728\u5904\u7406\u8ba2\u5355 #12345\u201d&#xff09;<\/li>\n<\/ul>\n<p>\u5b9e\u73b0\u4e0a&#xff0c;\u8fd9\u4e9b\u8bb0\u5fc6\u7684 score \u88ab\u4e58\u4e00\u4e2a\u5927\u7cfb\u6570&#xff08;\u5982 10&#xff09;&#xff0c;\u8ba9\u5b83\u4eec\u6c38\u8fdc\u6392\u5728 Sorted Set \u7684\u9876\u7aef\u3002<\/p>\n<p><span class=\"token comment\"># \u26a0\ufe0f \u9aa8\u67b6\u793a\u4f8b&#xff1a;\u767d\u540d\u5355\u4fdd\u62a4\u903b\u8f91<\/span><br \/>\nWHITELIST_BOOST <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">10.0<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">remember_with_whitelist<\/span><span class=\"token punctuation\">(<\/span>memory_id<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> importance<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">float<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                            is_whitelisted<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">bool<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">False<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    whitelist <span class=\"token operator\">&#061;<\/span> WHITELIST_BOOST <span class=\"token keyword\">if<\/span> is_whitelisted <span class=\"token keyword\">else<\/span> <span class=\"token number\">1.0<\/span><br \/>\n    recency <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1.0<\/span><br \/>\n    score <span class=\"token operator\">&#061;<\/span> importance <span class=\"token operator\">*<\/span> recency <span class=\"token operator\">*<\/span> whitelist<\/p>\n<p>    <span class=\"token comment\"># \u5982\u679c\u662f\u767d\u540d\u5355&#xff0c;\u8bb0\u5f55\u767d\u540d\u5355\u5143\u6570\u636e\u5907\u7528<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> is_whitelisted<span class=\"token punctuation\">:<\/span><br \/>\n        r<span class=\"token punctuation\">.<\/span>hset<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;agent:memory:whitelist&#034;<\/span><span class=\"token punctuation\">,<\/span> memory_id<span class=\"token punctuation\">,<\/span> json<span class=\"token punctuation\">.<\/span>dumps<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#034;importance&#034;<\/span><span class=\"token punctuation\">:<\/span> importance<span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#034;created_at&#034;<\/span><span class=\"token punctuation\">:<\/span> time<span class=\"token punctuation\">.<\/span>time<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    r<span class=\"token punctuation\">.<\/span>zadd<span class=\"token punctuation\">(<\/span>MEMORY_KEY<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span>memory_id<span class=\"token punctuation\">:<\/span> score<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u26a0\ufe0f \u767d\u540d\u5355\u7684&#034;\u767d&#034;\u4e0d\u662f\u6c38\u4e45\u7684&#xff1a;\u7528\u6237\u53ef\u80fd\u6539\u4e3b\u610f&#xff08;\u201c\u4e0d\u518d\u7528\u4e2d\u6587\u201d&#xff09;\u3001\u4efb\u52a1\u53ef\u80fd\u7ed3\u675f&#xff08;\u8ba2\u5355\u5df2\u5b8c\u6210&#xff09;\u3002\u5efa\u8bae\u63d0\u4f9b\u4e00\u4e2a&#034;\u964d\u7ea7&#034;\u63a5\u53e3&#xff0c;\u628a\u767d\u540d\u5355\u8bb0\u5fc6\u964d\u4e3a\u666e\u901a\u8bb0\u5fc6&#xff0c;\u53c2\u4e0e\u540e\u7eed\u6dd8\u6c70\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001TTL &#043; \u51b7\u70ed\u5206\u5c42&#xff1a;\u9632\u6b62&#034;\u521a\u8bb0\u4f4f\u5c31\u88ab\u6254&#034;<\/h3>\n<p>\u8fd8\u6709\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898&#xff1a;\u4e00\u6761\u8bb0\u5fc6\u521a\u5199\u8fdb\u53bb&#xff0c;\u56e0\u4e3a\u521d\u59cb\u5206\u6570\u4f4e&#xff08;\u6bd4\u5982\u666e\u901a\u95f2\u804a importance&#061;1&#xff09;&#xff0c;\u4e0b\u4e00\u8f6e\u6dd8\u6c70\u5c31\u88ab\u6254\u4e86\u3002<\/p>\n<p>\u4e09\u4e2a\u529e\u6cd5&#xff1a;<\/p>\n<li>\u65b0\u8bb0\u5fc6\u4fdd\u62a4\u671f&#xff1a;\u65b0\u5199\u5165\u7684\u8bb0\u5fc6\u5728 TTL \u5185&#xff08;\u6bd4\u5982 30 \u79d2&#xff09;\u4e0d\u53c2\u4e0e\u6dd8\u6c70\u3002\u7528 Redis \u7684 EXPIRE \u6216\u5355\u72ec\u7ef4\u62a4\u4e00\u4e2a&#034;\u4fdd\u62a4\u671f&#034;\u96c6\u5408\u3002<\/li>\n<li>\u51b7\u70ed\u5206\u5c42&#xff1a;\u5206\u4e24\u5c42\u2014\u2014\u70ed\u5c42&#xff08;\u5f53\u524d\u7a97\u53e3&#xff0c;\u6d3b\u8dc3\u8bb0\u5fc6&#xff09;\u548c\u51b7\u5c42&#xff08;\u5b58\u6863&#xff0c;\u53ef\u56de\u6eaf\u4f46\u4e0d\u8ba1\u5165\u4e0a\u4e0b\u6587&#xff09;\u3002\u6dd8\u6c70\u53ea\u5728\u70ed\u5c42\u505a&#xff0c;\u51b7\u5c42\u7528\u5355\u72ec\u7684\u6dd8\u6c70\u7b56\u7565&#xff08;\u5982 LRU&#xff09;\u3002<\/li>\n<li>\u6700\u4f4e\u5206\u515c\u5e95&#xff1a;\u7ed9\u6240\u6709\u8bb0\u5fc6\u8bbe\u4e00\u4e2a score_min&#xff08;\u6bd4\u5982 0.1&#xff09;&#xff0c;\u907f\u514d\u5206\u6570\u8870\u51cf\u5230 0 \u540e\u4e0b\u4e00\u8f6e\u5fc5\u7136\u88ab\u5220\u2014\u2014\u4f46\u767d\u540d\u5355\u4e0d\u53d7\u6b64\u9650\u3002<\/li>\n<p><span class=\"token comment\"># \u26a0\ufe0f \u9aa8\u67b6\u793a\u4f8b&#xff1a;\u65b0\u8bb0\u5fc6\u4fdd\u62a4\u671f<\/span><br \/>\nPROTECTION_TTL <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">30<\/span>  <span class=\"token comment\"># \u79d2<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">remember_with_protection<\/span><span class=\"token punctuation\">(<\/span>memory_id<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> importance<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">float<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># &#8230; \u6b63\u5e38\u5199\u5165\u903b\u8f91 &#8230;<\/span><br \/>\n    <span class=\"token comment\"># \u5728\u4fdd\u62a4\u671f\u96c6\u5408\u4e2d\u8bb0\u5f55<\/span><br \/>\n    r<span class=\"token punctuation\">.<\/span>sadd<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;agent:memory:protected&#034;<\/span><span class=\"token punctuation\">,<\/span> memory_id<span class=\"token punctuation\">)<\/span><br \/>\n    r<span class=\"token punctuation\">.<\/span>expire<span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;agent:memory:protect:<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>memory_id<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span> PROTECTION_TTL<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">evict_except_protected<\/span><span class=\"token punctuation\">(<\/span>max_size<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u6dd8\u6c70\u65f6\u8df3\u8fc7\u4fdd\u62a4\u671f\u5185\u7684\u8bb0\u5fc6&#034;&#034;&#034;<\/span><br \/>\n    protected <span class=\"token operator\">&#061;<\/span> r<span class=\"token punctuation\">.<\/span>smembers<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;agent:memory:protected&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u53ea\u6dd8\u6c70\u4e0d\u5728\u4fdd\u62a4\u671f\u5185\u7684\u4f4e\u5206\u8bb0\u5fc6<\/span><br \/>\n    <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><\/p>\n<hr \/>\n<h3>\u516d\u3001\u548c Context Engineering\u3001Prompt Caching \u5408\u8d77\u6765\u770b<\/h3>\n<p>\u7cfb\u5217\u8d70\u5230\u8fd9\u91cc&#xff0c;\u4e09\u5f20&#034;\u6210\u672c\u724c&#034;\u5df2\u7ecf\u9f50\u4e86&#xff1a;<\/p>\n<table>\n<tr>\u7b56\u7565\u7ba1\u4ec0\u4e48\u600e\u4e48\u505a<\/tr>\n<tbody>\n<tr>\n<td>Context Engineering<\/td>\n<td>\u5f80\u7a97\u53e3\u91cc\u653e\u54ea\u4e9b token<\/td>\n<td>\u9884\u7b97\u5206\u914d&#xff0c;L0-L5 \u5206\u5c42<\/td>\n<\/tr>\n<tr>\n<td>Prompt Caching<\/td>\n<td>\u7cfb\u7edf\u63d0\u793a\/\u5de5\u5177\u5b9a\u4e49\u5c11\u7b97<\/td>\n<td>\u524d\u7f00\u7f13\u5b58&#xff0c;\u65ad\u70b9 &#043; \u9884\u70ed<\/td>\n<\/tr>\n<tr>\n<td>\u8bb0\u5fc6\u6dd8\u6c70<\/td>\n<td>\u7528\u6237\u8bf4\u4e86\u4ec0\u4e48\u8be5\u7559<\/td>\n<td>\u4e09\u7ef4\u8bc4\u5206&#xff0c;Redis Sorted Set \u6dd8\u6c70<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e09\u8005\u7684\u5173\u7cfb&#xff1a;Context Engineering \u51b3\u5b9a&#034;\u653e\u4ec0\u4e48&#034;&#xff0c;Prompt Caching \u786e\u4fdd&#034;\u653e\u8fdb\u53bb\u7684\u5c11\u7b97&#034;&#xff0c;\u8bb0\u5fc6\u6dd8\u6c70\u786e\u4fdd**\u201c\u653e\u4e0d\u4e0b\u7684\u6254\u5f97\u5bf9\u201d**\u3002<\/p>\n<p>&#x1f4a1; \u5bf9\u5e94\u8bd5\/\u9762\u8bd5\u7684\u542f\u53d1&#xff1a;\u5f53\u9762\u8bd5\u5b98\u95ee&#034;Agent \u957f\u5bf9\u8bdd\u600e\u4e48\u5904\u7406&#034;&#xff0c;\u4e0d\u8981\u53ea\u7b54&#034;\u7528 RAG \u5b58&#034;\u2014\u2014\u628a\u8fd9\u4e09\u5f20\u724c\u4e32\u8d77\u6765&#xff0c;\u6bd4\u53ea\u7b54\u4e00\u4e2a\u5de5\u5177\u540d\u6df1\u5f97\u591a\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u300110 \u6761\u9762\u5411\u5ba2\u6237\/\u9762\u8bd5\u7684\u8868\u8fbe\u7ea2\u7ebf<\/h3>\n<table>\n<tr>\u522b\u8fd9\u4e48\u8bf4\u8be5\u600e\u4e48\u8bf4 \/ \u9519\u5728\u54ea<\/tr>\n<tbody>\n<tr>\n<td>\u300c\u7528\u5411\u91cf\u5e93\u5b58\u6240\u6709\u8bb0\u5fc6\u5c31\u884c\u300d<\/td>\n<td>\u5b58\u662f\u5b58\u50a8\u5c42&#xff0c;\u6dd8\u6c70\u662f\u7b56\u7565\u5c42&#xff0c;\u5b58\u5f97\u4e0b\u4e0d\u7b49\u4e8e\u7a97\u53e3\u653e\u5f97\u4e0b<\/td>\n<\/tr>\n<tr>\n<td>\u300c\u5148\u8fdb\u5148\u51fa\u591f\u7528\u4e86\u300d<\/td>\n<td>Agent \u5bf9\u8bdd\u91cc\u6700\u91cd\u8981\u7684\u4fe1\u606f\u5c45\u4e2d&#xff0c;FIFO \u6b63\u597d\u6dd8\u6c70\u5b83<\/td>\n<\/tr>\n<tr>\n<td>\u300c\u6211\u7684\u8bc4\u5206\u516c\u5f0f\u662f\u901a\u7528\u7684\u300d<\/td>\n<td>\u6743\u91cd\/\u9608\u503c\u6309\u573a\u666f\u8c03&#xff0c;\u6ca1\u6709\u4e07\u80fd\u53c2\u6570<\/td>\n<\/tr>\n<tr>\n<td>\u300c\u767d\u540d\u5355\u8bb0\u5fc6\u6c38\u4e0d\u6dd8\u6c70\u300d<\/td>\n<td>\u767d\u540d\u5355\u4f1a\u81a8\u80c0&#xff0c;\u9700\u8981\u4e0a\u9650\u548c&#034;\u964d\u7ea7&#034;\u673a\u5236<\/td>\n<\/tr>\n<tr>\n<td>\u300cRedis \u505a\u8bb0\u5fc6\u6dd8\u6c70\u5f88\u6162\u300d<\/td>\n<td>Sorted Set \u7684 ZRANK\/ZREMRANGEBYSCORE \u662f O(log N)&#xff0c;\u591f\u5feb<\/td>\n<\/tr>\n<tr>\n<td>\u300c\u5206\u6570\u8d8a\u9ad8\u8d8a\u91cd\u8981\u300d<\/td>\n<td>\u5206\u6570\u9ad8\u53ea\u8bf4\u660e\u73b0\u5728\u6392\u5728\u524d\u9762&#xff0c;\u8870\u51cf\u4f1a\u6539\u53d8\u6392\u540d<\/td>\n<\/tr>\n<tr>\n<td>\u300c\u8870\u51cf\u7cfb\u6570\u8bbe\u4e00\u4e2a\u5c31\u884c\u300d<\/td>\n<td>\u4e0d\u540c\u573a\u666f&#xff08;\u77ed\u671f\u5bf9\u8bdd vs \u957f\u671f\u9879\u76ee&#xff09;\u8870\u51cf\u901f\u5ea6\u4e0d\u540c<\/td>\n<\/tr>\n<tr>\n<td>\u300c\u6dd8\u6c70\u4e86\u5c31\u4e0d\u7ba1\u4e86\u300d<\/td>\n<td>\u6dd8\u6c70\u7684\u8bb0\u5fc6\u53ef\u4ee5\u5f52\u6863\u5230\u51b7\u5c42&#xff0c;\u9700\u8981\u65f6\u8fd8\u80fd\u56de\u6eaf<\/td>\n<\/tr>\n<tr>\n<td>\u300c\u8bb0\u5fc6\u7ba1\u7406\u4e0d\u9700\u8981\u6d4b\u8bd5\u300d<\/td>\n<td>\u6a21\u62df\u957f\u5bf9\u8bdd\u3001\u6ce8\u5165\u5173\u952e\u4fe1\u606f\u3001\u770b\u5b83\u662f\u5426\u88ab\u8bef\u6740\u2014\u2014\u5fc5\u987b\u6d4b<\/td>\n<\/tr>\n<tr>\n<td>\u300c\u6211\u7684\u8bb0\u5fc6\u65b9\u6848\u662f\u751f\u4ea7\u7ea7\u7684\u300d<\/td>\n<td>\u5982\u679c\u6ca1\u8dd1\u8fc7\u8d85\u8fc7\u7a97\u53e3\u7684\u5bf9\u8bdd&#xff0c;\u5b83\u53ea\u662f\u9aa8\u67b6&#xff0c;\u522b\u5199\u6210&#034;\u5df2\u4e0a\u7ebf&#034;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u516b\u3001\u4e00\u53e5\u8bdd\u5e26\u8d70<\/h3>\n<p>\u8bb0\u5fc6\u4e0d\u662f\u65e0\u9650\u4ed3\u5e93&#xff0c;\u6dd8\u6c70\u662f\u5fc5\u7136\u7684\u51b3\u7b56&#xff1b;\u7528\u4e09\u7ef4\u8bc4\u5206\u6392\u4f18\u5148\u7ea7&#xff0c;\u7528 Redis \u6392\u5e8f\u96c6\u843d\u5730&#xff0c;\u7528\u767d\u540d\u5355\u4fdd\u62a4\u5173\u952e\u8bb0\u5fc6\u2014\u2014\u7136\u540e\u628a\u4e00\u5207\u6570\u5b57\u6807\u6210&#034;\u6309\u573a\u666f\u8c03\u53c2&#034;\u3002<\/p>\n<hr \/>\n<p>\u4e0b\u671f\u9884\u544a&#xff1a;\u7b2c\u2465\u7bc7\u8bb2\u300cDelta Channels\u300d\u2014\u2014LangGraph \u7684 checkpoint \u4ece O(N\u00b2) \u964d\u5230 O(N) \u7684&#034;\u5b9e\u9a8c\u6027&#034;\u529f\u80fd&#xff0c;\u503c\u5f97\u6bcf\u4e2a\u505a\u590d\u6742 Agent \u7684\u4eba\u5173\u6ce8\u3002<\/p>\n<hr \/>\n<p>\u53c2\u8003&#xff1a;Redis Sorted Set \u6587\u6863&#xff08;ZADD\/ZRANK\/ZREMRANGEBYSCORE&#xff09;&#xff1b;MemGPT\/LangMem \u5b98\u65b9\u6587\u6863&#xff08;\u4ee5\u53d1\u5e03\u65f6\u7248\u672c\u4e3a\u51c6&#xff09;&#xff1b;\u672c\u6587\u8bc4\u5206\u516c\u5f0f\u4e3a\u9aa8\u67b6&#xff0c;\u6743\u91cd\/\u9608\u503c\u9700\u6309\u573a\u666f\u8c03\u53c2\u3002<\/p>\n<hr \/>\n<h4>\u672c\u7cfb\u5217\u76ee\u5f55<\/h4>\n<ul>\n<li>\u2460 Java \u540e\u7aef\u4e0d\u505a Agent&#xff1f;Spring AI &#043; MCP \u5b9e\u6218&#xff08;\u5df2\u53d1\u5e03&#xff09;<\/li>\n<li>\u2461 MCP vs A2A&#xff1a;\u534f\u8bae\u6808\u4f4d\u7f6e\u4e0e\u9009\u578b\u51b3\u7b56\u6811&#xff08;\u5df2\u53d1\u5e03&#xff09;<\/li>\n<li>\u2462 \u522b\u518d\u53ea\u4f1a\u5199 Prompt&#xff1a;Context Engineering \u624d\u662f Agent \u7684\u4e0b\u4e00\u4e2a\u8303\u5f0f&#xff08;\u5df2\u53d1\u5e03&#xff09;<\/li>\n<li>\u2463 Prompt \u7f13\u5b58\u4e0d\u662f\u7384\u5b66&#xff1a;\u547d\u4e2d\u5224\u5b9a\u3001\u65ad\u70b9\u4e0e\u9884\u70ed&#xff08;\u5df2\u53d1\u5e03&#xff09;<\/li>\n<li>\u2464 \u8bb0\u5fc6\u6dd8\u6c70\u7b56\u7565&#xff1a;\u91cd\u8981\u6027 \u00d7 \u65f6\u6548\u6027 \u00d7 \u767d\u540d\u5355&#xff08;\u672c\u6587&#xff09;<\/li>\n<li>\u2465 LangGraph Delta Channels\u2014\u2014\u4e0b\u671f\u9884\u544a<\/li>\n<li>\u5b89\u5168\u4e0e\u53ef\u4fe1 \u2192 \u6210\u672c\u4e0e\u8de8\u6808 \u2192 \u672a\u5b8c\u5f85\u7eed<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Agent \u8bb0\u5fc6\u4f1a\\&#8221;\u6ee1\\&#8221;\u5417&#xff1f;\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355&#xff0c;\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7\u672c\u6587\u662f\u300cAgent \u5e94\u7528\u5f00\u53d1\u5de5\u7a0b\u5e08\u300d\u7cfb\u5217\u7b2c\u2464\u7bc7 \u00b7 \u4e0a\u4e0b\u6587\u662f\u9884\u7b97&#xff0c;\u7f13\u5b58\u662f\u7b2c\u4e00\u5200&#xff0c;\u8bb0\u5fc6\u6dd8\u6c70\u662f\u7b2c\u4e8c\u5200\u2014\u2014\u628a\u6700\u503c\u5f97\u8bb0\u4f4f\u7684\u7559\u4e0b\u3002\u26a1 TL;DR \u00b7 \u5148\u770b\u7ed3\u8bba<br \/>\nAgent \u8bb0\u5fc6\u4e0d\u662f\u65e0\u9650\u4ed3\u5e93&#xff0c;\u4e0a\u4e0b\u6587\u7a97\u53e3\u6ee1\u4e86\u5c31\u5f97\u6dd8\u6c70&#xff0c;\u6dd8\u6c70\u4e0d\u80fd\u9760\\&#8221;\u5148\u8fdb\u5148\u51fa\\&#8221;\u2014\u2014\u91cd\u8981\u8bb0\u5fc6\u521a\u8bf4\u5b8c\u5c31\u88ab\u6254\u4e86\u3002\u672c\u6587\u7ed9\u51fa\u4e00\u4e2a\u4e09\u7ef4\u8bc4\u5206\u516c\u5f0f&#xff1a;score  importan<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,50,51],"topic":[],"class_list":["post-101694","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-50","tag-51"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Agent \u8bb0\u5fc6\u4f1a\u201c\u6ee1\u201c\u5417\uff1f\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355\uff0c\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/101694.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Agent \u8bb0\u5fc6\u4f1a\u201c\u6ee1\u201c\u5417\uff1f\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355\uff0c\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Agent \u8bb0\u5fc6\u4f1a&quot;\u6ee1&quot;\u5417&#xff1f;\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355&#xff0c;\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7\u672c\u6587\u662f\u300cAgent \u5e94\u7528\u5f00\u53d1\u5de5\u7a0b\u5e08\u300d\u7cfb\u5217\u7b2c\u2464\u7bc7 \u00b7 \u4e0a\u4e0b\u6587\u662f\u9884\u7b97&#xff0c;\u7f13\u5b58\u662f\u7b2c\u4e00\u5200&#xff0c;\u8bb0\u5fc6\u6dd8\u6c70\u662f\u7b2c\u4e8c\u5200\u2014\u2014\u628a\u6700\u503c\u5f97\u8bb0\u4f4f\u7684\u7559\u4e0b\u3002\u26a1 TL;DR \u00b7 \u5148\u770b\u7ed3\u8bba Agent \u8bb0\u5fc6\u4e0d\u662f\u65e0\u9650\u4ed3\u5e93&#xff0c;\u4e0a\u4e0b\u6587\u7a97\u53e3\u6ee1\u4e86\u5c31\u5f97\u6dd8\u6c70&#xff0c;\u6dd8\u6c70\u4e0d\u80fd\u9760&quot;\u5148\u8fdb\u5148\u51fa&quot;\u2014\u2014\u91cd\u8981\u8bb0\u5fc6\u521a\u8bf4\u5b8c\u5c31\u88ab\u6254\u4e86\u3002\u672c\u6587\u7ed9\u51fa\u4e00\u4e2a\u4e09\u7ef4\u8bc4\u5206\u516c\u5f0f&#xff1a;score importan\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/101694.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-07T00:41:07+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/101694.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/101694.html\",\"name\":\"Agent \u8bb0\u5fc6\u4f1a\u201c\u6ee1\u201c\u5417\uff1f\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355\uff0c\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-07T00:41:07+00:00\",\"dateModified\":\"2026-09-07T00:41:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/101694.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/101694.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/101694.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Agent \u8bb0\u5fc6\u4f1a\u201c\u6ee1\u201c\u5417\uff1f\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355\uff0c\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Agent \u8bb0\u5fc6\u4f1a\u201c\u6ee1\u201c\u5417\uff1f\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355\uff0c\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/101694.html","og_locale":"zh_CN","og_type":"article","og_title":"Agent \u8bb0\u5fc6\u4f1a\u201c\u6ee1\u201c\u5417\uff1f\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355\uff0c\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Agent \u8bb0\u5fc6\u4f1a\"\u6ee1\"\u5417&#xff1f;\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355&#xff0c;\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7\u672c\u6587\u662f\u300cAgent \u5e94\u7528\u5f00\u53d1\u5de5\u7a0b\u5e08\u300d\u7cfb\u5217\u7b2c\u2464\u7bc7 \u00b7 \u4e0a\u4e0b\u6587\u662f\u9884\u7b97&#xff0c;\u7f13\u5b58\u662f\u7b2c\u4e00\u5200&#xff0c;\u8bb0\u5fc6\u6dd8\u6c70\u662f\u7b2c\u4e8c\u5200\u2014\u2014\u628a\u6700\u503c\u5f97\u8bb0\u4f4f\u7684\u7559\u4e0b\u3002\u26a1 TL;DR \u00b7 \u5148\u770b\u7ed3\u8bba Agent \u8bb0\u5fc6\u4e0d\u662f\u65e0\u9650\u4ed3\u5e93&#xff0c;\u4e0a\u4e0b\u6587\u7a97\u53e3\u6ee1\u4e86\u5c31\u5f97\u6dd8\u6c70&#xff0c;\u6dd8\u6c70\u4e0d\u80fd\u9760\"\u5148\u8fdb\u5148\u51fa\"\u2014\u2014\u91cd\u8981\u8bb0\u5fc6\u521a\u8bf4\u5b8c\u5c31\u88ab\u6254\u4e86\u3002\u672c\u6587\u7ed9\u51fa\u4e00\u4e2a\u4e09\u7ef4\u8bc4\u5206\u516c\u5f0f&#xff1a;score importan","og_url":"https:\/\/www.wsisp.com\/helps\/101694.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-07T00:41:07+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/101694.html","url":"https:\/\/www.wsisp.com\/helps\/101694.html","name":"Agent \u8bb0\u5fc6\u4f1a\u201c\u6ee1\u201c\u5417\uff1f\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355\uff0c\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-07T00:41:07+00:00","dateModified":"2026-09-07T00:41:07+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/101694.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/101694.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/101694.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Agent \u8bb0\u5fc6\u4f1a\u201c\u6ee1\u201c\u5417\uff1f\u91cd\u8981\u6027\u00d7\u65f6\u6548\u6027\u00d7\u767d\u540d\u5355\uff0c\u7ed9\u8bb0\u5fc6\u6392\u4e2a\u6dd8\u6c70\u4f18\u5148\u7ea7"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/101694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=101694"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/101694\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=101694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=101694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=101694"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=101694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}