{"id":87792,"date":"2026-07-30T21:48:29","date_gmt":"2026-07-30T13:48:29","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/87792.html"},"modified":"2026-07-30T21:48:29","modified_gmt":"2026-07-30T13:48:29","slug":"%e5%a4%a7%e6%a8%a1%e5%9e%8b%e9%87%91%e9%b1%bc%e8%84%91%e7%bb%88%e7%bb%93%e8%80%85%ef%bc%81ai-agent%e7%9f%ad%e6%9c%9f%e8%ae%b0%e5%bf%86%e4%b8%8e%e9%95%bf%e6%9c%9f%e8%ae%b0%e5%bf%86","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/87792.html","title":{"rendered":"\u5927\u6a21\u578b\u201c\u91d1\u9c7c\u8111\u201d\u7ec8\u7ed3\u8005\uff01AI Agent\u77ed\u671f\u8bb0\u5fc6\u4e0e\u957f\u671f\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1\u53caLangChain\u72b6\u6001\u7ba1\u7406\u6e90\u7801\u5256\u6790"},"content":{"rendered":"<h3>\u524d\u8a00<\/h3>\n<p>\u5728\u6784\u5efaAI\u667a\u80fd\u4f53&#xff08;Agent&#xff09;\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u6211\u8e29\u8fc7\u6700\u6df1\u7684\u4e00\u4e2a\u5751\u5c31\u662f\u2014\u2014\u5927\u6a21\u578b\u662f\u4e2a\u201c\u91d1\u9c7c\u8111\u201d \u3002\u65e0\u8bba\u4f60\u4e0a\u4e00\u8f6e\u8ddf\u5b83\u804a\u4e86\u4ec0\u4e48&#xff0c;\u4e0b\u4e00\u8f6e\u5b83\u53ef\u80fd\u5c31\u5fd8\u5f97\u4e00\u5e72\u4e8c\u51c0\u3002<\/p>\n<p>\u8fd9\u4e0d\u662f\u5927\u6a21\u578b\u7684\u201c\u6001\u5ea6\u95ee\u9898\u201d&#xff0c;\u800c\u662f\u5b83\u7684\u5e95\u5c42\u8bbe\u8ba1\u51b3\u5b9a\u7684&#xff1a;\u6240\u6709\u5927\u6a21\u578b\u672c\u8d28\u4e0a\u90fd\u662f\u201c\u65e0\u72b6\u6001\u201d\u7684\u2014\u2014\u5b83\u5bf9\u6bcf\u4e00\u6b21\u8bf7\u6c42\u7684\u5904\u7406\u90fd\u662f\u72ec\u7acb\u7684&#xff0c;\u4e0d\u4f1a\u4e3b\u52a8\u7559\u5b58\u4e0a\u4e00\u8f6e\u5bf9\u8bdd\u7684\u4efb\u4f55\u4fe1\u606f\u3002\u60f3\u8ba9\u5927\u6a21\u578b\u201c\u8bb0\u4f4f\u201d\u4e0a\u4e0b\u6587&#xff0c;\u672c\u8d28\u4e0a\u9700\u8981\u505a\u4e24\u4ef6\u4e8b&#xff1a;\u8bb0\u5f55\u5386\u53f2&#xff08;\u5c06\u7528\u6237\u63d0\u95ee\u548c\u6a21\u578b\u56de\u7b54\u5b58\u50a8\u5728\u5916\u90e8\u8f7d\u4f53\u4e2d&#xff09;&#xff0c;\u4ee5\u53ca\u5728\u53d1\u8d77\u65b0\u8bf7\u6c42\u65f6\u5c06\u5386\u53f2\u5bf9\u8bdd\u62fc\u63a5\u5230\u63d0\u793a\u8bcd\u4e2d\u3002<\/p>\n<p>\u5bf9\u4e8e\u7b80\u5355\u7684\u5bf9\u8bdd\u673a\u5668\u4eba&#xff0c;\u8fd9\u4e2a\u95ee\u9898\u53ef\u80fd\u8fd8\u597d\u89e3\u51b3\u3002\u4f46\u5f53\u4f60\u7684Agent\u9700\u8981\u6267\u884c\u590d\u6742\u957f\u94fe\u4efb\u52a1\u2014\u2014\u6bd4\u5982\u81ea\u52a8\u5b8c\u6210\u4e00\u4efd\u5e02\u573a\u8c03\u7814\u62a5\u544a\u3001\u534f\u8c03\u591a\u4e2a\u5b50Agent\u5b8c\u6210\u4f9b\u5e94\u94fe\u8c03\u5ea6\u2014\u2014\u8bb0\u5fc6\u673a\u5236\u7684\u7f3a\u5931\u5c31\u4f1a\u6210\u4e3a\u81f4\u547d\u7684\u77ed\u677f\u3002\u4efb\u52a1\u6267\u884c\u5230\u4e00\u534a&#xff0c;Agent\u5fd8\u4e86\u4e4b\u524d\u6536\u96c6\u4e86\u4ec0\u4e48\u4fe1\u606f&#xff1b;\u8de8\u4f1a\u8bdd\u4ea4\u4e92\u65f6&#xff0c;Agent\u8ba4\u4e0d\u51fa\u8fd9\u662f\u201c\u8001\u719f\u4eba\u201d\u3002<\/p>\n<p>\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790LangChain\u751f\u6001\u4e2d\u7684\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1&#xff0c;\u4ece\u77ed\u671f\u8bb0\u5fc6\u7684\u591a\u79cd\u5b9e\u73b0\u7b56\u7565\u5230\u957f\u671f\u8bb0\u5fc6\u7684\u67b6\u6784\u65b9\u6848&#xff0c;\u7ed3\u5408\u6e90\u7801\u89e3\u8bfb&#xff0c;\u5e2e\u4f60\u5f7b\u5e95\u641e\u61c2\u5982\u4f55\u8ba9AI Agent\u544a\u522b\u201c\u91d1\u9c7c\u8111\u201d\u3002<\/p>\n<h3>\u4e00\u3001\u8bb0\u5fc6\u7684\u672c\u8d28&#xff1a;\u4ece\u201c\u65e0\u72b6\u6001\u201d\u5230\u201c\u6709\u8bb0\u5fc6\u201d<\/h3>\n<p>\u5728\u6df1\u5165\u6846\u67b6\u4e4b\u524d&#xff0c;\u6211\u4eec\u5148\u5efa\u7acb\u4e00\u4e2a\u6838\u5fc3\u8ba4\u77e5&#xff1a;\u6240\u8c13\u201c\u8bb0\u5fc6\u201d&#xff0c;\u672c\u8d28\u662f\u901a\u8fc7\u5916\u90e8\u7cfb\u7edf\u5b58\u50a8\u5bf9\u8bdd\u5386\u53f2&#xff0c;\u518d\u5c06\u5176\u52a8\u6001\u62fc\u63a5\u81f3\u63d0\u793a\u8bcd\u4e2d\u3002<\/p>\n<p>LangChain\u901a\u8fc7Memory\u7ec4\u4ef6\u5c06\u8fd9\u4e2a\u201c\u8bb0\u5f55-\u5b58\u50a8-\u62fc\u63a5\u201d\u7684\u8fc7\u7a0b\u8fdb\u884c\u4e86\u6807\u51c6\u5316\u5c01\u88c5\u3002\u6574\u4e2a\u8bb0\u5fc6\u7cfb\u7edf\u7531\u4e24\u4e2a\u6838\u5fc3\u62bd\u8c61\u5c42\u7ec4\u6210&#xff1a;<\/p>\n<table>\n<tr>\u62bd\u8c61\u5c42\u804c\u8d23<\/tr>\n<tbody>\n<tr>\n<td>BaseMemory<\/td>\n<td>\u5b9a\u4e49\u201c\u5982\u4f55\u7ba1\u7406\u8bb0\u5fc6\u201d\u2014\u2014\u4fdd\u5b58\u3001\u52a0\u8f7d\u3001\u6e05\u7a7a\u7b49\u884c\u4e3a\u63a5\u53e3<\/td>\n<\/tr>\n<tr>\n<td>ChatMessageHistory<\/td>\n<td>\u5b9a\u4e49\u201c\u8bb0\u5fc6\u5b58\u653e\u5728\u54ea\u91cc\u201d\u2014\u2014\u652f\u6301\u5185\u5b58\u3001Redis\u3001\u6570\u636e\u5e93\u7b49\u4e0d\u540c\u540e\u7aef<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7406\u89e3\u8fd9\u4e24\u4e2a\u5c42\u6b21\u540e&#xff0c;\u5c31\u80fd\u8f7b\u677e\u638c\u63e1\u4e0d\u540c\u7c7b\u578b\u8bb0\u5fc6\u673a\u5236\u7684\u8bbe\u8ba1\u903b\u8f91\u3002<\/p>\n<h3>\u4e8c\u3001\u77ed\u671f\u8bb0\u5fc6&#xff1a;\u8ba9Agent\u201c\u8bb0\u4f4f\u521a\u624d\u8bf4\u4e86\u4ec0\u4e48\u201d<\/h3>\n<p>\u77ed\u671f\u8bb0\u5fc6&#xff08;Short-term Memory&#xff09;\u662f\u4f1a\u8bdd\u7ea7\u522b\u7684\u8bb0\u5fc6&#xff0c;\u8d1f\u8d23\u5728\u5355\u6b21\u4f1a\u8bdd\u4e2d\u7ef4\u6301\u5bf9\u8bdd\u4e0a\u4e0b\u6587\u3002LangChain\u63d0\u4f9b\u4e86\u591a\u79cd\u77ed\u671f\u8bb0\u5fc6\u5b9e\u73b0&#xff0c;\u9002\u7528\u4e8e\u4e0d\u540c\u573a\u666f\u3002<\/p>\n<h4>2.1 ConversationBufferMemory&#xff1a;\u5168\u91cf\u8bb0\u5fc6<\/h4>\n<p>\u6700\u57fa\u7840\u7684\u5b9e\u73b0&#xff0c;\u76f4\u63a5\u5c06\u5b8c\u6574\u5bf9\u8bdd\u5386\u53f2\u4ee5\u5217\u8868\u5f62\u5f0f\u5b58\u50a8\u3002<\/p>\n<p><span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>memory <span class=\"token keyword\">import<\/span> ConversationBufferMemory<br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>chains <span class=\"token keyword\">import<\/span> ConversationChain<br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>chat_models <span class=\"token keyword\">import<\/span> ChatOpenAI<\/p>\n<p>memory <span class=\"token operator\">&#061;<\/span> ConversationBufferMemory<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\nchain <span class=\"token operator\">&#061;<\/span> ConversationChain<span class=\"token punctuation\">(<\/span>llm<span class=\"token operator\">&#061;<\/span>ChatOpenAI<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> memory<span class=\"token operator\">&#061;<\/span>memory<span class=\"token punctuation\">)<\/span><\/p>\n<p>chain<span class=\"token punctuation\">.<\/span>run<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u6211\u53eb\u5f20\u4e09&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\nchain<span class=\"token punctuation\">.<\/span>run<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6211\u559c\u6b22\u559d\u62ff\u94c1&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\nchain<span class=\"token punctuation\">.<\/span>run<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u4f60\u8bb0\u5f97\u6211\u53eb\u4ec0\u4e48\u5417&#xff1f;&#034;<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u2705 \u80fd\u8bb0\u4f4f<\/span><\/p>\n<p>\u539f\u7406&#xff1a;\u6bcf\u6b21\u4ea4\u4e92\u540e&#xff0c;\u5c06\u7528\u6237\u8f93\u5165\u548c\u6a21\u578b\u8f93\u51fa\u8ffd\u52a0\u5230\u5185\u5b58\u5217\u8868\u4e2d&#xff1b;\u8c03\u7528\u65f6\u901a\u8fc7load_memory_variables\u8fd4\u56de\u5b8c\u6574\u5386\u53f2\u3002<\/p>\n<p>\u9002\u7528\u573a\u666f&#xff1a;\u77ed\u5bf9\u8bdd&#xff08;\u5982\u5ba2\u670d\u5355\u8f6e\u54a8\u8be2&#xff09;\u3002\u4f18\u70b9\u662f\u5b8c\u5168\u4fdd\u7559\u7ec6\u8282&#xff0c;\u7f3a\u70b9\u662f\u968f\u5bf9\u8bdd\u957f\u5ea6\u589e\u52a0\u4f1a\u5bfc\u81f4Prompt\u8fc7\u957f&#xff0c;\u8d85\u51fa\u6a21\u578b\u4e0a\u4e0b\u6587\u7a97\u53e3\u3002<\/p>\n<h4>2.2 ConversationBufferWindowMemory&#xff1a;\u6ed1\u52a8\u7a97\u53e3\u8bb0\u5fc6<\/h4>\n<p>\u5e26\u201c\u7a97\u53e3\u9650\u5236\u201d\u7684\u7f13\u51b2\u8bb0\u5fc6&#xff0c;\u53ea\u4fdd\u7559\u6700\u8fd1\u7684k\u8f6e\u5bf9\u8bdd\u3002<\/p>\n<p><span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>memory <span class=\"token keyword\">import<\/span> ConversationBufferWindowMemory<\/p>\n<p>memory <span class=\"token operator\">&#061;<\/span> ConversationBufferWindowMemory<span class=\"token punctuation\">(<\/span>k<span class=\"token operator\">&#061;<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u53ea\u4fdd\u7559\u6700\u8fd13\u6761\u6d88\u606f<\/span><br \/>\nchain <span class=\"token operator\">&#061;<\/span> ConversationChain<span class=\"token punctuation\">(<\/span>llm<span class=\"token operator\">&#061;<\/span>ChatOpenAI<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> memory<span class=\"token operator\">&#061;<\/span>memory<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u539f\u7406&#xff1a;\u7ef4\u62a4\u4e00\u4e2a\u56fa\u5b9a\u957f\u5ea6\u7684\u6ed1\u52a8\u7a97\u53e3&#xff0c;\u8d85\u8fc7k\u8f6e\u540e\u81ea\u52a8\u4e22\u5f03\u6700\u65e9\u7684\u5bf9\u8bdd\u3002<\/p>\n<p>\u9002\u7528\u573a\u666f&#xff1a;\u4e2d\u7b49\u957f\u5ea6\u5bf9\u8bdd&#xff08;\u5982\u591a\u8f6e\u95ee\u7b54&#xff09;&#xff0c;\u5e73\u8861\u4e0a\u4e0b\u6587\u76f8\u5173\u6027\u548c\u957f\u5ea6\u3002<\/p>\n<h4>2.3 ConversationTokenBufferMemory&#xff1a;\u6309Token\u9650\u5236\u8bb0\u5fc6<\/h4>\n<p>\u6309Token\u6570\u91cf\u9650\u5236\u8bb0\u5fc6&#xff0c;\u786e\u4fdd\u603b\u5bf9\u8bdd\u5386\u53f2\u7684Token\u6570\u4e0d\u8d85\u8fc7\u6a21\u578b\u7a97\u53e3\u3002<\/p>\n<p><span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>memory <span class=\"token keyword\">import<\/span> ConversationTokenBufferMemory<\/p>\n<p>memory <span class=\"token operator\">&#061;<\/span> ConversationTokenBufferMemory<span class=\"token punctuation\">(<\/span>llm<span class=\"token operator\">&#061;<\/span>ChatOpenAI<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> max_token_limit<span class=\"token operator\">&#061;<\/span><span class=\"token number\">2000<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u539f\u7406&#xff1a;\u901a\u8fc7Tokenizer\u8ba1\u7b97\u6bcf\u8f6e\u5bf9\u8bdd\u7684Token\u6570&#xff0c;\u7d2f\u8ba1\u8d85\u8fc7\u9608\u503c\u65f6\u4ece\u6700\u65e9\u7684\u5bf9\u8bdd\u5f00\u59cb\u5220\u9664\u3002<\/p>\n<p>\u9002\u7528\u573a\u666f&#xff1a;\u5bf9Token\u6210\u672c\u654f\u611f\u6216\u6a21\u578b\u7a97\u53e3\u56fa\u5b9a\u7684\u573a\u666f&#xff08;\u5982API\u8c03\u7528&#xff09;\u3002<\/p>\n<h4>2.4 ConversationSummaryMemory&#xff1a;\u6458\u8981\u538b\u7f29\u8bb0\u5fc6<\/h4>\n<p>\u5bf9\u5bf9\u8bdd\u5386\u53f2\u8fdb\u884c\u201c\u6458\u8981\u538b\u7f29\u201d&#xff0c;\u7528\u6458\u8981\u4ee3\u66ff\u539f\u59cb\u5bf9\u8bdd\u3002<\/p>\n<p><span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>memory <span class=\"token keyword\">import<\/span> ConversationSummaryMemory<\/p>\n<p>memory <span class=\"token operator\">&#061;<\/span> ConversationSummaryMemory<span class=\"token punctuation\">(<\/span>llm<span class=\"token operator\">&#061;<\/span>ChatOpenAI<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\nchain <span class=\"token operator\">&#061;<\/span> ConversationChain<span class=\"token punctuation\">(<\/span>llm<span class=\"token operator\">&#061;<\/span>ChatOpenAI<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> memory<span class=\"token operator\">&#061;<\/span>memory<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u539f\u7406&#xff1a;\u6bcf\u8f6e\u4ea4\u4e92\u540e\u8c03\u7528LLM\u5bf9\u5386\u53f2\u5bf9\u8bdd\u751f\u6210\u6458\u8981&#xff0c;\u540e\u7eed\u4ec5\u5c06\u6458\u8981\u4f20\u5165Prompt\u3002<\/p>\n<p>\u9002\u7528\u573a\u666f&#xff1a;\u957f\u5bf9\u8bdd&#xff08;\u5982\u6301\u7eed\u51e0\u5c0f\u65f6\u7684\u54a8\u8be2&#xff09;&#xff0c;\u907f\u514d\u539f\u59cb\u5386\u53f2\u8fc7\u957f\u3002\u7f3a\u70b9\u662f\u53ef\u80fd\u4e22\u5931\u7ec6\u8282&#xff08;\u6458\u8981\u7cbe\u5ea6\u4f9d\u8d56LLM&#xff09;\u3002<\/p>\n<h3>\u4e09\u3001\u6e90\u7801\u5256\u6790&#xff1a;BaseMemory\u6838\u5fc3\u63a5\u53e3\u8bbe\u8ba1<\/h3>\n<p>\u4e86\u89e3\u4e86\u5404\u79cd\u8bb0\u5fc6\u7c7b\u578b\u540e&#xff0c;\u6211\u4eec\u6df1\u5165\u6e90\u7801\u770b\u770bLangChain\u662f\u5982\u4f55\u8bbe\u8ba1\u8fd9\u5957\u8bb0\u5fc6\u7cfb\u7edf\u7684\u3002<\/p>\n<h4>3.1 BaseMemory\u62bd\u8c61\u57fa\u7c7b<\/h4>\n<p>BaseMemory\u662f\u6240\u6709\u8bb0\u5fc6\u7c7b\u7684\u62bd\u8c61\u57fa\u7c7b&#xff0c;\u5b9a\u4e49\u4e86\u8bb0\u5fc6\u6a21\u5757\u5fc5\u987b\u5b9e\u73b0\u7684\u6838\u5fc3\u63a5\u53e3&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> abc <span class=\"token keyword\">import<\/span> ABC<span class=\"token punctuation\">,<\/span> abstractmethod<br \/>\n<span class=\"token keyword\">from<\/span> typing <span class=\"token keyword\">import<\/span> Any<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">BaseMemory<\/span><span class=\"token punctuation\">(<\/span>Serializable<span class=\"token punctuation\">,<\/span> ABC<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u8bb0\u5fc6\u7684\u62bd\u8c61\u57fa\u7c7b&#xff0c;\u5b9a\u4e49\u4e86\u6240\u6709\u8bb0\u5fc6\u7c7b\u578b\u5fc5\u987b\u5b9e\u73b0\u7684\u6838\u5fc3\u63a5\u53e3&#034;&#034;&#034;<\/span><\/p>\n<p>    <span class=\"token decorator annotation punctuation\">&#064;property<\/span><br \/>\n    <span class=\"token decorator annotation punctuation\">&#064;abstractmethod<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">memory_variables<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">list<\/span><span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u8fd4\u56de\u6b64\u8bb0\u5fc6\u7ec4\u4ef6\u7ba1\u7406\u7684\u53d8\u91cf\u540d&#xff0c;\u4f8b\u5982&#xff1a;[&#034;history&#034;, &#034;summary&#034;]&#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">pass<\/span><\/p>\n<p>    <span class=\"token decorator annotation punctuation\">&#064;abstractmethod<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">load_memory_variables<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> inputs<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> Any<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> Any<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;<br \/>\n        \u52a0\u8f7d\u8bb0\u5fc6\u53d8\u91cf&#xff0c;\u6839\u636e\u8f93\u5165\u83b7\u53d6\u76f8\u5173\u7684\u5386\u53f2\u5185\u5bb9<br \/>\n        \u8fd4\u56de\u7684\u5b57\u5178\u4f1a\u88ab\u6dfb\u52a0\u5230\u63d0\u793a\u8bcd\u7684\u4e0a\u4e0b\u6587\u4e2d<br \/>\n        &#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">pass<\/span><\/p>\n<p>    <span class=\"token decorator annotation punctuation\">&#064;abstractmethod<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">save_context<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> inputs<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> Any<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> outputs<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;<br \/>\n        \u4fdd\u5b58\u5f53\u524d\u5bf9\u8bdd\u4e0a\u4e0b\u6587<br \/>\n        inputs: \u7528\u6237\u7684\u8f93\u5165&#xff0c;\u5982 {&#034;input&#034;: &#034;\u4f60\u597d&#034;}<br \/>\n        outputs: \u6a21\u578b\u7684\u8f93\u51fa&#xff0c;\u5982 {&#034;output&#034;: &#034;\u4f60\u597d&#xff01;&#034;}<br \/>\n        &#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">pass<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">clear<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u6e05\u9664\u6240\u6709\u8bb0\u5fc6\u5185\u5bb9&#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">pass<\/span><\/p>\n<p>\u8fd9\u5957\u63a5\u53e3\u8bbe\u8ba1\u7684\u7cbe\u5999\u4e4b\u5904\u5728\u4e8e&#xff1a;load_memory_variables\u548csave_context\u6784\u6210\u4e86\u8bb0\u5fc6\u7684\u8bfb\u5199\u95ed\u73af&#xff0c;\u800cmemory_variables\u5219\u544a\u8bc9Chain\u54ea\u4e9b\u53d8\u91cf\u9700\u8981\u88ab\u6ce8\u5165\u5230Prompt\u4e2d\u3002<\/p>\n<h4>3.2 BaseChatMemory&#xff1a;\u804a\u5929\u8bb0\u5fc6\u7684\u5177\u4f53\u5b9e\u73b0<\/h4>\n<p>BaseChatMemory\u7ee7\u627f\u81eaBaseMemory&#xff0c;\u63d0\u4f9b\u4e86\u804a\u5929\u8bb0\u5fc6\u7684\u901a\u7528\u5b9e\u73b0&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">BaseChatMemory<\/span><span class=\"token punctuation\">(<\/span>BaseMemory<span class=\"token punctuation\">,<\/span> ABC<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u804a\u5929\u8bb0\u5fc6\u7684\u57fa\u7840\u7c7b&#xff0c;\u63d0\u4f9b\u4e86\u804a\u5929\u8bb0\u5fc6\u7684\u901a\u7528\u5b9e\u73b0&#034;&#034;&#034;<\/span><\/p>\n<p>    chat_memory<span class=\"token punctuation\">:<\/span> BaseChatMessageHistory <span class=\"token operator\">&#061;<\/span> Field<span class=\"token punctuation\">(<\/span><br \/>\n        default_factory<span class=\"token operator\">&#061;<\/span>InMemoryChatMessageHistory<br \/>\n    <span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u6d88\u606f\u5386\u53f2\u5b58\u50a8\u5bf9\u8c61&#xff0c;\u53ef\u66ff\u6362\u4e3aRedis\u3001\u6570\u636e\u5e93\u7b49\u4e0d\u540c\u540e\u7aef&#034;&#034;&#034;<\/span><\/p>\n<p>    output_key<span class=\"token punctuation\">:<\/span> Optional<span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">None<\/span><br \/>\n    input_key<span class=\"token punctuation\">:<\/span> Optional<span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">None<\/span><br \/>\n    return_messages<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">bool<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">False<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">_get_input<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> inputs<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> Any<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u4ece\u8f93\u5165\u4e2d\u83b7\u53d6\u7528\u6237\u6d88\u606f&#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> self<span class=\"token punctuation\">.<\/span>input_key <span class=\"token keyword\">is<\/span> <span class=\"token keyword\">not<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> inputs<span class=\"token punctuation\">[<\/span>self<span class=\"token punctuation\">.<\/span>input_key<span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token comment\"># &#8230;<\/span><\/p>\n<p>\u8fd9\u91cc\u7684\u5173\u952e\u8bbe\u8ba1\u662f\u4f9d\u8d56\u6ce8\u5165&#xff1a;chat_memory\u5b57\u6bb5\u5141\u8bb8\u5f00\u53d1\u8005\u6ce8\u5165\u4e0d\u540c\u7684\u5b58\u50a8\u540e\u7aef\u5b9e\u73b0&#xff08;\u5185\u5b58\u3001Redis\u3001\u6570\u636e\u5e93\u7b49&#xff09;&#xff0c;\u800c\u4e0d\u9700\u8981\u4fee\u6539\u8bb0\u5fc6\u903b\u8f91\u672c\u8eab\u3002\u8fd9\u5c31\u662f\u201c\u5982\u4f55\u7ba1\u7406\u8bb0\u5fc6\u201d\u4e0e\u201c\u8bb0\u5fc6\u5b58\u653e\u5728\u54ea\u91cc\u201d\u7684\u89e3\u8026\u3002<\/p>\n<h3>\u56db\u3001\u957f\u671f\u8bb0\u5fc6&#xff1a;\u8ba9Agent\u201c\u8bb0\u4f4f\u6628\u5929\u7684\u4e8b\u201d<\/h3>\n<p>\u77ed\u671f\u8bb0\u5fc6\u89e3\u51b3\u4e86\u201c\u4f1a\u8bdd\u5185\u201d\u7684\u95ee\u9898&#xff0c;\u4f46Agent\u8fd8\u9700\u8981\u201c\u8de8\u4f1a\u8bdd\u201d\u7684\u8bb0\u5fc6\u80fd\u529b\u2014\u2014\u957f\u671f\u8bb0\u5fc6&#xff08;Long-term Memory&#xff09; \u3002<\/p>\n<h4>4.1 \u957f\u671f\u8bb0\u5fc6\u7684\u6838\u5fc3\u6311\u6218<\/h4>\n<p>\u5b9e\u73b0\u957f\u671f\u8bb0\u5fc6\u9762\u4e34\u4e09\u5927\u6280\u672f\u6311\u6218&#xff1a;<\/p>\n<li>\u4e0a\u4e0b\u6587\u7a97\u53e3\u9650\u5236&#xff1a;\u65e0\u6cd5\u5c06\u6240\u6709\u5386\u53f2\u90fd\u585e\u8fdbPrompt<\/li>\n<li>\u8bb0\u5fc6\u6570\u636e\u7684\u6709\u6548\u7ec4\u7ec7&#xff1a;\u5982\u4f55\u7ed3\u6784\u5316\u5b58\u50a8\u6d77\u91cf\u4fe1\u606f<\/li>\n<li>\u957f\u671f\u4e0e\u77ed\u671f\u8bb0\u5fc6\u7684\u5e73\u8861&#xff1a;\u4e24\u8005\u5982\u4f55\u534f\u540c\u5de5\u4f5c<\/li>\n<h4>4.2 VectorStoreRetrieverMemory&#xff1a;\u5411\u91cf\u68c0\u7d22\u8bb0\u5fc6<\/h4>\n<p>LangChain\u63d0\u4f9b\u4e86VectorStoreRetrieverMemory&#xff0c;\u901a\u8fc7\u5411\u91cf\u6570\u636e\u5e93\u5b9e\u73b0\u6d77\u91cf\u5bf9\u8bdd\u7684\u6301\u4e45\u5316\u8bb0\u5fc6\u548c\u8bed\u4e49\u68c0\u7d22&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>memory <span class=\"token keyword\">import<\/span> VectorStoreRetrieverMemory<br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>vectorstores <span class=\"token keyword\">import<\/span> Chroma<br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>embeddings <span class=\"token keyword\">import<\/span> OpenAIEmbeddings<\/p>\n<p><span class=\"token comment\"># \u521d\u59cb\u5316\u5411\u91cf\u6570\u636e\u5e93<\/span><br \/>\nvectorstore <span class=\"token operator\">&#061;<\/span> Chroma<span class=\"token punctuation\">(<\/span><br \/>\n    embedding_function<span class=\"token operator\">&#061;<\/span>OpenAIEmbeddings<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    collection_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;agent_memory&#034;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u521b\u5efa\u68c0\u7d22\u5668<\/span><br \/>\nretriever <span class=\"token operator\">&#061;<\/span> vectorstore<span class=\"token punctuation\">.<\/span>as_retriever<span class=\"token punctuation\">(<\/span>search_kwargs<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;k&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u521b\u5efa\u5411\u91cf\u8bb0\u5fc6<\/span><br \/>\nmemory <span class=\"token operator\">&#061;<\/span> VectorStoreRetrieverMemory<span class=\"token punctuation\">(<\/span>retriever<span class=\"token operator\">&#061;<\/span>retriever<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u4fdd\u5b58\u8bb0\u5fc6&#xff08;\u81ea\u52a8\u5411\u91cf\u5316\u5b58\u50a8&#xff09;<\/span><br \/>\nmemory<span class=\"token punctuation\">.<\/span>save_context<span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;input&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;\u6211\u662f\u5f20\u4e09&#xff0c;\u4f4f\u5728\u5317\u4eac&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;output&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;\u597d\u7684&#xff0c;\u8bb0\u4f4f\u4e86&#034;<\/span><span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u52a0\u8f7d\u76f8\u5173\u8bb0\u5fc6&#xff08;\u8bed\u4e49\u68c0\u7d22&#xff09;<\/span><br \/>\n<span class=\"token builtin\">vars<\/span> <span class=\"token operator\">&#061;<\/span> memory<span class=\"token punctuation\">.<\/span>load_memory_variables<span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;input&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;\u6211\u5728\u54ea\u4e2a\u57ce\u5e02&#xff1f;&#034;<\/span><span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u8fd4\u56de&#xff1a;{&#034;history&#034;: &#034;\u7528\u6237\u4e4b\u524d\u8bf4\u4f4f\u5728\u5317\u4eac&#034;}<\/span><\/p>\n<p>\u6838\u5fc3\u539f\u7406&#xff1a;VectorStoreRetrieverMemory\u5c06\u8bb0\u5fc6\u5b58\u50a8\u5728VectorDB\u4e2d&#xff0c;\u6bcf\u6b21\u8c03\u7528\u65f6\u901a\u8fc7\u8bed\u4e49\u68c0\u7d22\u53ec\u56de\u6700\u76f8\u5173\u7684top-K\u6761\u8bb0\u5fc6\u3002\u8fd9\u79cd\u65b9\u5f0f\u5c06RAG\u7684\u601d\u60f3\u5e94\u7528\u5230\u4e86\u8bb0\u5fc6\u7ba1\u7406\u4e2d\u2014\u2014\u4e0d\u662f\u7b80\u5355\u5730\u628a\u6240\u6709\u5386\u53f2\u585e\u8fdb\u53bb&#xff0c;\u800c\u662f\u6309\u9700\u68c0\u7d22\u6700\u76f8\u5173\u7684\u5185\u5bb9\u3002<\/p>\n<h4>4.3 LangGraph\u7684\u957f\u671f\u8bb0\u5fc6Store<\/h4>\n<p>\u5728LangGraph\u4e2d&#xff0c;\u957f\u671f\u8bb0\u5fc6\u901a\u8fc7Store\u673a\u5236\u5b9e\u73b0&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> langgraph<span class=\"token punctuation\">.<\/span>store<span class=\"token punctuation\">.<\/span>memory <span class=\"token keyword\">import<\/span> InMemoryStore<\/p>\n<p><span class=\"token comment\"># \u521b\u5efa\u957f\u671f\u8bb0\u5fc6\u5b58\u50a8<\/span><br \/>\nstore <span class=\"token operator\">&#061;<\/span> InMemoryStore<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6309\u547d\u540d\u7a7a\u95f4\u5b58\u50a8\u8bb0\u5fc6<\/span><br \/>\nstore<span class=\"token punctuation\">.<\/span>put<span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;user_profile&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;user_123&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;name&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;\u5f20\u4e09&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;preferences&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;theme&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;dark&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;language&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;zh&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u68c0\u7d22\u8bb0\u5fc6<\/span><br \/>\nmemories <span class=\"token operator\">&#061;<\/span> store<span class=\"token punctuation\">.<\/span>search<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;user_profile&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;user_123&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>LangGraph\u7684Store\u652f\u6301\u81ea\u5b9a\u4e49\u547d\u540d\u7a7a\u95f4&#xff0c;\u8bb0\u5fc6\u53ef\u4ee5\u5728\u4e0d\u540c\u4f1a\u8bdd\u7ebf\u7a0b\u4e4b\u95f4\u5171\u4eab\u3002\u8fd9\u610f\u5473\u7740&#xff1a;\u7528\u6237\u4eca\u5929\u548cAgent\u804a\u4e86\u504f\u597d\u8bbe\u7f6e&#xff0c;\u660e\u5929\u6253\u5f00\u65b0\u4f1a\u8bdd&#xff0c;Agent\u4f9d\u7136\u80fd\u201c\u8bb0\u4f4f\u201d\u8fd9\u4e9b\u4fe1\u606f\u3002<\/p>\n<h4>4.4 \u957f\u671f\u8bb0\u5fc6\u7684\u5b58\u50a8\u9009\u578b<\/h4>\n<p>\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u957f\u671f\u8bb0\u5fc6\u7684\u5b58\u50a8\u6709\u591a\u79cd\u9009\u62e9&#xff1a;<\/p>\n<table>\n<tr>\u5b58\u50a8\u65b9\u6848\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u5173\u7cfb\u578b\u6570\u636e\u5e93&#xff08;PostgreSQL&#xff09;<\/td>\n<td>\u7ed3\u6784\u5316\u7528\u6237\u6863\u6848\u3001\u5386\u53f2\u8ba2\u5355\u7b49<\/td>\n<\/tr>\n<tr>\n<td>NoSQL&#xff08;MongoDB&#xff09;<\/td>\n<td>\u7075\u6d3b\u7684\u5bf9\u8bdd\u8bb0\u5f55\u3001\u975e\u7ed3\u6784\u5316\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>\u5411\u91cf\u6570\u636e\u5e93&#xff08;Chroma\/Pinecone&#xff09;<\/td>\n<td>\u8bed\u4e49\u68c0\u7d22\u3001\u76f8\u4f3c\u6027\u53ec\u56de<\/td>\n<\/tr>\n<tr>\n<td>Redis<\/td>\n<td>\u9ad8\u9891\u8bbf\u95ee\u7684\u77ed\u671f\u7f13\u5b58<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4e94\u3001\u6df7\u5408\u8bb0\u5fc6\u67b6\u6784&#xff1a;\u77ed\u671f&#043;\u957f\u671f\u534f\u540c\u5de5\u4f5c<\/h3>\n<p>\u751f\u4ea7\u7ea7\u7684Agent\u7cfb\u7edf\u901a\u5e38\u9700\u8981\u6df7\u5408\u8bb0\u5fc6\u67b6\u6784\u2014\u2014\u77ed\u671f\u8bb0\u5fc6\u8d1f\u8d23\u4f1a\u8bdd\u5185\u7684\u4e0a\u4e0b\u6587\u8fde\u8d2f\u6027&#xff0c;\u957f\u671f\u8bb0\u5fc6\u8d1f\u8d23\u8de8\u4f1a\u8bdd\u7684\u77e5\u8bc6\u79ef\u7d2f\u3002<\/p>\n<h4>5.1 \u67b6\u6784\u8bbe\u8ba1<\/h4>\n<p>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502                    Agent \u5e94\u7528\u5c42                      \u2502<br \/>\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524<br \/>\n\u2502                                                     \u2502<br \/>\n\u2502  \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510         \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510        \u2502<br \/>\n\u2502  \u2502  \u77ed\u671f\u8bb0\u5fc6\u5c42   \u2502         \u2502  \u957f\u671f\u8bb0\u5fc6\u5c42   \u2502        \u2502<br \/>\n\u2502  \u2502              \u2502         \u2502              \u2502        \u2502<br \/>\n\u2502  \u2502 BufferWindow \u2502\u25c4\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502 VectorStore  \u2502        \u2502<br \/>\n\u2502  \u2502 Summary      \u2502         \u2502 PostgreSQL   \u2502        \u2502<br \/>\n\u2502  \u2502 TokenBuffer  \u2502         \u2502 Redis        \u2502        \u2502<br \/>\n\u2502  \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518         \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518        \u2502<br \/>\n\u2502         \u2502                        \u2502                  \u2502<br \/>\n\u2502         \u25bc                        \u25bc                  \u2502<br \/>\n\u2502  \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510          \u2502<br \/>\n\u2502  \u2502         ChatMessageHistory           \u2502          \u2502<br \/>\n\u2502  \u2502    (\u53ef\u63d2\u62d4\u5b58\u50a8\u540e\u7aef&#xff1a;\u5185\u5b58\/Redis\/DB)    \u2502          \u2502<br \/>\n\u2502  \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518          \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/p>\n<h4>5.2 \u5b9e\u8df5\u793a\u4f8b&#xff1a;\u6df7\u5408\u8bb0\u5fc6\u7684\u7ec4\u88c5<\/h4>\n<p><span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>memory <span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">(<\/span><br \/>\n    ConversationBufferWindowMemory<span class=\"token punctuation\">,<\/span><br \/>\n    VectorStoreRetrieverMemory<br \/>\n<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>vectorstores <span class=\"token keyword\">import<\/span> Chroma<br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>embeddings <span class=\"token keyword\">import<\/span> OpenAIEmbeddings<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">HybridMemory<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u6df7\u5408\u8bb0\u5fc6&#xff1a;\u77ed\u671f\u7a97\u53e3\u8bb0\u5fc6 &#043; \u957f\u671f\u5411\u91cf\u68c0\u7d22\u8bb0\u5fc6&#034;&#034;&#034;<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> window_size<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> top_k<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># \u77ed\u671f\u8bb0\u5fc6&#xff1a;\u53ea\u4fdd\u7559\u6700\u8fd110\u8f6e\u5bf9\u8bdd<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>short_term <span class=\"token operator\">&#061;<\/span> ConversationBufferWindowMemory<span class=\"token punctuation\">(<\/span><br \/>\n            k<span class=\"token operator\">&#061;<\/span>window_size<span class=\"token punctuation\">,<\/span><br \/>\n            memory_key<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;recent_history&#034;<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\"># \u957f\u671f\u8bb0\u5fc6&#xff1a;\u5411\u91cf\u68c0\u7d22<\/span><br \/>\n        vectorstore <span class=\"token operator\">&#061;<\/span> Chroma<span class=\"token punctuation\">(<\/span><br \/>\n            embedding_function<span class=\"token operator\">&#061;<\/span>OpenAIEmbeddings<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            collection_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;long_term_memory&#034;<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><br \/>\n        retriever <span class=\"token operator\">&#061;<\/span> vectorstore<span class=\"token punctuation\">.<\/span>as_retriever<span class=\"token punctuation\">(<\/span>search_kwargs<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;k&#034;<\/span><span class=\"token punctuation\">:<\/span> top_k<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>long_term <span class=\"token operator\">&#061;<\/span> VectorStoreRetrieverMemory<span class=\"token punctuation\">(<\/span><br \/>\n            retriever<span class=\"token operator\">&#061;<\/span>retriever<span class=\"token punctuation\">,<\/span><br \/>\n            memory_key<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;long_term_context&#034;<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">load_memory_variables<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> inputs<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u52a0\u8f7d\u6df7\u5408\u8bb0\u5fc6&#034;&#034;&#034;<\/span><br \/>\n        short <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>short_term<span class=\"token punctuation\">.<\/span>load_memory_variables<span class=\"token punctuation\">(<\/span>inputs<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token builtin\">long<\/span> <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>long_term<span class=\"token punctuation\">.<\/span>load_memory_variables<span class=\"token punctuation\">(<\/span>inputs<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token operator\">**<\/span>short<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">**<\/span><span class=\"token builtin\">long<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">save_context<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> inputs<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">,<\/span> outputs<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u4fdd\u5b58\u5230\u4e24\u79cd\u8bb0\u5fc6&#034;&#034;&#034;<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>short_term<span class=\"token punctuation\">.<\/span>save_context<span class=\"token punctuation\">(<\/span>inputs<span class=\"token punctuation\">,<\/span> outputs<span class=\"token punctuation\">)<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>long_term<span class=\"token punctuation\">.<\/span>save_context<span class=\"token punctuation\">(<\/span>inputs<span class=\"token punctuation\">,<\/span> outputs<span class=\"token punctuation\">)<\/span><\/p>\n<h4>5.3 LangGraph\u7684Checkpointer&#xff1a;\u72b6\u6001\u6301\u4e45\u5316<\/h4>\n<p>\u5728LangGraph\u4e2d&#xff0c;\u77ed\u671f\u8bb0\u5fc6\u901a\u8fc7Checkpointer&#xff08;\u68c0\u67e5\u70b9\u4fdd\u5b58\u5668&#xff09; \u5b9e\u73b0\u6301\u4e45\u5316&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> langgraph<span class=\"token punctuation\">.<\/span>checkpoint<span class=\"token punctuation\">.<\/span>sqlite <span class=\"token keyword\">import<\/span> SqliteSaver<\/p>\n<p><span class=\"token comment\"># \u521b\u5efa\u68c0\u67e5\u70b9\u4fdd\u5b58\u5668&#xff08;\u6301\u4e45\u5316\u5230SQLite&#xff09;<\/span><br \/>\ncheckpointer <span class=\"token operator\">&#061;<\/span> SqliteSaver<span class=\"token punctuation\">.<\/span>from_conn_string<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;checkpoints.db&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u7f16\u8bd1\u56fe\u65f6\u4f20\u5165checkpointer<\/span><br \/>\ngraph <span class=\"token operator\">&#061;<\/span> builder<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">compile<\/span><span class=\"token punctuation\">(<\/span>checkpointer<span class=\"token operator\">&#061;<\/span>checkpointer<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6307\u5b9athread_id\u6062\u590d\u4f1a\u8bdd<\/span><br \/>\nconfig <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;configurable&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;thread_id&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;conversation_123&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">}<\/span><br \/>\nresult <span class=\"token operator\">&#061;<\/span> graph<span class=\"token punctuation\">.<\/span>invoke<span class=\"token punctuation\">(<\/span>inputs<span class=\"token punctuation\">,<\/span> config<span class=\"token operator\">&#061;<\/span>config<span class=\"token punctuation\">)<\/span><\/p>\n<p>Checkpointer\u7684\u5de5\u4f5c\u539f\u7406\u7c7b\u4f3c\u4e8e\u6e38\u620f\u5b58\u6863&#xff1a;\u6bcf\u5f53\u56fe\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\u6267\u884c\u5b8c\u6bd5\u540e&#xff0c;LangGraph\u4f1a\u81ea\u52a8\u628a\u5f53\u524d\u7684State&#xff08;\u5305\u62ec\u6d88\u606f\u5386\u53f2\u3001\u53d8\u91cf\u503c&#xff09;\u6253\u4e00\u4e2a\u5feb\u7167\u5e76\u5b58\u5165\u6570\u636e\u5e93\u3002\u901a\u8fc7thread_id&#xff0c;\u53ef\u4ee5\u968f\u65f6\u6062\u590d\u5230\u4efb\u610f\u65f6\u95f4\u70b9\u7684\u72b6\u6001\u3002<\/p>\n<h3>\u516d\u3001LangChain vs LangGraph&#xff1a;\u8bb0\u5fc6\u5b9e\u73b0\u7684\u5dee\u5f02<\/h3>\n<p>\u540c\u4e3aLangChain\u751f\u6001&#xff0c;LangChain\u548cLangGraph\u5728\u8bb0\u5fc6\u5b9e\u73b0\u4e0a\u8d70\u51fa\u4e86\u4e0d\u540c\u8def\u5f84&#xff1a;<\/p>\n<table>\n<tr>\u7ef4\u5ea6LangChainLangGraph<\/tr>\n<tbody>\n<tr>\n<td>\u5b9a\u4f4d<\/td>\n<td>\u901a\u7528\u5927\u6a21\u578b\u5e94\u7528\u6846\u67b6<\/td>\n<td>\u9762\u5411Agent\u7684\u4e13\u7528\u6846\u67b6<\/td>\n<\/tr>\n<tr>\n<td>\u8bb0\u5fc6\u65b9\u5f0f<\/td>\n<td>Memory\u7ec4\u4ef6&#xff08;\u5bf9\u8bdd\u5386\u53f2\u7ba1\u7406&#xff09;<\/td>\n<td>State &#043; Checkpointer&#xff08;\u72b6\u6001\u56fe\u7ba1\u7406&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u77ed\u671f\u8bb0\u5fc6<\/td>\n<td>\u5404\u7c7bBuffer\/Window\/Summary Memory<\/td>\n<td>State\u4e2d\u7684messages\u5b57\u6bb5 &#043; Checkpointer<\/td>\n<\/tr>\n<tr>\n<td>\u957f\u671f\u8bb0\u5fc6<\/td>\n<td>VectorStoreRetrieverMemory<\/td>\n<td>Store&#xff08;\u8de8\u7ebf\u7a0b\u547d\u540d\u7a7a\u95f4\u5b58\u50a8&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u72b6\u6001\u6062\u590d<\/td>\n<td>\u9700\u624b\u52a8\u7ba1\u7406<\/td>\n<td>\u901a\u8fc7thread_id\u81ea\u52a8\u6062\u590d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7b80\u5355\u6765\u8bf4&#xff1a;LangChain\u7684Memory\u662f\u201c\u9644\u52a0\u7684\u201d &#xff0c;\u4f60\u9700\u8981\u663e\u5f0f\u5730\u5c06Memory\u7ec4\u4ef6\u6302\u8f7d\u5230Chain\u4e0a&#xff1b;\u800cLangGraph\u7684\u8bb0\u5fc6\u662f\u201c\u5929\u7136\u7684\u201d &#xff0c;StateGraph\u672c\u8eab\u5c31\u6709\u72b6\u6001&#xff0c;Checkpointer\u8ba9\u8fd9\u79cd\u72b6\u6001\u53ef\u4ee5\u968f\u65f6\u4fdd\u5b58\u548c\u6062\u590d\u3002<\/p>\n<h3>\u4e03\u3001\u603b\u7ed3\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h3>\n<p>\u7ecf\u8fc7\u4ee5\u4e0a\u5206\u6790&#xff0c;\u6211\u603b\u7ed3\u4e86\u51e0\u6761\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u843d\u5730\u8bb0\u5fc6\u673a\u5236\u7684\u5b9e\u8df5\u7ecf\u9a8c&#xff1a;<\/p>\n<h4>7.1 \u9009\u578b\u5efa\u8bae<\/h4>\n<table>\n<tr>\u573a\u666f\u63a8\u8350\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>\u7b80\u5355\u95ee\u7b54\u673a\u5668\u4eba<\/td>\n<td>ConversationBufferWindowMemory&#xff08;k&#061;5~10&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u957f\u5bf9\u8bdd\u5ba2\u670d\u7cfb\u7edf<\/td>\n<td>ConversationSummaryMemory \u6216 ConversationSummaryBufferMemory<\/td>\n<\/tr>\n<tr>\n<td>Token\u654f\u611f\u573a\u666f<\/td>\n<td>ConversationTokenBufferMemory<\/td>\n<\/tr>\n<tr>\n<td>\u9700\u8981\u8de8\u4f1a\u8bdd\u8bb0\u5fc6<\/td>\n<td>VectorStoreRetrieverMemory &#043; \u5411\u91cf\u6570\u636e\u5e93<\/td>\n<\/tr>\n<tr>\n<td>\u590d\u6742Agent\u4efb\u52a1<\/td>\n<td>LangGraph &#043; Checkpointer &#043; Store<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>7.2 \u907f\u5751\u6307\u5357<\/h4>\n<li>\u4e0d\u8981\u628a\u6240\u6709\u5386\u53f2\u90fd\u585e\u8fdb\u53bb&#xff1a;\u5927\u6a21\u578b\u7684\u4e0a\u4e0b\u6587\u7a97\u53e3\u6709\u9650&#xff0c;\u8d85\u51fa\u9650\u5236\u4f1a\u89e6\u53d1\u622a\u65ad\u6216\u62a5\u9519\u3002<\/li>\n<li>\u77ed\u671f\u8bb0\u5fc6\u548c\u957f\u671f\u8bb0\u5fc6\u8981\u5206\u5de5&#xff1a;\u77ed\u671f\u8bb0\u201c\u521a\u624d\u8bf4\u4e86\u4ec0\u4e48\u201d&#xff0c;\u957f\u671f\u8bb0\u201c\u7528\u6237\u662f\u8c01\u3001\u504f\u597d\u4ec0\u4e48\u201d\u3002<\/li>\n<li>\u8bb0\u5fc6\u4e0eRAG\u8981\u533a\u5206&#xff1a;RAG\u7684\u672c\u8d28\u662f\u6309\u9700\u68c0\u7d22\u5916\u90e8\u9759\u6001\u77e5\u8bc6&#xff0c;\u5929\u7136\u65e0\u72b6\u6001&#xff1b;\u800c\u8bb0\u5fc6\u7cfb\u7edf\u5f3a\u8c03\u8de8\u4f1a\u8bdd\u7684\u72b6\u6001\u79ef\u7d2f\u3002<\/li>\n<li>\u751f\u4ea7\u73af\u5883\u52a1\u5fc5\u6301\u4e45\u5316&#xff1a;\u5f00\u53d1\u65f6\u7528InMemoryChatMessageHistory\u6ca1\u95ee\u9898&#xff0c;\u4e0a\u7ebf\u540e\u4e00\u5b9a\u8981\u6362\u6210Redis\u6216\u6570\u636e\u5e93\u540e\u7aef\u3002<\/li>\n<h4>7.3 \u6838\u5fc3 Takeaways<\/h4>\n<ul>\n<li>\u5927\u6a21\u578b\u662f\u65e0\u72b6\u6001\u7684&#xff0c;\u201c\u8bb0\u5fc6\u201d\u672c\u8d28\u662f\u5916\u90e8\u5b58\u50a8&#043;\u52a8\u6001\u62fc\u63a5<\/li>\n<li>LangChain\u7684BaseMemory\u5b9a\u4e49\u4e86\u8bb0\u5fc6\u7684\u8bfb\u5199\u63a5\u53e3&#xff0c;ChatMessageHistory\u5b9a\u4e49\u4e86\u5b58\u50a8\u540e\u7aef<\/li>\n<li>\u77ed\u671f\u8bb0\u5fc6\u6709\u56db\u79cd\u4e3b\u6d41\u5b9e\u73b0&#xff1a;\u5168\u91cf\u3001\u7a97\u53e3\u3001Token\u9650\u5236\u3001\u6458\u8981<\/li>\n<li>\u957f\u671f\u8bb0\u5fc6\u901a\u8fc7\u5411\u91cf\u68c0\u7d22\u6216LangGraph Store\u5b9e\u73b0\u8de8\u4f1a\u8bdd\u77e5\u8bc6\u590d\u7528<\/li>\n<li>\u6df7\u5408\u67b6\u6784\u624d\u662f\u751f\u4ea7\u7ea7Agent\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f<\/li>\n<\/ul>\n<p>\u8bb0\u5fc6\u673a\u5236\u662fAI Agent\u4ece\u201c\u73a9\u5177\u201d\u8d70\u5411\u201c\u5de5\u5177\u201d\u7684\u5173\u952e\u4e00\u6b65\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5e2e\u4f60\u5f7b\u5e95\u641e\u61c2LangChain\u751f\u6001\u4e2d\u7684\u8bb0\u5fc6\u8bbe\u8ba1&#xff0c;\u8ba9\u4f60\u7684Agent\u771f\u6b63\u544a\u522b\u201c\u91d1\u9c7c\u8111\u201d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00<br \/>\n\u5728\u6784\u5efaAI\u667a\u80fd\u4f53&#xff08;Agent&#xff09;\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u6211\u8e29\u8fc7\u6700\u6df1\u7684\u4e00\u4e2a\u5751\u5c31\u662f\u2014\u2014\u5927\u6a21\u578b\u662f\u4e2a\u201c\u91d1\u9c7c\u8111\u201d \u3002\u65e0\u8bba\u4f60\u4e0a\u4e00\u8f6e\u8ddf\u5b83\u804a\u4e86\u4ec0\u4e48&#xff0c;\u4e0b\u4e00\u8f6e\u5b83\u53ef\u80fd\u5c31\u5fd8\u5f97\u4e00\u5e72\u4e8c\u51c0\u3002<br \/>\n\u8fd9\u4e0d\u662f\u5927\u6a21\u578b\u7684\u201c\u6001\u5ea6\u95ee\u9898\u201d&#xff0c;\u800c\u662f\u5b83\u7684\u5e95\u5c42\u8bbe\u8ba1\u51b3\u5b9a\u7684&#xff1a;\u6240\u6709\u5927\u6a21\u578b\u672c\u8d28\u4e0a\u90fd\u662f\u201c\u65e0\u72b6\u6001\u201d\u7684\u2014\u2014\u5b83\u5bf9\u6bcf\u4e00\u6b21\u8bf7\u6c42\u7684\u5904\u7406\u90fd\u662f\u72ec\u7acb\u7684&#xff0c;\u4e0d\u4f1a\u4e3b\u52a8\u7559\u5b58\u4e0a\u4e00\u8f6e\u5bf9\u8bdd\u7684\u4efb\u4f55\u4fe1\u606f\u3002\u60f3\u8ba9\u5927\u6a21\u578b\u201c\u8bb0\u4f4f\u201d\u4e0a\u4e0b\u6587&#xff0c;\u672c\u8d28\u4e0a\u9700\u8981\u505a\u4e24\u4ef6\u4e8b&#xff1a;\u8bb0<\/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":[997,666,50],"topic":[],"class_list":["post-87792","post","type-post","status-publish","format-standard","hentry","category-server","tag-langchain","tag-microsoft","tag-50"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5927\u6a21\u578b\u201c\u91d1\u9c7c\u8111\u201d\u7ec8\u7ed3\u8005\uff01AI Agent\u77ed\u671f\u8bb0\u5fc6\u4e0e\u957f\u671f\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1\u53caLangChain\u72b6\u6001\u7ba1\u7406\u6e90\u7801\u5256\u6790 - \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\/87792.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5927\u6a21\u578b\u201c\u91d1\u9c7c\u8111\u201d\u7ec8\u7ed3\u8005\uff01AI Agent\u77ed\u671f\u8bb0\u5fc6\u4e0e\u957f\u671f\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1\u53caLangChain\u72b6\u6001\u7ba1\u7406\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00 \u5728\u6784\u5efaAI\u667a\u80fd\u4f53&#xff08;Agent&#xff09;\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u6211\u8e29\u8fc7\u6700\u6df1\u7684\u4e00\u4e2a\u5751\u5c31\u662f\u2014\u2014\u5927\u6a21\u578b\u662f\u4e2a\u201c\u91d1\u9c7c\u8111\u201d \u3002\u65e0\u8bba\u4f60\u4e0a\u4e00\u8f6e\u8ddf\u5b83\u804a\u4e86\u4ec0\u4e48&#xff0c;\u4e0b\u4e00\u8f6e\u5b83\u53ef\u80fd\u5c31\u5fd8\u5f97\u4e00\u5e72\u4e8c\u51c0\u3002 \u8fd9\u4e0d\u662f\u5927\u6a21\u578b\u7684\u201c\u6001\u5ea6\u95ee\u9898\u201d&#xff0c;\u800c\u662f\u5b83\u7684\u5e95\u5c42\u8bbe\u8ba1\u51b3\u5b9a\u7684&#xff1a;\u6240\u6709\u5927\u6a21\u578b\u672c\u8d28\u4e0a\u90fd\u662f\u201c\u65e0\u72b6\u6001\u201d\u7684\u2014\u2014\u5b83\u5bf9\u6bcf\u4e00\u6b21\u8bf7\u6c42\u7684\u5904\u7406\u90fd\u662f\u72ec\u7acb\u7684&#xff0c;\u4e0d\u4f1a\u4e3b\u52a8\u7559\u5b58\u4e0a\u4e00\u8f6e\u5bf9\u8bdd\u7684\u4efb\u4f55\u4fe1\u606f\u3002\u60f3\u8ba9\u5927\u6a21\u578b\u201c\u8bb0\u4f4f\u201d\u4e0a\u4e0b\u6587&#xff0c;\u672c\u8d28\u4e0a\u9700\u8981\u505a\u4e24\u4ef6\u4e8b&#xff1a;\u8bb0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/87792.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-30T13:48:29+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\/87792.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/87792.html\",\"name\":\"\u5927\u6a21\u578b\u201c\u91d1\u9c7c\u8111\u201d\u7ec8\u7ed3\u8005\uff01AI Agent\u77ed\u671f\u8bb0\u5fc6\u4e0e\u957f\u671f\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1\u53caLangChain\u72b6\u6001\u7ba1\u7406\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-30T13:48:29+00:00\",\"dateModified\":\"2026-07-30T13:48:29+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/87792.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/87792.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/87792.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5927\u6a21\u578b\u201c\u91d1\u9c7c\u8111\u201d\u7ec8\u7ed3\u8005\uff01AI Agent\u77ed\u671f\u8bb0\u5fc6\u4e0e\u957f\u671f\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1\u53caLangChain\u72b6\u6001\u7ba1\u7406\u6e90\u7801\u5256\u6790\"}]},{\"@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":"\u5927\u6a21\u578b\u201c\u91d1\u9c7c\u8111\u201d\u7ec8\u7ed3\u8005\uff01AI Agent\u77ed\u671f\u8bb0\u5fc6\u4e0e\u957f\u671f\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1\u53caLangChain\u72b6\u6001\u7ba1\u7406\u6e90\u7801\u5256\u6790 - \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\/87792.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5927\u6a21\u578b\u201c\u91d1\u9c7c\u8111\u201d\u7ec8\u7ed3\u8005\uff01AI Agent\u77ed\u671f\u8bb0\u5fc6\u4e0e\u957f\u671f\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1\u53caLangChain\u72b6\u6001\u7ba1\u7406\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00 \u5728\u6784\u5efaAI\u667a\u80fd\u4f53&#xff08;Agent&#xff09;\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u6211\u8e29\u8fc7\u6700\u6df1\u7684\u4e00\u4e2a\u5751\u5c31\u662f\u2014\u2014\u5927\u6a21\u578b\u662f\u4e2a\u201c\u91d1\u9c7c\u8111\u201d \u3002\u65e0\u8bba\u4f60\u4e0a\u4e00\u8f6e\u8ddf\u5b83\u804a\u4e86\u4ec0\u4e48&#xff0c;\u4e0b\u4e00\u8f6e\u5b83\u53ef\u80fd\u5c31\u5fd8\u5f97\u4e00\u5e72\u4e8c\u51c0\u3002 \u8fd9\u4e0d\u662f\u5927\u6a21\u578b\u7684\u201c\u6001\u5ea6\u95ee\u9898\u201d&#xff0c;\u800c\u662f\u5b83\u7684\u5e95\u5c42\u8bbe\u8ba1\u51b3\u5b9a\u7684&#xff1a;\u6240\u6709\u5927\u6a21\u578b\u672c\u8d28\u4e0a\u90fd\u662f\u201c\u65e0\u72b6\u6001\u201d\u7684\u2014\u2014\u5b83\u5bf9\u6bcf\u4e00\u6b21\u8bf7\u6c42\u7684\u5904\u7406\u90fd\u662f\u72ec\u7acb\u7684&#xff0c;\u4e0d\u4f1a\u4e3b\u52a8\u7559\u5b58\u4e0a\u4e00\u8f6e\u5bf9\u8bdd\u7684\u4efb\u4f55\u4fe1\u606f\u3002\u60f3\u8ba9\u5927\u6a21\u578b\u201c\u8bb0\u4f4f\u201d\u4e0a\u4e0b\u6587&#xff0c;\u672c\u8d28\u4e0a\u9700\u8981\u505a\u4e24\u4ef6\u4e8b&#xff1a;\u8bb0","og_url":"https:\/\/www.wsisp.com\/helps\/87792.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-30T13:48:29+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\/87792.html","url":"https:\/\/www.wsisp.com\/helps\/87792.html","name":"\u5927\u6a21\u578b\u201c\u91d1\u9c7c\u8111\u201d\u7ec8\u7ed3\u8005\uff01AI Agent\u77ed\u671f\u8bb0\u5fc6\u4e0e\u957f\u671f\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1\u53caLangChain\u72b6\u6001\u7ba1\u7406\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-30T13:48:29+00:00","dateModified":"2026-07-30T13:48:29+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/87792.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/87792.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/87792.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5927\u6a21\u578b\u201c\u91d1\u9c7c\u8111\u201d\u7ec8\u7ed3\u8005\uff01AI Agent\u77ed\u671f\u8bb0\u5fc6\u4e0e\u957f\u671f\u8bb0\u5fc6\u673a\u5236\u8bbe\u8ba1\u53caLangChain\u72b6\u6001\u7ba1\u7406\u6e90\u7801\u5256\u6790"}]},{"@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\/87792","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=87792"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/87792\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=87792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=87792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=87792"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=87792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}