{"id":3784,"date":"2026-08-17T15:18:22","date_gmt":"2026-08-17T07:18:22","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=3784"},"modified":"2026-08-17T15:18:22","modified_gmt":"2026-08-17T07:18:22","slug":"models-invoke%e4%b8%8estream%e7%bb%99agent%e6%8d%a2%e5%a4%a7%e8%84%91","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3784","title":{"rendered":"Models-invoke\u4e0estream\u7ed9Agent\u6362\u5927\u8111"},"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\u56db\u6b65\u8dd1\u901a\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;\">create_agent<\/code>\u2014\u2014Models + Tools \u5c31\u80fd\u5e72\u6d3b\u3002\u4f46\u585e\u8fdb\u53bb\u7684\u90a3\u4e2a\u300c\u5927\u8111\u300d\u5230\u5e95\u600e\u4e48\u521b\u5efa\u3001\u600e\u4e48\u8c03\u7528\uff1f\u8fd9\u7bc7\u628a <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">Models<\/strong> \u5355\u72ec\u62c6\u5f00\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;\">ChatOpenAI<\/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;\">init_chat_model<\/code>\uff0c\u4ee5\u53ca <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> \u4e0e <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;\">stream<\/code>\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\u53d1\u73b0 Agent\u300c\u6362\u6a21\u578b\u300d\u5f88\u70e6<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u5c0f\u660e\u628a Agent \u8dd1\u901a\u4e86\uff0c\u540c\u4e8b\u7a81\u7136\u8bf4\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);\">\u628a qwen-plus \u6362\u6210\u53e6\u4e00\u5bb6\u517c\u5bb9\u63a5\u53e3\u8bd5\u8bd5\uff0c\n\u804a\u5929\u9875\u8fd8\u8981\u652f\u6301\u300c\u4e00\u4e2a\u5b57\u4e00\u4e2a\u5b57\u5f80\u5916\u8e66\u300d\u7684\u6548\u679c\u3002\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u4ed6\u6253\u5f00 <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;\">agent_loop.py<\/code>\uff0c\u53d1\u73b0\u6a21\u578b\u521b\u5efa\u57cb\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;\">get_chat_model()<\/code> \u91cc\uff1b\u518d\u7ffb\u81ea\u5df1\u4ee5\u524d\u7684\u811a\u672c\uff0c\u6709\u7684\u5730\u65b9\u76f4\u63a5 <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;\">ChatOpenAI(...)<\/code>\uff0c\u6709\u7684\u6284\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;\">init_chat_model(...)<\/code>\uff0c\u6d41\u5f0f\u8f93\u51fa\u53c8\u662f\u53e6\u4e00\u5957 <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;\">for chunk in ...<\/code>\u3002<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u66f4\u7cdf\u7684\u662f\uff0c\u4ed6\u5206\u4e0d\u6e05\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);\">model.invoke(\"\u4f60\u597d\")       # \u6574\u6bb5\u8fd4\u56de\uff1f\nmodel.stream(\"\u4f60\u597d\")       # \u548c Agent \u7684 invoke \u662f\u4e00\u56de\u4e8b\u5417\uff1f\ncreate_agent(model, tools=...) # \u6362\u6a21\u578b\u662f\u4e0d\u662f\u6539\u8fd9\u4e00\u5904\u5c31\u884c\uff1f\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u5c0f\u660e\u53bb\u627e\u8001\u5f20\uff1a&#8221;Agent \u6211\u4f1a\u5efa\u4e86\uff0c\u4f46\u5927\u8111\u63a5\u53e3\u8fd8\u662f\u4e00\u56e2\u6d46\u7cca\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u90a3\u5c31\u628a\u955c\u5934\u4ece\u6307\u6325\u5b98\u62c9\u56de\u5927\u8111\u2014\u2014\u5148\u628a <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">ChatModel<\/strong> \u7684\u521b\u5efa\u65b9\u5f0f\u548c\u4e24\u79cd\u8bbf\u95ee\u65b9\u5f0f\u5403\u900f\u3002Agent \u53ea\u662f\u628a\u8fd9\u4e2a\u6a21\u578b\u63d2\u8fdb\u53bb\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;\">\u4ec0\u4e48\u662f Models\uff08ChatModel\uff09<\/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);\">\u6a21\u578b = \u5927\u8bed\u8a00\u6a21\u578b\uff08LLM\uff09\n\u80fd\u7406\u89e3\u4eba\u7c7b\u8bed\u8a00\uff0c\u751f\u6210\u5185\u5bb9\u3001\u7ffb\u8bd1\u3001\u6458\u8981\u3001\u56de\u7b54\u95ee\u9898\u2026\u2026\n\n\u5728 LangChain \u91cc\u65e5\u5e38\u63a5\u89e6\u7684\u662f ChatModel\uff1a\n  \u8f93\u5165\uff1a\u5b57\u7b26\u4e32 \u6216 Messages\n  \u8f93\u51fa\uff1aAIMessage\uff08\u6216\u6d41\u5f0f chunk\uff09\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u6bd4\u55bb\uff1a\u6a21\u578b\u662f\u53d1\u52a8\u673a\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;\">create_agent<\/code> \u662f\u6574\u8f66\u63a7\u5236\u7cfb\u7edf\u2014\u2014\u6cb9\u95e8\u3001\u6362\u6321\u5b83\u5e2e\u4f60\u7ba1\uff0c\u4f46\u4f60\u5f97\u4f1a\u9009\u53d1\u52a8\u673a\u3001\u4f1a\u770b\u8f6c\u901f\u8868\u3002<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u4e24\u79cd\u5e38\u89c1\u300c\u88c5\u53d1\u52a8\u673a\u300d\u7684\u65b9\u5f0f\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);\">A. ChatOpenAI(...)   \u2192 \u663e\u5f0f\u6307\u5b9a OpenAI \u517c\u5bb9\u7aef\uff08\u901a\u4e49\u7b49\u6700\u76f4\u89c2\uff09\nB. init_chat_model(...)\u2192 \u5b98\u65b9\u7edf\u4e00\u5165\u53e3\uff08\u6362 provider \u65f6\u5c11\u6539\u80f6\u6c34\uff09\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u4e24\u79cd\u5e38\u89c1\u300c\u8e29\u6cb9\u95e8\u300d\u7684\u65b9\u5f0f\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);\">invoke  \u2192 \u963b\u585e\uff1a\u7b49\u6574\u6bb5\u751f\u6210\u5b8c\u518d\u8fd4\u56de\nstream  \u2192 \u6d41\u5f0f\uff1a\u8fb9\u751f\u6210\u8fb9\u5410 chunk\uff0c\u9002\u5408\u6253\u5b57\u673a UI\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);\">\u7ef4\u5ea6<\/th>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">invoke<\/th>\n<th style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">stream<\/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;\">\u7b49\u5f85\u65b9\u5f0f<\/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;\">\u963b\u585e\u5230\u5b8c\u6574\u7ed3\u679c<\/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;\">\u8fed\u4ee3 chunk<\/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;\">\u8fd4\u56de\u5f62\u6001<\/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;\">\u4e00\u6761 AIMessage<\/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\u4e2a\u90e8\u5206 chunk<\/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;\">\u9002\u5408<\/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;\">\u811a\u672c\u3001\u6279\u5904\u7406\u3001Agent \u5185\u90e8\u4e00\u6b65\u51b3\u7b56<\/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;\">\u804a\u5929\u7a97\u53e3\u3001\u957f\u6587\u751f\u6210\u4f53\u9a8c<\/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;\">\u5fc3\u667a\u8d1f\u62c5<\/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;\">\u4f4e<\/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;\">\u8981\u81ea\u5df1\u62fc\u63a5 <code>chunk.content<\/code><\/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;\">\u5c0f\u660e\uff1a&#8221;Agent \u91cc\u7528\u7684\u662f\u54ea\u4e00\u79cd\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;<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> \u5403\u7684\u662f <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5df2\u7ecf\u5efa\u597d\u7684 ChatModel \u5b9e\u4f8b<\/strong>\u3002\u6846\u67b6\u5185\u90e8\u4f1a\u591a\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> \u505a\u51b3\u7b56\uff1b\u4f60\u7ed9\u7528\u6237\u505a\u300c\u6d41\u5f0f\u804a\u5929\u9875\u300d\u65f6\uff0c\u5f80\u5f80\u662f\u5bf9<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u88f8\u6a21\u578b<\/strong>\u6216\u94fe\u505a <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;\">stream<\/code>\uff0c\u522b\u548c Agent \u72b6\u6001\u673a\u6405\u5728\u4e00\u8d77\u2014\u2014\u5148\u5206\u5f00\u5b66\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;\">\u4ee3\u7801\u62c6\u89e3\uff1a\u6a21\u578b\u5de5\u5382 + \u4e09\u79cd\u6f14\u793a<\/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;\">1. \u6a21\u578b\u5de5\u5382\uff1a<code>llm.py<\/code><\/span><\/h3>\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);\">import<\/span> os\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">from<\/span> dotenv <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">import<\/span> load_dotenv\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">from<\/span> langchain.chat_models <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">import<\/span> init_chat_model\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">from<\/span> langchain_openai <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">import<\/span> ChatOpenAI\n\nload_dotenv()\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);\">get_chat_model<\/span>(<span class=\"hljs-params\">*, temperature: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">float<\/span> = <span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0.7<\/span><\/span>) -&gt; ChatOpenAI:\n  <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\"\u663e\u5f0f ChatOpenAI\uff08\u901a\u4e49\u7b49\u517c\u5bb9\u7aef\u6700\u76f4\u89c2\uff09\u3002\"\"\"<\/span>\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> 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=temperature,\n  )\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);\">get_init_chat_model<\/span>(<span class=\"hljs-params\">*, temperature: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">float<\/span> = <span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0.7<\/span><\/span>):\n  <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\"\u5b98\u65b9\u7edf\u4e00\u5165\u53e3 init_chat_model\u3002\"\"\"<\/span>\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> init_chat_model(\n    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    model_provider=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"openai\"<\/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=temperature,\n  )\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u53c2\u6570\u4e0a\u4f60\u6682\u65f6\u8bb0\u4f4f\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;\">model<\/code>\uff1a\u6a21\u578b\u540d  <\/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;\">api_key<\/code> \/ <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;\">base_url<\/code>\uff1a\u8fde\u54ea\u5bb6\u7f51\u5173  <\/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;\">temperature<\/code>\uff1a\u968f\u673a\u5ea6\uff1bAgent \u6f14\u793a\u5e38\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;\">0<\/code>\uff0c\u95f2\u804a\u53ef\u7565\u9ad8<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\"><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;\">get_chat_model<\/code> \u4e0e <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;\">get_init_chat_model<\/code> \u5728\u517c\u5bb9 OpenAI \u534f\u8bae\u65f6\uff0c\u65e5\u5e38\u6548\u679c\u63a5\u8fd1\uff1b\u524d\u8005\u7c7b\u578b\u660e\u786e\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;\">ChatOpenAI<\/code>\uff0c\u540e\u8005\u8d70\u7edf\u4e00\u5165\u53e3\u3002&#8221;<\/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;\">2. \u6f14\u793a A\uff1aChatOpenAI + invoke<\/span><\/h3>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\"><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;\">main.py<\/code>\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 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);\">from<\/span> langchain_core.messages <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">import<\/span> HumanMessage, SystemMessage\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">from<\/span> llm <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">import<\/span> get_chat_model, get_init_chat_model\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);\">demo_chat_openai_invoke<\/span>() -&gt; <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n  <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\"A. ChatOpenAI\uff1a\u5b57\u7b26\u4e32 invoke + \u6d88\u606f\u5217\u8868 invoke\u3002\"\"\"<\/span>\n  model = get_chat_model(temperature=<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0.3<\/span>)\n  msg = model.invoke(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u7528\u4e00\u53e5\u8bdd\u4ecb\u7ecd LangChain \u662f\u505a\u4ec0\u4e48\u7684\u3002\"<\/span>)\n  <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">type<\/span>(msg).__name__, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\":\"<\/span>, msg.content)\n\n  msg2 = model.invoke(\n    [\n      SystemMessage(content=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4f60\u662f\u7b80\u6d01\u7684\u6280\u672f\u52a9\u6559\uff0c\u56de\u7b54\u4e0d\u8d85\u8fc7 40 \u5b57\u3002\"<\/span>),\n      HumanMessage(content=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4ec0\u4e48\u662f ChatModel\uff1f\"<\/span>),\n    ]\n  )\n  <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages:\"<\/span>, msg2.content)\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u4e24\u4e2a\u7528\u6cd5\u8981\u523b\u8fdb\u808c\u8089\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;\">\u5b57\u7b26\u4e32<\/strong> \u2014\u2014 \u6700\u5feb\u8bd5\u6a21\u578b\u662f\u5426\u901a  <\/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;\">Messages \u5217\u8868<\/strong> \u2014\u2014 \u6b63\u5f0f\u7528\u6cd5\uff1bSystem \/ Human \u89d2\u8272\u5206\u5f00\uff0c\u540e\u9762 Messages\u3001\u591a\u6a21\u6001\u3001\u8bb0\u5fc6\u90fd\u5efa\u5728\u8fd9\u4e0a\u9762<\/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;\">\u8fd4\u56de\u7684\u662f\u6d88\u606f\u5bf9\u8c61\uff0c\u8bfb\u6b63\u6587\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;\">.content<\/code>\uff0c\u4e0d\u662f\u88f8\u5b57\u7b26\u4e32\u3002&#8221;<\/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;\">3. \u6f14\u793a B\uff1ainit_chat_model<\/span><\/h3>\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);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">demo_init_chat_model<\/span>() -&gt; <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n  <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\"B. \u5b98\u65b9\u7edf\u4e00\u5165\u53e3 init_chat_model\u3002\"\"\"<\/span>\n  model = get_init_chat_model(temperature=<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0.3<\/span>)\n  msg = model.invoke(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u7528\u4e00\u53e5\u8bdd\u8bf4\u660e init_chat_model \u7684\u7528\u9014\u3002\"<\/span>)\n  <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">type<\/span>(model).__name__, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\":\"<\/span>, msg.content)\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u540c\u4e8b\u8981\u4f60\u6362\u4f9b\u5e94\u5546\u65f6\uff0c\u4f18\u5148\u60f3\u7684\u662f\u6539\u5de5\u5382\u51fd\u6570\uff0c\u800c\u4e0d\u662f\u6ee1\u9879\u76ee\u641c <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;\">ChatOpenAI<\/code>\u3002\u8fd9\u5c31\u662f\u7edf\u4e00\u5165\u53e3\u7684\u4ef7\u503c\u3002&#8221;<\/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;\">4. \u6f14\u793a C\uff1astream<\/span><\/h3>\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);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">demo_stream<\/span>() -&gt; <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n  <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\"C. \u6d41\u5f0f\u8f93\u51fa\u3002\"\"\"<\/span>\n  model = get_chat_model(temperature=<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0.3<\/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);\">\"\u6d41\u5f0f\uff1a\"<\/span>, end=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"<\/span>, flush=<span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">True<\/span>)\n  n = <span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0<\/span>\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">for<\/span> chunk <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> model.stream(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u7528\u4e24\u4e09\u53e5\u8bdd\u4ecb\u7ecd\u4ec0\u4e48\u662f\u6d41\u5f0f\u8f93\u51fa\uff0c\u9002\u5408\u521d\u5b66\u8005\u3002\"<\/span>):\n    <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(chunk.content <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">or<\/span> <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"<\/span>, end=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"<\/span>, flush=<span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">True<\/span>)\n    n += <span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">1<\/span>\n  <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/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);\">\"chunk \u6570\u91cf:\"<\/span>, n)\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;<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;\">stream<\/code> \u8fd4\u56de\u53ef\u8fed\u4ee3\u5bf9\u8c61\u3002\u6bcf\u4e2a <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;\">chunk.content<\/code> \u53ef\u80fd\u662f\u4e00\u5c0f\u6bb5\u5b57\uff0c\u8981\u81ea\u5df1\u62fc\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;\">flush=True<\/code> \u662f\u4e3a\u4e86\u7ec8\u7aef\u7acb\u523b\u5237\u51fa\u6765\uff0c\u6a21\u62df\u6253\u5b57\u673a\u3002<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u6ce8\u610f\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;\">chunk.content<\/code> \u53ef\u80fd\u662f\u7a7a\uff0c\u6240\u4ee5\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;\">or \\\"\\\"<\/code>\uff0c\u907f\u514d\u6253\u5370 <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;\">None<\/code>\u3002&#8221;<\/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;\">5. \u63a5\u5230 Agent\uff1a\u521b\u5efa\u667a\u80fd\u4f53\u65f6\u6ce8\u5165\u6a21\u578b<\/span><\/h3>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u5927\u8111\u5c31\u662f\u8fd9\u6837\u63d2\u8fdb\u53bb\u7684\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 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);\">agent = create_agent(\n  get_chat_model(temperature=<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0<\/span>),\n  tools=TOOLS,\n  system_prompt=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4f60\u662f\u52a9\u624b\u3002\u9700\u8981\u67e5\u5929\u6c14\u6216\u505a\u52a0\u6cd5\u65f6\u5fc5\u987b\u8c03\u7528\u5de5\u5177\uff0c\u4e0d\u8981\u7f16\u9020\u3002\"<\/span>,\n)\nresult = agent.invoke({<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>: [{<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"user\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: question}]})\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5bfc\u56fe\u91cc\u7684\u300c\u5728 Agent \u4e2d\u4f7f\u7528\u6a21\u578b\u300d\u5c31\u4e24\u6b65\uff1a<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u521b\u5efa\u667a\u80fd\u4f53\u65f6\u4f20\u5165 model<\/strong> \u2192 <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u8c03\u7528\u667a\u80fd\u4f53<\/strong>\u3002<br \/>\n\u6362\u53d1\u52a8\u673a = \u6362 <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;\">get_chat_model<\/code> \/ <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;\">get_init_chat_model<\/code> \u7684\u5b9e\u73b0\u6216\u73af\u5883\u53d8\u91cf\uff0c\u4e0d\u5fc5\u6539\u5de5\u5177\u5faa\u73af\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u5c0f\u660e\u590d\u8ff0\uff1a&#8221;\u5de5\u5382\u9020 ChatModel\uff1binvoke \u6574\u6bb5\u3001stream \u9010\u7247\uff1bAgent \u5403\u7684\u662f\u6a21\u578b\u5b9e\u4f8b\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5bf9\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;\">main.py<\/code> \u91cc\u4e09\u4e2a demo \u9ed8\u8ba4\u53ea\u5f00\u4e86\u4e00\u4e2a\uff0c\u4f60\u672c\u5730\u628a\u6ce8\u91ca\u6253\u5f00\u5c31\u80fd\u5168\u8dd1\u3002&#8221;<\/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);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">main<\/span>() -&gt; <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># demo_chat_openai_invoke()<\/span>\n  demo_init_chat_model()\n  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># demo_stream()<\/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);\">\"Day1 OK\"<\/span>)\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;\">\u603b\u7ed3<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u7b2c\u4e09\u7bc7\u53ea\u529e\u4e00\u4ef6\u4e8b\u2014\u2014\u628a\u5927\u8111\u63a5\u53e3\u9489\u6b7b\u3002&#8221;<\/p>\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;\">ChatModel \u662f Agent \u7684\u53d1\u52a8\u673a<\/strong> \u2014\u2014 \u7528\u5de5\u5382\u521b\u5efa\uff0c\u7528\u73af\u5883\u53d8\u91cf\u6362\u7aef  <\/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;\">\u4e24\u6761\u521b\u5efa\u8def<\/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;\">ChatOpenAI<\/code> \u76f4\u89c2\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;\">init_chat_model<\/code> \u7edf\u4e00\u5165\u53e3  <\/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;\">\u4e24\u79cd\u8bbf\u95ee<\/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;\">invoke<\/code> \u963b\u585e\u6574\u6bb5\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;\">stream<\/code> \u9010 chunk\uff0c\u670d\u52a1\u4e0d\u540c\u573a\u666f&#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;\">LangChain \u652f\u7ebf\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);\">\u8ba4\u8bc6 LangChain\n  \u2193\nAgent \u5feb\u901f\u5165\u95e8\uff08create_agent\uff09\n  \u2193\nModels\uff08\u672c\u7bc7\uff1a\u5de5\u5382 + invoke\/stream\uff09\n  \u2193\nMessages \u2192 Prompts\/LCEL \u2192 Tools \u2192 Memory \u2192 \u2026\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u5c0f\u660e\u8bf4\uff1a&#8221;\u4e0b\u4e00\u7bc7\u8be5\u628a Messages \u548c\u591a\u6a21\u6001\u641e\u6e05\u695a\u4e86\u2014\u2014invoke \u5403\u5217\u8868\u65f6\u90a3\u4e9b SystemMessage \/ HumanMessage \u5230\u5e95\u600e\u4e48\u6392\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5bf9\u3002\u4e0b\u4e00\u7bc7\uff1a<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">Messages \u4e0e\u591a\u6a21\u6001<\/strong>\u2014\u2014\u6d88\u606f\u7c7b\u578b\u3001\u5728\u7ebf\u56fe\u7247\u3001\u672c\u5730 base64\u3002&#8221;<\/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;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4f1a\u5efa Agent \u4e0d\u591f\uff0c\u8fd8\u8981\u4f1a\u6362\u5927\u8111\u3001\u4f1a\u9009 invoke \u8fd8\u662f stream\u3002\u6a21\u578b\u5de5\u5382\u8ba9\u914d\u7f6e\u53ea\u6709\u4e00\u5904\u771f\u76f8\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u7bc7\u4f60\u56db\u6b65\u8dd1\u901a\u4e86 create_agent\u2014\u2014Models + Tools \u5c31\u80fd\u5e72\u6d3b\u3002\u4f46\u585e\u8fdb\u53bb\u7684\u90a3\u4e2a\u300c\u5927\u8111\u300d\u5230 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3785,"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\/3784"}],"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=3784"}],"version-history":[{"count":1,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3784\/revisions"}],"predecessor-version":[{"id":3786,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3784\/revisions\/3786"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/media\/3785"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}