{"id":3869,"date":"2026-08-22T16:52:47","date_gmt":"2026-08-22T08:52:47","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=3869"},"modified":"2026-08-22T16:52:47","modified_gmt":"2026-08-22T08:52:47","slug":"%e5%88%ab%e5%86%8d%e4%b9%b1%e5%ad%98-agent-%e6%95%b0%e6%8d%ae%ef%bc%81state-store-context-%e5%ba%95%e5%b1%82%e9%80%bb%e8%be%91-%e5%ae%9e%e6%88%98%e8%90%bd%e5%9c%b0","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3869","title":{"rendered":"\u522b\u518d\u4e71\u5b58 Agent \u6570\u636e\uff01State\/Store\/Context \u5e95\u5c42\u903b\u8f91 + \u5b9e\u6218\u843d\u5730"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\">\u4e0a\u7bc7\u4f60\u628a\u79c1\u53a8 Demo \u62fc\u8d77\u6765\u4e86\u2014\u2014\u770b\u56fe\u3001\u5de5\u5177\u3001\u4f1a\u8bdd\u8bb0\u5fc6\u90fd\u80fd\u8dd1\u3002\u53ef\u300c\u8fd9\u901a\u5bf9\u8bdd\u7684\u8ba1\u6570\u300d\u300c\u8de8\u4f1a\u8bdd\u7684\u996e\u54c1\u504f\u597d\u300d\u300c\u5f53\u524d\u767b\u5f55\u7528\u6237\u662f\u8c01\u300d\u5e38\u88ab\u63c9\u8fdb\u540c\u4e00\u4e2a list\u3002\u8fd9\u7bc7\u8bb2 Runtime \u4e09\u4ef6\u5957\uff1a<strong>State \/ Store \/ Context<\/strong>\uff0c\u5e76\u5728 Tool \u91cc\u6b63\u786e\u8bbf\u95ee\u5b83\u4eec\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u5c0f\u660e\u628a\u4e09\u79cd\u300c\u8bb0\u4f4f\u300d\u6df7\u6210\u4e00\u9505<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u79c1\u53a8\u4e0a\u7ebf\u8bd5\u73a9\u540e\uff0c\u4ea7\u54c1\u53c8\u63d0\u9700\u6c42\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">1)\u00a0\u672c\u4f1a\u8bdd\u70b9\u4e86\u51e0\u6b21\u300c\u6362\u4e00\u9053\u300d\u2192\u00a0\u663e\u793a\u00a0visit_count\n2)\u00a0\u7528\u6237\u559c\u6b22\u5c11\u6cb9\u00a0\u2192\u00a0\u6362\u4e2a\u00a0thread\u00a0\u8fd8\u8981\u8bb0\u5f97\n3)\u00a0\u540c\u4e00\u5957\u00a0Agent\u00a0\u670d\u52a1\u5c0f\u660e\u548c\u5c0f\u534e\u00a0\u2192\u00a0\u522b\u4e32\u6863\u6848\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\u5168\u5f80 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">ConversationMemory<\/code> \u91cc\u585e\u3002\u6362 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">thread_id<\/code> \u540e\u504f\u597d\u4e22\u4e86\uff1b\u4e0d\u6362 thread\uff0c\u4e24\u4e2a\u7528\u6237\u7684\u5fcc\u53e3\u53c8\u4e32\u4e86\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4ed6\u53bb\u627e\u8001\u5f20\uff1a&#8221;\u90fd\u662f\u8bb0\u5fc6\uff0c\u4e3a\u5565\u4e0d\u80fd\u4e00\u4e2a list \u641e\u5b9a\uff1f&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u56e0\u4e3a\u751f\u547d\u5468\u671f\u4e0d\u4e00\u6837\u3002Runtime \u4e09\u4ef6\u5957\u5404\u7ba1\u4e00\u6bb5\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">State\u00a0\u00a0\u00a0=\u00a0\u8fd9\u901a\u7535\u8bdd\u804a\u5230\u54ea\uff08\u542b\u672c\u8f6e\u4efb\u52a1\u5b57\u6bb5\uff09\nStore\u00a0\u00a0\u00a0=\u00a0\u5ba2\u6237\u6863\u6848\u67dc\uff08\u8de8\u7535\u8bdd\u7ebf\u8fd8\u80fd\u67e5\uff09\nContext\u00a0=\u00a0\u8fd9\u6b21\u662f\u8c01\u6253\u8fdb\u6765\u7684\uff08user_id\u00a0\u7b49\u914d\u7f6e\uff09\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;<\/p>\n<hr \/>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4ec0\u4e48\u662f Runtime \u4e09\u5206\u6cd5<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u538b\u6210\u4e00\u5f20\u8868\uff1a<\/p>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all;\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u6982\u5ff5<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u8bf4\u660e<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u751f\u547d\u5468\u671f<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u5de5\u5177\u91cc\u600e\u4e48\u62ff<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><strong>State<\/strong><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u77ed\u671f\uff1a<code>messages<\/code> + \u81ea\u5b9a\u4e49\u5b57\u6bb5<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5355 <code>thread_id<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><code>runtime.state<\/code> \/ <code>Command<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><strong>Store<\/strong><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u957f\u671f\uff1a\u504f\u597d\u3001\u53ef\u68c0\u7d22\u7b14\u8bb0<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><strong>\u8de8\u4f1a\u8bdd \/ \u8de8 thread<\/strong><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><code>runtime.store.get\/put\/search<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><strong>Context<\/strong><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u672c\u6b21\u8c03\u7528\u914d\u7f6e\uff08\u5982\u767b\u5f55\u7528\u6237\uff09<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5355\u6b21\u8bf7\u6c42<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><code>runtime.context<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">invoke(messages,\u00a0config.thread_id,\u00a0context=user_id)\n\u00a0\u00a0\u00a0\u00a0\u2502\n\u00a0\u00a0\u00a0\u00a0\u251c\u2500\u25ba\u00a0State\uff08\u672c\u00a0thread\u00a0\u6d88\u606f\u4e0e\u8ba1\u6570\uff09\n\u00a0\u00a0\u00a0\u00a0\u251c\u2500\u25ba\u00a0Context\uff08\u8fd9\u6b21\u662f\u8c01\uff09\n\u00a0\u00a0\u00a0\u00a0\u2514\u2500\u25ba\u00a0Store\uff08\u957f\u671f\u6863\u6848\u00a0\/\u00a0\u5411\u91cf\u7b14\u8bb0\uff09\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u25b2\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2502\u00a0\u5de5\u5177\u7ecf\u00a0ToolRuntime\u00a0\u8bfb\u5199\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;\u6bd4\u55bb\uff1a<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>State = \u767d\u677f\uff08\u8fd9\u8282\u8bfe\u5199\u6ee1\uff0c\u4e0b\u8bfe\u53ef\u64e6\uff0c\u540c\u6559\u5ba4\u7eed\u5199\u9760 thread\uff09<\/section>\n<\/li>\n<li>\n<section>Store = \u6863\u6848\u5ba4\uff08\u6362\u6559\u5ba4\u8fd8\u80fd\u501f\u9605\uff09<\/section>\n<\/li>\n<li>\n<section>Context = \u5de5\u724c\uff08\u544a\u8bc9\u5de5\u5177\u73b0\u5728\u63a5\u5f85\u7684\u662f\u54ea\u4f4d\u5ba2\u6237\uff09&#8221;<\/section>\n<\/li>\n<\/ul>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all; height: 204px;\" width=\"691\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u9700\u6c42<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u8be5\u653e\u54ea<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u300c\u6211\u53eb\u4ec0\u4e48\uff1f\u300d\u540c\u4f1a\u8bdd\u8ffd\u95ee<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">State.messages<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u672c\u4f1a\u8bdd visit_count<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">State \u81ea\u5b9a\u4e49\u5b57\u6bb5<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u300c\u559c\u6b22\u9f99\u4e95\u300d\u6362\u4f1a\u8bdd\u4ecd\u5728<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Store<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u6309\u300c\u559d\u8336\u548c\u897f\u6e56\u300d\u8bed\u4e49\u641c\u7b14\u8bb0<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Store + \u5411\u91cf index<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u533a\u5206 user_xiao \/ user_hua<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Context.user_id<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4ee3\u7801\u62c6\u89e3\uff1aState \u2192 Store \u2192 Context<\/span><\/h2>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">1. State\uff1a\u81ea\u5b9a\u4e49\u77ed\u671f\u5b57\u6bb5<\/h3>\n<p style=\"margin: 1em 0px;\">\u9ed8\u8ba4 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">AgentState<\/code> \u4e3b\u8981\u662f <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">messages<\/code>\u3002\u8981\u8bb0\u300c\u4f1a\u8bdd\u5f00\u59cb\u65f6\u95f4\u3001\u8bbf\u95ee\u6b21\u6570\u300d\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">class<\/span>\u00a0<span class=\"hljs-title class_\" style=\"color: #b58900;\">CustomState<\/span>(<span class=\"hljs-title class_ inherited__\" style=\"color: #859900;\">AgentState<\/span>):\n\u00a0\u00a0session_start:\u00a0NotRequired[<span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span>]\n\u00a0\u00a0visit_count:\u00a0NotRequired[<span class=\"hljs-built_in\" style=\"color: #2aa198;\">int<\/span>]\n\u00a0\u00a0model_call_count:\u00a0NotRequired[<span class=\"hljs-built_in\" style=\"color: #2aa198;\">int<\/span>]\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u521b\u5efa\u65f6\u6302\u4e0a\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span>\u00a0create_agent(\n\u00a0\u00a0get_chat_model(),\n\u00a0\u00a0tools=CUSTOM_TOOLS,\n\u00a0\u00a0system_prompt=<span class=\"hljs-string\" style=\"color: #859900;\">\"\u2026\u2026\"<\/span>,\n\u00a0\u00a0state_schema=CustomState,\n\u00a0\u00a0checkpointer=InMemorySaver(),\n)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5de5\u5177\u91cc\u8bfb \/ \u5199\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-meta\" style=\"color: #d33682;\">@tool<\/span>\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span>\u00a0<span class=\"hljs-title function_\" style=\"color: #268bd2;\">get_session_info<\/span>(<span class=\"hljs-params\">runtime:\u00a0ToolRuntime<\/span>)\u00a0-&gt;\u00a0<span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span>:\n\u00a0\u00a0state\u00a0=\u00a0runtime.state\n\u00a0\u00a0<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span>\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">f\"session_start=<span class=\"hljs-subst\" style=\"color: #93a1a1;\">{state.get(<span class=\"hljs-string\" style=\"color: #859900;\">'session_start'<\/span>)}<\/span>;\u00a0visit_count=<span class=\"hljs-subst\" style=\"color: #93a1a1;\">{...}<\/span>\"<\/span>\n\n<span class=\"hljs-meta\" style=\"color: #d33682;\">@tool<\/span>\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span>\u00a0<span class=\"hljs-title function_\" style=\"color: #268bd2;\">bump_visit<\/span>(<span class=\"hljs-params\">runtime:\u00a0ToolRuntime<\/span>)\u00a0-&gt;\u00a0Command:\n\u00a0\u00a0count\u00a0=\u00a0<span class=\"hljs-built_in\" style=\"color: #2aa198;\">int<\/span>(runtime.state.get(<span class=\"hljs-string\" style=\"color: #859900;\">\"visit_count\"<\/span>)\u00a0<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">or<\/span>\u00a0<span class=\"hljs-number\" style=\"color: #cb4b16;\">0<\/span>)\u00a0+\u00a0<span class=\"hljs-number\" style=\"color: #cb4b16;\">1<\/span>\n\u00a0\u00a0<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span>\u00a0Command(update={<span class=\"hljs-string\" style=\"color: #859900;\">\"visit_count\"<\/span>:\u00a0count,\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"messages\"<\/span>:\u00a0[...]})\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;<strong><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">runtime<\/code> \u662f\u6846\u67b6\u6ce8\u5165\u53c2\u6570<\/strong>\uff0c\u6a21\u578b\u770b\u4e0d\u89c1\uff1b\u4e1a\u52a1\u53c2\u6570\u522b\u53eb\u8fd9\u4e2a\u540d\u3002\u5199\u56de\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">Command(update=...)<\/code>\u3002&#8221;<\/p>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">2. Store\uff1a\u8de8 thread \u7684\u957f\u671f\u8bb0\u5fc6<\/h3>\n<p style=\"margin: 1em 0px;\">\u952e\u503c\u7ed3\u6784\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">namespace<\/code> + <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">key<\/code> + JSON <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">value<\/code>\u3002<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">USERS_NS\u00a0=\u00a0(<span class=\"hljs-string\" style=\"color: #859900;\">\"users\"<\/span>,)\n\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span>\u00a0<span class=\"hljs-title function_\" style=\"color: #268bd2;\">make_store<\/span>()\u00a0-&gt;\u00a0InMemoryStore:\n\u00a0\u00a0<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span>\u00a0InMemoryStore()\n\n<span class=\"hljs-comment\" style=\"color: #657b83;\">#\u00a0\u9884\u7f6e<\/span>\nstore.put(USERS_NS,\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"user_xiao\"<\/span>,\u00a0{<span class=\"hljs-string\" style=\"color: #859900;\">\"name\"<\/span>:\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"\u5c0f\u660e\"<\/span>,\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"drink\"<\/span>:\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"\u9f99\u4e95\u8336\"<\/span>})\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">Agent \u6ce8\u5165\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span>\u00a0<span class=\"hljs-title function_\" style=\"color: #268bd2;\">build_agent<\/span>(<span class=\"hljs-params\">*,\u00a0store:\u00a0BaseStore<\/span>):\n\u00a0\u00a0<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span>\u00a0create_agent(\n\u00a0\u00a0\u00a0\u00a0get_chat_model(),\n\u00a0\u00a0\u00a0\u00a0tools=PROFILE_TOOLS,\n\u00a0\u00a0\u00a0\u00a0system_prompt=<span class=\"hljs-string\" style=\"color: #859900;\">\"\u9700\u8981\u7528\u6237\u6863\u6848\u65f6\u8c03\u7528\u00a0get_user_profile\uff1b\u2026\u2026\"<\/span>,\n\u00a0\u00a0\u00a0\u00a0store=store,\n\u00a0\u00a0\u00a0\u00a0context_schema=Context,\n\u00a0\u00a0\u00a0\u00a0checkpointer=InMemorySaver(),\n\u00a0\u00a0)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5de5\u5177\u7ecf <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">runtime.store<\/code> + <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">runtime.context.user_id<\/code>\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-meta\" style=\"color: #d33682;\">@tool<\/span>\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span>\u00a0<span class=\"hljs-title function_\" style=\"color: #268bd2;\">get_user_profile<\/span>(<span class=\"hljs-params\">runtime:\u00a0ToolRuntime[Context]<\/span>)\u00a0-&gt;\u00a0<span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span>:\n\u00a0\u00a0user_id\u00a0=\u00a0runtime.context.user_id\n\u00a0\u00a0item\u00a0=\u00a0runtime.store.get(USERS_NS,\u00a0user_id)\n\u00a0\u00a0...\n\n<span class=\"hljs-meta\" style=\"color: #d33682;\">@tool<\/span>\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span>\u00a0<span class=\"hljs-title function_\" style=\"color: #268bd2;\">save_user_profile<\/span>(<span class=\"hljs-params\">name:\u00a0<span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span>,\u00a0drink:\u00a0<span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span>,\u00a0runtime:\u00a0ToolRuntime[Context]<\/span>)\u00a0-&gt;\u00a0<span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span>:\n\u00a0\u00a0user_id\u00a0=\u00a0runtime.context.user_id\n\u00a0\u00a0runtime.store.put(USERS_NS,\u00a0user_id,\u00a0{<span class=\"hljs-string\" style=\"color: #859900;\">\"name\"<\/span>:\u00a0name,\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"drink\"<\/span>:\u00a0drink})\n\u00a0\u00a0<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span>\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">f\"\u5df2\u4fdd\u5b58\u6863\u6848\u00a0user_id=<span class=\"hljs-subst\" style=\"color: #93a1a1;\">{user_id}<\/span>:\u00a0...\"<\/span>\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;Demo B \u7684\u6545\u4e8b\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">thread-1<\/code> \u5199\u5165\u504f\u597d \u2192 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">thread-2<\/code> \u6362\u77ed\u671f\u4f1a\u8bdd \u2192 \u540c\u4e00 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">Context(user_id=...)<\/code> \u4ecd\u80fd\u8bfb\u51fa\u6863\u6848\u3002\u8fd9\u5c31\u662f Store \u76f8\u5bf9 State \u7684\u4ef7\u503c\u3002&#8221;<\/p>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">3. \u5411\u91cf Store\uff1a\u8bed\u4e49\u68c0\u7d22\u957f\u671f\u7b14\u8bb0<\/h3>\n<p style=\"margin: 1em 0px;\">\u5bfc\u56fe\uff1a\u6587\u5b57\u2192\u5411\u91cf\uff0c\u76f8\u8fd1\u542b\u4e49\u5728\u7a7a\u95f4\u4e2d\u66f4\u8fd1\u3002\u8bfe\u4ef6\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">text-embedding-v4<\/code>\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span>\u00a0<span class=\"hljs-title function_\" style=\"color: #268bd2;\">make_vector_store<\/span>()\u00a0-&gt;\u00a0InMemoryStore:\n\u00a0\u00a0<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span>\u00a0InMemoryStore(\n\u00a0\u00a0\u00a0\u00a0index={\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"dims\"<\/span>:\u00a0EMBED_DIMS,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"embed\"<\/span>:\u00a0embed_texts,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"fields\"<\/span>:\u00a0[<span class=\"hljs-string\" style=\"color: #859900;\">\"text\"<\/span>],\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0)\n<\/code><\/pre>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-meta\" style=\"color: #d33682;\">@tool<\/span>\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span>\u00a0<span class=\"hljs-title function_\" style=\"color: #268bd2;\">search_memories<\/span>(<span class=\"hljs-params\">query:\u00a0<span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span>,\u00a0runtime:\u00a0ToolRuntime[Context]<\/span>)\u00a0-&gt;\u00a0<span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span>:\n\u00a0\u00a0hits\u00a0=\u00a0runtime.store.search(MEMORIES_NS,\u00a0query=query,\u00a0limit=<span class=\"hljs-number\" style=\"color: #cb4b16;\">2<\/span>)\n\u00a0\u00a0...\n<\/code><\/pre>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">4. Context\uff1a\u672c\u6b21\u662f\u8c01<\/h3>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-meta\" style=\"color: #d33682;\">@dataclass<\/span>\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">class<\/span>\u00a0<span class=\"hljs-title class_\" style=\"color: #b58900;\">Context<\/span>:\n\u00a0\u00a0user_id:\u00a0<span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span>\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u8c03\u7528\u65f6\u4f20\u5165\uff08\u4e0e thread \u5206\u5f00\uff09\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">agent.invoke(\n\u00a0\u00a0{<span class=\"hljs-string\" style=\"color: #859900;\">\"messages\"<\/span>:\u00a0[{<span class=\"hljs-string\" style=\"color: #859900;\">\"role\"<\/span>:\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"user\"<\/span>,\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"content\"<\/span>:\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"\u6211\u7684\u6863\u6848\u91cc\u5199\u4e86\u4ec0\u4e48\uff1f\"<\/span>}]},\n\u00a0\u00a0{<span class=\"hljs-string\" style=\"color: #859900;\">\"configurable\"<\/span>:\u00a0{<span class=\"hljs-string\" style=\"color: #859900;\">\"thread_id\"<\/span>:\u00a0<span class=\"hljs-string\" style=\"color: #859900;\">\"day10-a\"<\/span>}},\n\u00a0\u00a0context=Context(user_id=<span class=\"hljs-string\" style=\"color: #859900;\">\"user_xiao\"<\/span>),\n)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;\u5bfc\u56fe\u4f8b\u5b50\uff1a\u7528\u6237\u5148\u767b\u5f55\u518d\u8bbf\u95ee Agent\u2014\u2014\u767b\u5f55\u8eab\u4efd\u8fdb Context\uff0c\u5de5\u5177\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">runtime.context<\/code> \u53d6\uff0c\u518d\u53bb Store \u91cc\u6309 user_id \u53d6\u6863\u6848\u3002<strong>\u522b\u628a user_id \u53ea\u5199\u5728\u67d0\u53e5\u804a\u5929\u91cc\u78b0\u8fd0\u6c14\u3002<\/strong>&#8220;<\/p>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\u590d\u8ff0\uff1a&#8221;State \u7ba1\u8fd9\u901a\uff1bStore \u7ba1\u6863\u6848\uff1bContext \u7ba1\u5de5\u724c\uff1b\u5de5\u5177\u7edf\u4e00\u8d70 ToolRuntime\u3002&#8221;<\/p>\n<hr \/>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u603b\u7ed3<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u7b2c\u4e5d\u7bc7\u53ea\u529e\u4e00\u4ef6\u4e8b\u2014\u2014\u628a\u4e09\u79cd\u300e\u8bb0\u4f4f\u300f\u62c6\u5f00\u3002&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">&#8220;\u4e09\u4e2a\u6838\u5fc3\u7406\u89e3\uff1a<\/p>\n<ol style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: decimal;\">\n<li>\n<section><strong>State<\/strong> \u2014\u2014 \u672c\u4f1a\u8bdd\u6d88\u606f\u4e0e\u4efb\u52a1\u5b57\u6bb5\uff1b<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">state_schema<\/code> + <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">runtime.state<\/code><\/section>\n<\/li>\n<li>\n<section><strong>Store<\/strong> \u2014\u2014 \u8de8\u4f1a\u8bdd\u952e\u503c \/ \u5411\u91cf\uff1b<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">store=<\/code> + <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">runtime.store<\/code><\/section>\n<\/li>\n<li>\n<section><strong>Context<\/strong> \u2014\u2014 \u672c\u6b21\u5de5\u724c\uff1b<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">context_schema<\/code> + <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">runtime.context<\/code>&#8220;<\/section>\n<\/li>\n<\/ol>\n<p style=\"margin: 1em 0px;\">LangChain \u652f\u7ebf\u8fdb\u5ea6\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\u2026\u00a0\u2192\u00a0AI\u00a0\u79c1\u53a8\u5b9e\u6218\n\u00a0\u00a0\u00a0\u00a0\u2193\nRuntime\uff1aState\u00a0\/\u00a0Store\u00a0\/\u00a0Context\uff08\u672c\u7bc7\uff09\n\u00a0\u00a0\u00a0\u00a0\u2193\nMiddleware\u00a0\u2192\u00a0\u591a\u00a0Agent\u00a0\u2192\u00a0Agentic\u00a0RAG\u00a0\u2026\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\u8bf4\uff1a&#8221;\u4e0b\u4e00\u7bc7\u8be5\u770b\u4e2d\u95f4\u4ef6\u4e86\u2014\u2014\u5728\u6a21\u578b\u8c03\u7528\u524d\u540e\u6302\u94a9\u5b50\uff0c\u505a\u9650\u6d41\u3001\u6458\u8981\u3001\u8131\u654f\u3002&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">&#8220;\u5bf9\u3002\u4e0b\u4e00\u7bc7\uff1a<strong>Middleware<\/strong>\u3002&#8221;<\/p>\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\"><strong>Runtime \u4e09\u5206\u6cd5\uff1a\u767d\u677f\u8bb0\u8fd9\u901a\uff0c\u6863\u6848\u67dc\u8bb0\u957f\u671f\uff0c\u5de5\u724c\u6807\u660e\u6b64\u523b\u662f\u8c01\u3002\u6df7\u7528\u4e00\u4e2a list\uff0c\u4e0d\u662f\u7701\u4e8b\uff0c\u662f\u57cb\u96f7\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u7bc7\u4f60\u628a\u79c1\u53a8 Demo \u62fc\u8d77\u6765\u4e86\u2014\u2014\u770b\u56fe\u3001\u5de5\u5177\u3001\u4f1a\u8bdd\u8bb0\u5fc6\u90fd\u80fd\u8dd1\u3002\u53ef\u300c\u8fd9\u901a\u5bf9\u8bdd\u7684\u8ba1\u6570\u300d\u300c\u8de8\u4f1a\u8bdd\u7684\u996e\u54c1\u504f\u597d\u300d\u300c\u5f53\u524d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3870,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[163,165],"tags":[167,168,170],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3869"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3869"}],"version-history":[{"count":1,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3869\/revisions"}],"predecessor-version":[{"id":3871,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3869\/revisions\/3871"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/media\/3870"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}