{"id":3889,"date":"2026-08-29T07:34:37","date_gmt":"2026-08-28T23:34:37","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=3889"},"modified":"2026-08-29T07:34:37","modified_gmt":"2026-08-28T23:34:37","slug":"langgraph-%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5%ef%bc%9astate%e3%80%81node%e3%80%81edge-%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3889","title":{"rendered":"LangGraph \u57fa\u672c\u6982\u5ff5\uff1aState\u3001Node\u3001Edge \u5165\u95e8"},"content":{"rendered":"<section id=\"wenyan\" data-provider=\"WenYan\" style=\"font-family: system-ui, &quot;Apple Color Emoji&quot;, &quot;Segoe UI&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Sans&quot;, Roboto, sans-serif; word-break: break-word; overflow-wrap: break-word; color: rgb(0, 0, 0); font-size: 16px; line-height: 1.75; caret-color: rgb(0, 0, 0);\">\n<blockquote style=\"color: rgb(85, 85, 85); background-color: rgb(255, 249, 235); background-image: none; padding: 16px 20px; margin: 20px 0px; border-width: 0px 0px 0px 4px; border-style: none none none solid; border-color: currentcolor currentcolor currentcolor rgb(248, 180, 63); border-radius: 6px; font-style: normal; quotes: none;\">\n<p style=\"margin: 0.55em 0px; color: rgb(85, 85, 85); text-indent: 0px; padding: 0px; line-height: 1.75; font-style: normal; background: transparent;\">\u4e0a\u7bc7\u4f60\u641e\u6e05\u4e86\u300c\u4e3a\u4f55\u8981 Graph\u300d\u548c\u9009\u578b\u4e09\u53e5\u8bdd\u3002\u8fd9\u7bc7\u662f <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">LangGraph \u4e13\u9898\u7b2c 02 \u7bc7<\/strong>\u2014\u2014\u628a\u4e09\u8981\u7d20\u5199\u8fdb\u4ee3\u7801\uff1a\u7ebf\u6027\u56fe \u2192 \u6761\u4ef6\u8fb9 \u2192 \u5de5\u5177\u73af \u2192 checkpointer\u3002<\/p>\n<\/blockquote>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5c0f\u660e\u60f3\u628a\u300c\u5fc5\u987b\u62d2\u7b54\u300d\u753b\u6210\u56fe\uff0c\u5374\u4e0d\u77e5\u4ece\u54ea\u4e0b\u7b14<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u9009\u578b\u6284\u8fdb\u672c\u5b50\u540e\uff0c\u5c0f\u660e\u6253\u5f00\u7f16\u8f91\u5668\uff0c\u51c6\u5907\u628a\u5ba2\u670d\u6539\u6210\u56fe\u3002\u76ef\u7740\u7a7a\u767d\u6587\u4ef6\u53d1\u5446\uff1a<\/p>\n<blockquote style=\"color: rgb(85, 85, 85); background-color: rgb(255, 249, 235); background-image: none; padding: 16px 20px; margin: 20px 0px; border-width: 0px 0px 0px 4px; border-style: none none none solid; border-color: currentcolor currentcolor currentcolor rgb(248, 180, 63); border-radius: 6px; font-style: normal; quotes: none;\">\n<p style=\"margin: 0.55em 0px; color: rgb(85, 85, 85); text-indent: 0px; padding: 0px; line-height: 1.75; font-style: normal; background: transparent;\">State \u653e\u54ea\u513f\uff1f\u8282\u70b9\u8fd4\u56de\u6574\u4e2a\u5b57\u5178\u8fd8\u662f\u53ea\u8fd4\u56de\u6539\u52a8\u7684\u5b57\u6bb5\uff1f\u6761\u4ef6\u8fb9\u548c <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">if<\/code> \u6709\u5565\u533a\u522b\uff1f<\/p>\n<\/blockquote>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u4ed6\u8dd1\u53bb\u627e\u8001\u5f20\uff1a&#8221;\u4ecb\u7ecd\u7bc7\u8bf4 Node \/ Edge \/ State\uff0c\u80fd\u4e0d\u80fd\u4e00\u5929\u4e00\u53f0\u9636\u62c6\u5f00\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u62c9\u5f00\u6905\u5b50\uff1a&#8221;\u53ef\u4ee5\u3002\u4eca\u5929\u6838\u5fc3\u5c31\u4e09\u6837\u2014\u2014<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u8282\u70b9\u5e72\u6d3b\u3001\u8fb9\u6307\u8def\u3001\u72b6\u6001\u4f20\u6570\u636e<\/strong>\u3002 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">Command<\/code>\u3001<code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">interrupt<\/code> \u4eca\u5929\u53ea\u70b9\u540d\uff0c\u6df1\u6316\u7559\u7ed9\u5ba2\u670d\u9879\u76ee\u7bc7\u3002&#8221;<\/p>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4e09\u8981\u7d20\uff1a\u4e00\u5f20\u56fe\u8bb0\u4f4f<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u5728\u767d\u677f\u4e0a\u5199\uff1a<\/p>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">State  = \u6574\u4e2a\u5de5\u4f5c\u6d41\u91cc\u6d41\u8f6c\u7684\u6570\u636e\uff08TypedDict\uff09\nNode   = \u5173\u952e\u5de5\u4f5c\u4ee3\u7801\uff08\u51fd\u6570\uff09\uff1a\u8bfb State \u2192 \u5e72\u6d3b \u2192 \u8fd4\u56de\u300c\u8981\u66f4\u65b0\u7684\u5b57\u6bb5\u300d\nEdge   = \u8fde\u63a5\u8282\u70b9\u7684\u8def\u5f84\uff1a\u4e32\u884c \/ \u5e76\u884c \/ \u6761\u4ef6\nGraph  = Node + Edge \u7ec4\u6210\u7684\u5de5\u4f5c\u6d41\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u6bd4\u55bb\uff1a<\/p>\n<blockquote style=\"color: rgb(85, 85, 85); background-color: rgb(255, 249, 235); background-image: none; padding: 16px 20px; margin: 20px 0px; border-width: 0px 0px 0px 4px; border-style: none none none solid; border-color: currentcolor currentcolor currentcolor rgb(248, 180, 63); border-radius: 6px; font-style: normal; quotes: none;\">\n<p style=\"margin: 0.55em 0px; color: rgb(85, 85, 85); text-indent: 0px; padding: 0px; line-height: 1.75; font-style: normal; background: transparent;\">State \u662f\u5171\u4eab\u767d\u677f\uff1b\u6bcf\u4e2a Node \u662f\u6765\u5199\u4e00\u7b14\u7684\u540c\u4e8b\uff1bEdge \u89c4\u5b9a\u4e0b\u4e00\u4f4d\u8c01\u4e0a\u573a\u3002<\/p>\n<\/blockquote>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u8fde\u63a5\u65b9\u5f0f<\/th>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u4e32\u884c<\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">A \u5b8c\u4e00\u5b9a\u5230 B<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6761\u4ef6<\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u770b State \u518d\u9009\u8def<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u5e76\u884c<\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u591a\u8282\u70b9\u540c\u65f6\u8dd1\u518d\u6c47\u805a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u6784\u56fe\u56fa\u5b9a\u56db\u6b65\uff1a<\/p>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">StateGraph(State)\n  \u2192 add_node \/ add_edge \/ add_conditional_edges\n  \u2192 compile()\n  \u2192 invoke(...)\n<\/code><\/pre>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u7ebf\u6027\u56fe\u2014\u2014\u8282\u70b9\u8fd4\u56de<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u4e0d\u63a5 LLM\uff0c\u5148\u7ec3\u9aa8\u67b6<\/p>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs language-python\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\"><span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">class<\/span> <span class=\"hljs-title class_\" style=\"color: rgb(181, 137, 0);\">GraphState<\/span>(<span class=\"hljs-title class_ inherited__\" style=\"color: rgb(133, 153, 0);\">TypedDict<\/span>):\n  text: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>\n  steps: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">list<\/span>[<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>]\n\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">normalize<\/span>(<span class=\"hljs-params\">state: GraphState<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>:\n  text = state[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"text\"<\/span>].strip().lower()\n  steps = <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">list<\/span>(state.get(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"steps\"<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">or<\/span> [])\n  steps.append(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">f\"<span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">len<\/span>(steps) + <span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">1<\/span>}<\/span>.\u89c4\u8303\u5316\u6587\u672c\"<\/span>)\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"text\"<\/span>: text, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"steps\"<\/span>: steps}  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u53ea\u8fd4\u56de\u8981\u6539\u7684\u5b57\u6bb5<\/span>\n\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">shout<\/span>(<span class=\"hljs-params\">state: GraphState<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>:\n  steps = <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">list<\/span>(state.get(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"steps\"<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">or<\/span> [])\n  steps.append(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">f\"<span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">len<\/span>(steps) + <span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">1<\/span>}<\/span>.\u5927\u5199\u6587\u672c\"<\/span>)\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"text\"<\/span>: state[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"text\"<\/span>].upper() + <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"!\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"steps\"<\/span>: steps}\n\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">build_graph<\/span>():\n  g = StateGraph(GraphState)\n  g.add_node(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"normalize\"<\/span>, normalize)\n  g.add_node(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"shout\"<\/span>, shout)\n  g.add_edge(START, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"normalize\"<\/span>)\n  g.add_edge(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"normalize\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"shout\"<\/span>)\n  g.add_edge(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"shout\"<\/span>, END)\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> g.<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">compile<\/span>()\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u6572\u9ed1\u677f\uff1a<\/p>\n<ol style=\"margin: 8px 0px; padding-left: 28px; list-style: outside decimal;\">\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u8f93\u5165<\/strong>\u662f\u5b8c\u6574 State\uff1b<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u8f93\u51fa<\/strong>\u662f\u90e8\u5206 dict\u2014\u2014\u6846\u67b6\u8d1f\u8d23\u5408\u5e76\u3002<\/section>\n<\/li>\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section>\u4e0d\u8981\u5728\u8282\u70b9\u91cc\u5077\u5077\u6539\u5168\u5c40\u53d8\u91cf\uff1b\u53ef\u6d4b\u3001\u53ef\u6062\u590d\u90fd\u9760\u300c\u8fd4\u56de\u66f4\u65b0\u300d\u3002<\/section>\n<\/li>\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section><code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">START \u2192 normalize \u2192 shout \u2192 END<\/code>\uff1a\u4e32\u884c\u8fb9\uff0c\u8def\u5f84\u5199\u6b7b\u3002<\/section>\n<\/li>\n<\/ol>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u6761\u4ef6\u8fb9\u2014\u2014\u628a if\/else \u753b\u6210\u8def\u7531\u8868<\/span><\/h2>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">START \u2192 classify \u252c\u2500 weather \u2192 END\n         \u251c\u2500 policy  \u2192 END\n         \u2514\u2500 chitchat \u2192 END\n<\/code><\/pre>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs language-python\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\"><span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">class<\/span> <span class=\"hljs-title class_\" style=\"color: rgb(181, 137, 0);\">GraphState<\/span>(<span class=\"hljs-title class_ inherited__\" style=\"color: rgb(133, 153, 0);\">TypedDict<\/span>):\n    question: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>\n    route: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>\n    answer: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>\n  \n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">classify<\/span>(<span class=\"hljs-params\">state: GraphState<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>:\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\" \u5206\u7c7b\u95ee\u9898 \"\"\"<\/span>\n    q = state[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"question\"<\/span>].lower()\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">any<\/span>(k <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> q <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">for<\/span> k <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> (<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u5929\u6c14\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"weather\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6e29\u5ea6\"<\/span>)): <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u5224\u65ad\u662f\u5426\u5305\u542b\u5929\u6c14\u3001weather\u3001\u6e29\u5ea6<\/span>\n        route = <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"weather\"<\/span>\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">elif<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">any<\/span>(k <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> q <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">for<\/span> k <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> (<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u8bf7\u5047\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u5e74\u5047\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u5236\u5ea6\"<\/span>)): <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u5224\u65ad\u662f\u5426\u5305\u542b\u8bf7\u5047\u3001\u5e74\u5047\u3001\u5236\u5ea6<\/span>\n        route = <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"policy\"<\/span>\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">else<\/span>: <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u5426\u5219\u4e3a\u95f2\u804a<\/span>\n        route = <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"chitchat\"<\/span>\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"route\"<\/span>: route}\n  \n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">weather_node<\/span>(<span class=\"hljs-params\">state: GraphState<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>:\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"answer\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\uff08\u5929\u6c14\u5206\u652f\uff09\u4eca\u65e5\u57f9\u8bad\u57ce\u5e02\uff1a\u6674\uff0c22C\uff08\u6a21\u62df\uff09\"<\/span>}\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">policy_node<\/span>(<span class=\"hljs-params\">state: GraphState<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>:\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"answer\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\uff08\u5236\u5ea6\u5206\u652f\uff09\u8bf7\u67e5\u9605\u8bf7\u5047\u5236\u5ea6\uff1a\u6ee1 1 \u5e74\u5e74\u5047 5 \u5929\uff08\u6837\u4f8b\uff09\u3002\"<\/span>}\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">chitchat_node<\/span>(<span class=\"hljs-params\">state: GraphState<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>:\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"answer\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\uff08\u95f2\u804a\u5206\u652f\uff09\u4f60\u597d\uff0c\u6211\u662f\u8def\u7531\u6f14\u793a\u52a9\u624b\u3002\"<\/span>}\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">pick_branch<\/span>(<span class=\"hljs-params\">state: GraphState<\/span>) -&gt; <span class=\"hljs-type\" style=\"color: rgb(108, 113, 196);\">Literal<\/span>[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"weather\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"policy\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"chitchat\"<\/span>]:\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> state[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"route\"<\/span>]  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># type: ignore[<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span>-value]<\/span>\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">build_graph<\/span>():\n    g = StateGraph(GraphState)\n    g.add_node(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"classify\"<\/span>, classify)\n    g.add_node(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"weather\"<\/span>, weather_node)\n    g.add_node(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"policy\"<\/span>, policy_node)\n    g.add_node(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"chitchat\"<\/span>, chitchat_node)\n    g.add_edge(START, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"classify\"<\/span>)\n    g.add_conditional_edges(\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"classify\"<\/span>,\n        pick_branch,\n        {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"weather\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"weather\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"policy\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"policy\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"chitchat\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"chitchat\"<\/span>},\n    )\n\n    g.add_edge(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"weather\"<\/span>, END)\n    g.add_edge(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"policy\"<\/span>, END)\n    g.add_edge(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"chitchat\"<\/span>, END)\n\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> g.<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">compile<\/span>()\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">run_demo<\/span>() -&gt; <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n    app = build_graph()\n    cases = [\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u676d\u5dde\u5929\u6c14\u600e\u4e48\u6837\uff1f\"<\/span>,\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u5e74\u5047\u600e\u4e48\u8bf7\uff1f\"<\/span>,\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4f60\u597d\u5440\"<\/span>,\n    ]\n\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">for<\/span> q <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> cases:\n        out = app.invoke({<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"question\"<\/span>: q, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"route\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"answer\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"<\/span>})\n        <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">f\"Q: <span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{q}<\/span>\"<\/span>)\n        <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">f\"  route=<span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{out[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">'route'<\/span>]}<\/span> | answer=<span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{out[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">'answer'<\/span>]}<\/span>\"<\/span>)\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8981\u70b9\uff1a<\/p>\n<ul style=\"margin: 8px 0px; padding-left: 28px; list-style: outside disc;\">\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section><code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">classify<\/code> <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5199<\/strong> <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">route<\/code> \u8fdb State\uff1b<code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">pick_branch<\/code> <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u8bfb<\/strong> State \u51b3\u5b9a\u4e0b\u4e00\u8282\u70b9\u540d\u3002<\/section>\n<\/li>\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section>\u6620\u5c04\u8868\u91cc\u7684 key \u5fc5\u987b\u548c\u8def\u7531\u51fd\u6570\u8fd4\u56de\u503c\u5bf9\u5f97\u4e0a\uff1b\u5efa\u8bae <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">Literal<\/code> + \u9ed8\u8ba4\u5206\u652f\u3002<\/section>\n<\/li>\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section>\u89c4\u5219\u8def\u7531\u7a33\u3001\u4fbf\u5b9c\uff1b\u6362\u6210 LLM \u5206\u7c7b\u66f4\u61c2\u81ea\u7136\u8bed\u8a00\uff0c\u4f46\u8d35\u3001\u8981\u515c\u5e95\uff08WorkFlow \u7bc7\u518d\u6bd4\uff09\u3002<\/section>\n<\/li>\n<\/ul>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs language-bash\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">python main.py\n<\/code><\/pre>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">Q: \u676d\u5dde\u5929\u6c14\u600e\u4e48\u6837\uff1f\n  route=weather | answer=\uff08\u5929\u6c14\u5206\u652f\uff09\u4eca\u65e5\u57f9\u8bad\u57ce\u5e02\uff1a\u6674\uff0c22C\uff08\u6a21\u62df\uff09\nQ: \u5e74\u5047\u600e\u4e48\u8bf7\uff1f\n  route=policy | answer=\uff08\u5236\u5ea6\u5206\u652f\uff09\u8bf7\u67e5\u9605\u8bf7\u5047\u5236\u5ea6\uff1a\u2026\nQ: \u4f60\u597d\u5440\n  route=chitchat | answer=\uff08\u95f2\u804a\u5206\u652f\uff09\u4f60\u597d\uff0c\u6211\u662f\u8def\u7531\u6f14\u793a\u52a9\u624b\u3002\n<\/code><\/pre>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5de5\u5177\u73af\u2014\u2014\u53ef\u89c1\u7684 ReAct<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u5c0f\u660e\u6700\u719f\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">while tool_calls<\/code>\uff0c\u753b\u6210\u56fe\u5c31\u662f\uff1a<\/p>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">START \u2192 agent \u2500\u2500has tool_calls\u2500\u2500\u25ba tools \u2500\u2510\n      \u25b2                \u2502\n      \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 loop \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n      \u2514\u2500 no tool_calls \u2192 END\n<\/code><\/pre>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs language-python\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\"><span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">class<\/span> <span class=\"hljs-title class_\" style=\"color: rgb(181, 137, 0);\">AgentState<\/span>(<span class=\"hljs-title class_ inherited__\" style=\"color: rgb(133, 153, 0);\">TypedDict<\/span>):\n  messages: Annotated[<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">list<\/span>[BaseMessage], add_messages]\n\n<span class=\"hljs-meta\" style=\"color: rgb(211, 54, 130);\">@tool<\/span>\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">get_weather<\/span>(<span class=\"hljs-params\">city: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span><\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>:\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\"\u67e5\u8be2\u57ce\u5e02\u5929\u6c14\uff08\u6a21\u62df\uff09\u3002\"\"\"<\/span>\n    data = {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u676d\u5dde\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u5c0f\u96e8\uff0c17C\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u5317\u4eac\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6674\uff0c15C\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"Hangzhou\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"rain, 17C\"<\/span>}\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> data.get(city, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">f\"<span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{city}<\/span>\uff1a\u6674\uff0c20C\uff08\u6a21\u62df\uff09\"<\/span>)\n\ntools = [get_weather]\ntool_node = ToolNode(tools) <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u5de5\u5177\u8282\u70b9<\/span>\n\nmodel = ChatOpenAI(\n    model=os.environ.get(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"OPENAI_MODEL\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"qwen-plus\"<\/span>),\n    api_key=os.environ[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"OPENAI_API_KEY\"<\/span>],\n    base_url=os.environ.get(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"OPENAI_BASE_URL\"<\/span>),\n    temperature=<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0<\/span>,\n).bind_tools(tools)\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">call_model<\/span>(<span class=\"hljs-params\">state: AgentState<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>:\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\" \u8c03\u7528\u6a21\u578b \"\"\"<\/span>\n    ai = model.invoke(state[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>])\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>: [ai]}\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">should_continue<\/span>(<span class=\"hljs-params\">state: AgentState<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>:\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\" \u5224\u65ad\u662f\u5426\u7ee7\u7eed \"\"\"<\/span>\n    last = state[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>][-<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">1<\/span>]\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u5224\u65ad\u662f\u5426\u4e3aAI\u6d88\u606f\u4e14\u6709\u5de5\u5177\u8c03\u7528<\/span>\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">isinstance<\/span>(last, AIMessage) <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">and<\/span> last.tool_calls:\n        <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tools\"<\/span>\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"end\"<\/span>\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">build_graph<\/span>():\n    g = StateGraph(AgentState)\n    g.add_node(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"agent\"<\/span>, call_model)\n    g.add_node(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tools\"<\/span>, tool_node)\n    g.add_edge(START, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"agent\"<\/span>)\n    g.add_conditional_edges(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"agent\"<\/span>, should_continue, {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tools\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tools\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"end\"<\/span>: END})\n    g.add_edge(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tools\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"agent\"<\/span>)\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> g.<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">compile<\/span>()\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">run_demo<\/span>() -&gt; <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n    app = build_graph()\n    result = app.invoke(\n        {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>: [HumanMessage(content=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u676d\u5dde\u5929\u6c14\u600e\u4e48\u6837\uff1f\u7528\u4e00\u53e5\u8bdd\u56de\u7b54\u3002\"<\/span>)]}\n    )\n\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">for<\/span> m <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> result[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>]:\n        t = <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">getattr<\/span>(m, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"type\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"?\"<\/span>)\n        <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">getattr<\/span>(m, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool_calls\"<\/span>, <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>):\n            <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">f\"[<span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{t}<\/span>] tool_calls=<span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{m.tool_calls}<\/span>\"<\/span>)\n        <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">else<\/span>:\n            content = (<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">getattr<\/span>(m, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"<\/span>) <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">or<\/span> <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"<\/span>)[:<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">200<\/span>]\n            <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">f\"[<span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{t}<\/span>] <span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{content}<\/span>\"<\/span>)\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u5f3a\u8c03\u4e24\u5904\uff1a<\/p>\n<ol style=\"margin: 8px 0px; padding-left: 28px; list-style: outside decimal;\">\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\"><code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">add_messages<\/code> \u662f reducer<\/strong>\uff1a\u591a\u8f6e\u6d88\u606f<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u8ffd\u52a0<\/strong>\uff0c\u4e0d\u662f\u6574\u8868\u8986\u76d6\u3002\u6d88\u606f\u94fe\u573a\u666f\u51e0\u4e4e\u5fc5\u7528\u3002<\/section>\n<\/li>\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section>\u548c <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">create_agent<\/code> \u6bd4\uff1a\u5faa\u73af<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u770b\u5f97\u89c1<\/strong>\uff1b\u4e2d\u95f4\u53ef\u63d2\u5ba1\u6838\u3001\u68c0\u7d22\u3001\u9650\u6b65\u8282\u70b9\u3002\u8fdb\u9636\u53ef\u5728 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">should_continue<\/code> \u91cc\u52a0\u300c\u6700\u591a 3 \u6b65\u300d\u3002<\/section>\n<\/li>\n<\/ol>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs language-bash\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">python main.py --demo\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u5178\u578b\u8f93\u51fa\u5f62\u72b6\uff08\u5185\u5bb9\u968f\u6a21\u578b\u7565\u6709\u51fa\u5165\uff09\uff1a<\/p>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">[human] \u676d\u5dde\u5929\u6c14\u600e\u4e48\u6837\uff1f\u7528\u4e00\u53e5\u8bdd\u56de\u7b54\u3002\n[ai] tool_calls=[...]\n[tool] \u5c0f\u96e8\uff0c17C\n[ai] \u676d\u5dde\u4eca\u5929\u5c0f\u96e8\uff0c\u7ea6 17\u00b0C\u3002\nDay3 OK\n<\/code><\/pre>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">checkpointer + thread_id\u2014\u2014\u56fe\u4e5f\u6709\u77ed\u671f\u8bb0\u5fc6<\/span><\/h2>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs language-python\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\"><span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">class<\/span> <span class=\"hljs-title class_\" style=\"color: rgb(181, 137, 0);\">ChatState<\/span>(<span class=\"hljs-title class_ inherited__\" style=\"color: rgb(133, 153, 0);\">TypedDict<\/span>):\n    messages: Annotated[<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">list<\/span>[BaseMessage], add_messages]\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">chatbot<\/span>(<span class=\"hljs-params\">state: ChatState<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>:\n    ai = model.invoke(state[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>])\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>: [ai]}\n\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">build_graph<\/span>():\n    g = StateGraph(ChatState)\n    g.add_node(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"chatbot\"<\/span>, chatbot)\n    g.add_edge(START, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"chatbot\"<\/span>)\n    g.add_edge(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"chatbot\"<\/span>, END)\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> g.<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">compile<\/span>(checkpointer=InMemorySaver())\n\ncfg1 = {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"configurable\"<\/span>: {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"thread_id\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"u1\"<\/span>}}\ncfg2 = {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"configurable\"<\/span>: {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"thread_id\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"u2\"<\/span>}}\n\napp.invoke({<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>: [HumanMessage(content=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6211\u53eb Carol\u3002\"<\/span>)]}, cfg1)\napp.invoke({<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>: [HumanMessage(content=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6211\u53eb\u4ec0\u4e48\uff1f\"<\/span>)]}, cfg1)  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u540c\u7ebf\u7a0b\u8bb0\u5f97<\/span>\napp.invoke({<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>: [HumanMessage(content=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6211\u53eb\u4ec0\u4e48\uff1f\"<\/span>)]}, cfg2)  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u5f02\u7ebf\u7a0b\u4e0d\u4e32<\/span>\n<\/code><\/pre>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u5199\u6cd5<\/th>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u6302\u8f7d\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>create_agent(..., checkpointer=...)<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">Agent \u9884\u7ec4\u88c5<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>StateGraph.compile(checkpointer=...)<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u81ea\u5efa\u56fe\uff0c\u540c\u4e00\u5957\u673a\u5236<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u6ca1\u6709 checkpointer\uff1a\u6bcf\u6b21 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">invoke<\/code> \u4e0d\u4f1a\u81ea\u52a8\u8de8\u8c03\u7528\u6062\u590d\uff0c\u9664\u975e\u4f60\u81ea\u5df1\u4f20\u5165\u5b8c\u6574\u5386\u53f2\u3002\u8bfe\u5802\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">InMemorySaver<\/code>\uff1b\u751f\u4ea7\u518d\u6362 Postgres \u7b49\uff08\u9009\u4fee\uff09\u3002<\/p>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs language-bash\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">python main.py --demo\n<\/code><\/pre>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">=== Day4 demo: graph checkpointer + thread_id ===\nthread=u1 | \uff08\u786e\u8ba4\u8bb0\u4f4f Carol \u4e00\u7c7b\u56de\u590d\uff09\nthread=u1 | Carol\uff08\u6216\u7b49\u4ef7\uff09\nthread=u2 | \uff08\u4e0d\u77e5\u9053 \/ \u672a\u5728\u672c\u7ebf\u7a0b\u4ecb\u7ecd\uff09\nDay4 OK\n<\/code><\/pre>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5bf9\u7167\u8868\uff1a\u56db\u5929\u5206\u522b\u7ec3\u4e86\u4ec0\u4e48<\/span><\/h2>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u4f60\u7ec3\u5230\u7684\u80fd\u529b<\/th>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u4e09\u8981\u7d20\u4fa7\u91cd\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6700\u5c0f\u7ebf\u6027 <code>StateGraph<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">State + \u4e32\u884c Edge + \u90e8\u5206\u66f4\u65b0<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>add_conditional_edges<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6761\u4ef6 Edge \/ \u8def\u7531\u8868<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>ToolNode<\/code> + \u5faa\u73af<\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">reducer\uff08<code>add_messages<\/code>\uff09+ \u6761\u4ef6\u73af<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>InMemorySaver<\/code> + <code>thread_id<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u8de8 invoke \u7684 State \u6301\u4e45<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8fdb\u9636\u540d\u8bcd\uff1a<\/p>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u540d\u8bcd<\/th>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u4e00\u53e5\u8bdd<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>Command<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u8282\u70b9\u91cc\u540c\u65f6\u66f4\u65b0 State \u5e76\u6307\u5b9a\u4e0b\u4e00\u8df3<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>interrupt<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6682\u505c\u7ed9\u4eba\u5ba1\uff0c\u518d resume\uff08\u5ba2\u670d\u7bc7 \/ HITL\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">Retry \/ Timeout<\/td>\n<td style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u8282\u70b9\u7ea7\u5931\u8d25\u4e0e\u8d85\u65f6\u7b56\u7565<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4e09\u4e2a\u5e38\u89c1\u5751<\/span><\/h2>\n<h3 style=\"font-size: 16px; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 24px; margin-bottom: 12px; padding-left: 12px; border-left: 4px solid rgb(248, 180, 63);\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5751 1\uff1a\u8282\u70b9\u8fd4\u56de\u4e86\u300c\u5b8c\u6574\u65b0 State\u300d\u5374\u6f0f\u5b57\u6bb5<\/span><\/h3>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u75c7\u72b6<\/strong>\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">steps<\/code> \u6216\u5176\u5b83\u952e\u83ab\u540d\u53d8\u7a7a\u3002<br \/>\n<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u539f\u56e0<\/strong>\uff1a\u8bef\u4ee5\u4e3a\u5fc5\u987b\u8fd4\u56de\u5168\u91cf\uff1b\u6f0f\u952e\u82e5\u88ab\u5f53\u6210\u8986\u76d6\u4f1a\u51fa\u4e8b\uff08\u89c6 reducer \u800c\u5b9a\uff09\u3002<br \/>\n<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4fee\u6cd5<\/strong>\uff1a\u4e60\u60ef\u53ea\u8fd4\u56de<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u53d8\u66f4\u5b57\u6bb5<\/strong>\uff1b\u5217\u8868\u5b57\u6bb5\u81ea\u5df1 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">list(...)<\/code> \u62f7\u8d1d\u518d\u6539\uff0c\u907f\u514d\u5171\u4eab\u5f15\u7528\u8e29\u5751\u3002<\/p>\n<h3 style=\"font-size: 16px; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 24px; margin-bottom: 12px; padding-left: 12px; border-left: 4px solid rgb(248, 180, 63);\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5751 2\uff1a\u6761\u4ef6\u8fb9\u8fd4\u56de\u503c\u4e0d\u5728\u6620\u5c04\u8868\u91cc<\/span><\/h3>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u75c7\u72b6<\/strong>\uff1a\u8fd0\u884c\u62a5\u9519\u6216\u8d70\u5230\u610f\u5916\u7ec8\u70b9\u3002<br \/>\n<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u539f\u56e0<\/strong>\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">pick_branch<\/code> \u8fd4\u56de\u4e86 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">\"Weather\"<\/code> \u800c map \u5199\u7684\u662f <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">\"weather\"<\/code>\u3002<br \/>\n<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4fee\u6cd5<\/strong>\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">Literal<\/code> \u7ea6\u675f\uff1b\u6c38\u8fdc\u7559\u9ed8\u8ba4\u5206\u652f\uff08\u5982 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">chitchat<\/code>\uff09\u3002<\/p>\n<h3 style=\"font-size: 16px; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 24px; margin-bottom: 12px; padding-left: 12px; border-left: 4px solid rgb(248, 180, 63);\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5751 3\uff1a\u6d88\u606f State \u4e0d\u7528 <code>add_messages<\/code><\/span><\/h3>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u75c7\u72b6<\/strong>\uff1a\u7b2c\u4e8c\u8f6e\u5bf9\u8bdd\u628a\u5386\u53f2\u76d6\u6389\uff0c\u6216\u7c7b\u578b\u5bf9\u4e0d\u4e0a\u3002<br \/>\n<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u539f\u56e0<\/strong>\uff1a\u666e\u901a <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">list<\/code> \u9ed8\u8ba4\u662f\u8986\u76d6\u8bed\u4e49\u3002<br \/>\n<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4fee\u6cd5<\/strong>\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">messages: Annotated[list[BaseMessage], add_messages]<\/code>\uff08\u6216 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">MessagesState<\/code>\uff09\u3002<\/p>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u603b\u7ed3<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u4e09\u4e2a\u6838\u5fc3\u7406\u89e3\uff1a<\/p>\n<ol style=\"margin: 8px 0px; padding-left: 28px; list-style: outside decimal;\">\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4e09\u8981\u7d20<\/strong> \u2014\u2014 State \u4f20\u6570\u636e\uff0cNode \u8fd4\u56de\u90e8\u5206\u66f4\u65b0\uff0cEdge \u51b3\u5b9a\u4e0b\u4e00\u6b65\uff08\u4e32\u884c\/\u6761\u4ef6\/\u5e76\u884c\uff09  <\/section>\n<\/li>\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u6784\u56fe\u56db\u6b65<\/strong> \u2014\u2014 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">StateGraph<\/code> \u2192 \u52a0\u8282\u70b9\u8fb9 \u2192 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">compile<\/code> \u2192 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">invoke<\/code>  <\/section>\n<\/li>\n<li style=\"margin-bottom: 8px; padding-left: 0px; text-indent: 0px; color: rgb(51, 51, 51); list-style: inherit;\">\n<section><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4ece\u7ba1\u9053\u5230 Agent<\/strong> \u2014\u2014 \u7ebf\u6027\u8fb9 \u2192 \u6761\u4ef6\u8def\u7531 \u2192 \u5de5\u5177\u73af \u2192 checkpointer \u8bb0\u5fc6&#8221;<\/section>\n<\/li>\n<\/ol>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">LangGraph \u4e13\u9898\u8fdb\u5ea6\uff1a<\/p>\n<pre style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow: auto hidden; max-width: 100%; box-sizing: border-box; position: relative; line-height: 1.5; border-radius: 4px; margin: 16px 0px; padding: 0.5em; white-space: pre; word-break: normal; overflow-wrap: normal; background: rgb(0, 43, 54);\"><section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"45\" height=\"12\" viewBox=\"0 0 450 130\"><ellipse cx=\"65\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(220,60,54)\" stroke-width=\"2\" fill=\"rgb(237,108,96)\"><\/ellipse><ellipse cx=\"225\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(218,151,33)\" stroke-width=\"2\" fill=\"rgb(247,193,81)\"><\/ellipse><ellipse cx=\"385\" cy=\"65\" rx=\"50\" ry=\"52\" stroke=\"rgb(27,161,37)\" stroke-width=\"2\" fill=\"rgb(100,200,86)\"><\/ellipse><\/svg><\/section><code class=\"hljs\" style=\"tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; display: block; overflow: auto hidden; max-width: 100%; box-sizing: border-box; margin: 0.5em; padding: 3px 5px; white-space: nowrap; word-break: normal; overflow-wrap: normal; color: rgb(147, 161, 161); background: rgb(0, 43, 54);\">01 \u4ecb\u7ecd\uff08\u4e3a\u4f55 Graph\uff09\n    \u2193\n02 \u57fa\u672c\u6982\u5ff5\u548c\u5165\u95e8\uff08\u672c\u7bc7\uff09\n    \u2193\n03 \u5e38\u89c1 WorkFlow\uff08\u4e03\u79cd\u7f16\u6392\u6a21\u5f0f\uff09\n    \u2193\n04 \u5ba2\u6237\u652f\u6301 Email Agent\n<\/code><\/pre>\n<blockquote style=\"color: rgb(85, 85, 85); background-color: rgb(255, 249, 235); background-image: none; padding: 16px 20px; margin: 20px 0px; border-width: 0px 0px 0px 4px; border-style: none none none solid; border-color: currentcolor currentcolor currentcolor rgb(248, 180, 63); border-radius: 6px; font-style: normal; quotes: none;\">\n<p style=\"margin: 0.55em 0px; color: rgb(85, 85, 85); text-indent: 0px; padding: 0px; line-height: 1.75; font-style: normal; background: transparent;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u56fe\u4e0d\u662f\u9b54\u6cd5\uff1a\u5b83\u662f\u628a\u4f60\u672c\u6765\u8981\u5199\u7684 if\/while\/\u5b58\u6863\uff0c\u53d8\u6210\u770b\u5f97\u89c1\u3001\u6539\u5f97\u52a8\u3001\u6d4b\u5f97\u7740\u7684\u62d3\u6251\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u7bc7\u4f60\u641e\u6e05\u4e86\u300c\u4e3a\u4f55\u8981 Graph\u300d\u548c\u9009\u578b\u4e09\u53e5\u8bdd\u3002\u8fd9\u7bc7\u662f LangGraph \u4e13\u9898\u7b2c 02 \u7bc7\u2014\u2014\u628a\u4e09\u8981\u7d20\u5199\u8fdb\u4ee3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3890,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[163,165],"tags":[167,168,170,210],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3889"}],"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=3889"}],"version-history":[{"count":1,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3889\/revisions"}],"predecessor-version":[{"id":3891,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3889\/revisions\/3891"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/media\/3890"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}