{"id":3808,"date":"2026-08-18T05:59:45","date_gmt":"2026-08-17T21:59:45","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=3808"},"modified":"2026-08-18T05:59:45","modified_gmt":"2026-08-17T21:59:45","slug":"messages-%e8%ae%a9agent%e7%9c%8b%e6%87%82%e5%9b%be%e6%96%87%e5%a4%9a%e6%a8%a1%e6%80%81","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3808","title":{"rendered":"Messages-\u8ba9Agent\u770b\u61c2\u56fe\u6587\u591a\u6a21\u6001"},"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; line-height: 1.75; font-size: 16px; color: rgb(0, 0, 0); caret-color: rgb(0, 0, 0);\">\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid rgb(239, 112, 96); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; background: rgb(255, 249, 249);\">\n<p style=\"margin: 1em 0px;\">\u4e0a\u7bc7\u4f60\u628a\u5927\u8111\u63a5\u53e3\u9489\u6b7b\u4e86\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; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">invoke<\/code> \u65e2\u80fd\u5403\u5b57\u7b26\u4e32\uff0c\u4e5f\u80fd\u5403 Messages \u5217\u8868\u3002\u5b57\u7b26\u4e32\u53ea\u591f\u6253\u62db\u547c\uff1b\u6b63\u5f0f\u5bf9\u8bdd\u3001\u5de5\u5177\u56de\u586b\u3001\u770b\u56fe\u8bf4\u8bdd\uff0c\u5168\u9760 <strong>Messages<\/strong>\u3002\u8fd9\u7bc7\u8bb2\u6d88\u606f\u7c7b\u578b\u3001\u600e\u4e48\u904d\u5386\uff0c\u4ee5\u53ca\u591a\u6a21\u6001\uff08\u5728\u7ebf URL \/ \u672c\u5730 base64\uff09\u600e\u4e48\u585e\u8fdb\u540c\u4e00\u6761\u6d88\u606f\u3002<\/p>\n<\/blockquote>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid rgb(239, 112, 96); display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u5c0f\u660e\u628a\u89d2\u8272\u641e\u6df7\u4e86<\/span><\/p>\n<section style=\"border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent; align-self: flex-end; height: 0px;\"><\/section>\n<\/h2>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\u6cbf\u7528\u4e0a\u7bc7\u5199\u6cd5\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\">model.invoke(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u7528\u4e00\u53e5\u8bdd\u4ecb\u7ecd LangChain\"<\/span>)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u540c\u4e8b\u7529\u6765\u9700\u6c42\uff1aAI \u79c1\u53a8\u8981\u300c\u770b\u51b0\u7bb1\u7167\u7247\u8ba4\u98df\u6750\u300d\u3002\u4ed6\u968f\u624b\u628a\u56fe\u7247\u8def\u5f84\u62fc\u8fdb\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\">\u8bf7\u770b\u8fd9\u5f20\u56fe D:\\fridge.jpg\uff0c\u91cc\u9762\u6709\u4ec0\u4e48\u83dc\uff1f\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6a21\u578b\u5f53\u7136\u300c\u770b\u4e0d\u89c1\u300d\u6587\u4ef6\u8def\u5f84\u3002\u4ed6\u53c8\u8bd5\u8fc7\u5728\u5b57\u5178\u91cc\u4e71\u5199\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\">{<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"image\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"http:\/\/...\"<\/span>}  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u60f3\u5f53\u7136<\/span>\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u540c\u65f6\uff0cAgent \u8fd4\u56de\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; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">result[\"messages\"]<\/code> \u91cc\u53c8\u5192\u51fa <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">ToolMessage<\/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; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">AIMessage<\/code>\uff0c\u4ed6\u5206\u4e0d\u6e05\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; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">SystemMessage<\/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; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">HumanMessage<\/code> \u8c01\u5148\u8c01\u540e\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\u53bb\u627e\u8001\u5f20\uff1a&#8221;Messages \u5230\u5e95\u6709\u51e0\u7c7b\uff1f\u770b\u56fe\u53c8\u8be5\u600e\u4e48\u53d1\uff1f&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u5148\u628a<strong>\u6587\u672c\u6d88\u606f\u534f\u8bae<\/strong>\u7ad9\u7a33\uff0c\u518d\u5728 Human \u6d88\u606f\u7684 content \u91cc\u6302\u56fe\u2014\u2014\u591a\u6a21\u6001\u4e0d\u662f\u65b0\u89d2\u8272\uff0c\u662f content \u53d8\u5bcc\u4e86\u3002&#8221;<\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid rgb(239, 112, 96); display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4ec0\u4e48\u662f Messages<\/span><\/p>\n<section style=\"border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent; align-self: flex-end; height: 0px;\"><\/section>\n<\/h2>\n<p style=\"margin: 1em 0px;\">\u8001\u5f20\u5728\u767d\u677f\u4e0a\u753b\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\">\u4e00\u6761\u5bf9\u8bdd = \u6709\u5e8f\u5217\u8868 messages[]\n\n\u5e38\u89c1\u7c7b\u578b\uff08LangChain\uff09\uff1a\n  SystemMessage  \u2192 \u4eba\u8bbe \/ \u603b\u89c4\u5219\uff08\u2248 role=system\uff09\n  HumanMessage   \u2192 \u7528\u6237\u8f93\u5165\uff08\u2248 role=user\uff09\n  AIMessage    \u2192 \u6a21\u578b\u56de\u590d\uff08\u2248 role=assistant\uff09\n  ToolMessage  \u2192 \u5de5\u5177\u7ed3\u679c\u56de\u586b\uff08\u2248 role=tool\uff0c\u5e26 tool_call_id\uff09\n\n\u591a\u6a21\u6001\uff1a\n  \u4ecd\u662f HumanMessage\uff08\u6216\u7b49\u4ef7 user\uff09\n  \u53ea\u662f content \u4ece\u300c\u7eaf\u5b57\u7b26\u4e32\u300d\n     \u53d8\u6210\u300c\u6587\u672c\u5757 + \u56fe\u7247\u5757\u300d\u7684\u5217\u8868\n<\/code><\/pre>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u672c\u5730\u56fe\u7247\u4e0d\u662f URL\uff0c\u800c\u662f\u6587\u4ef6\u5b57\u8282 \u2192 \u8f6c <strong>base64<\/strong> \u518d\u53d1\u7ed9\u6a21\u578b  <\/section>\n<\/li>\n<li>\n<section>\u53e6\u4e00\u6761\u8def\uff1a\u5148\u4e0a\u4f20 OSS\uff0c\u53d8\u6210<strong>\u5728\u7ebf\u56fe\u7247 URL<\/strong><\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u6bd4\u55bb\uff1aMessages \u662f\u8bdd\u5267\u5267\u672c\u7684\u53f0\u8bcd\u8868\u3002System \u662f\u65c1\u767d\u89c4\u77e9\uff0cHuman \u662f\u4e3b\u89d2\u53f0\u8bcd\uff0cAI \u662f\u5bf9\u624b\u620f\uff0cTool \u662f\u573a\u52a1\u9012\u4e0a\u6765\u7684\u9053\u5177\u6e05\u5355\u3002\u770b\u56fe\u8bf4\u8bdd\uff0c\u53ea\u662f\u4e3b\u89d2\u53f0\u8bcd\u91cc\u5939\u4e86\u4e00\u5f20\u5267\u7167\u2014\u2014\u89d2\u8272\u8fd8\u662f Human\u3002&#8221;<\/p>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all;\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top; font-weight: bold; background-color: rgb(255, 249, 249); color: rgb(239, 112, 96);\">\u7c7b\u578b<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top; font-weight: bold; background-color: rgb(255, 249, 249); color: rgb(239, 112, 96);\">\u8c01\u4ea7\u751f<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top; font-weight: bold; background-color: rgb(255, 249, 249); color: rgb(239, 112, 96);\">\u5178\u578b\u7528\u9014<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">SystemMessage<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u4f60 \/ Agent \u7684 system_prompt<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u89d2\u8272\u3001\u7981\u7f16\u9020\u3001\u8f93\u51fa\u683c\u5f0f<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">HumanMessage<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u7528\u6237<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u95ee\u9898\u3001\u56fe\u6587\u8f93\u5165<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">AIMessage<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u6a21\u578b<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u6700\u7ec8\u56de\u7b54\uff1b\u6216\u5e26 <code>tool_calls<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">ToolMessage<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u4f60\u7684\u5de5\u5177\u6267\u884c\u7ed3\u679c<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u5fc5\u987b\u914d\u5bf9\u67d0\u4e2a <code>tool_call_id<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid rgb(239, 112, 96); display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4ee3\u7801\u62c6\u89e3\uff1a\u6587\u672c Messages \u2192 \u591a\u6a21\u6001 content<\/span><\/p>\n<section style=\"border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent; align-self: flex-end; height: 0px;\"><\/section>\n<\/h2>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\"><span>1. \u6700\u5c0f Messages \u8c03\u7528<\/span><\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\"><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\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_messages<\/span>() -&gt; <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n  model = get_chat_model(temperature=<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0.2<\/span>)\n  ai = model.invoke(\n    [\n      SystemMessage(content=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4f60\u662f\u52a9\u6559\uff0c\u56de\u7b54\u4e0d\u8d85\u8fc7 50 \u5b57\u3002\"<\/span>),\n      HumanMessage(content=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"SystemMessage \u548c role=system \u662f\u4ec0\u4e48\u5173\u7cfb\uff1f\"<\/span>),\n    ]\n  )\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>(ai).__name__, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\":\"<\/span>, ai.content)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;\u5bf9\u7167\u8868\uff1a<\/p>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all;\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top; font-weight: bold; background-color: rgb(255, 249, 249); color: rgb(239, 112, 96);\">LangChain \u7c7b<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top; font-weight: bold; background-color: rgb(255, 249, 249); color: rgb(239, 112, 96);\">OpenAI \u98ce\u683c role<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">SystemMessage<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\"><code>system<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">HumanMessage<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\"><code>user<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u8fd4\u56de\u7684 AIMessage<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\"><code>assistant<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u987a\u5e8f\u5f88\u91cd\u8981\uff1a\u4e00\u822c\u5148 System\uff0c\u518d Human\u3002\u8fd4\u56de\u503c\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; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">AIMessage<\/code>\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; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">.content<\/code>\u2014\u2014\u4e0a\u7bc7\u8bf4\u8fc7\u3002&#8221;<\/p>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\"><span>2. \u904d\u5386 Messages \u6570\u7ec4<\/span><\/h3>\n<p style=\"margin: 1em 0px;\">Agent \u8dd1\u5b8c\u540e\uff0c\u8f68\u8ff9\u90fd\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; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">messages<\/code> \u91cc\u3002\u8c03\u8bd5\u65f6\u517b\u6210\u904d\u5386\u4e60\u60ef\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\">result = 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<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  name = <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">type<\/span>(m).__name__\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>)\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);\">{name}<\/span>: <span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>(content)[:<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">80<\/span>]}<\/span>\"<\/span>)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;\u4f60\u4f1a\u770b\u89c1\uff1aHuman \u2192 AI\uff08\u53ef\u80fd\u542b tool_calls\uff09\u2192 Tool \u2192 AI\uff08\u6700\u7ec8\u8bdd\uff09\u2026\u2026<br \/>\n<strong>\u904d\u5386<\/strong>\u662f\u4e3a\u4e86\u6392\u969c\uff1a\u5230\u5e95\u6709\u6ca1\u6709\u8c03\u5de5\u5177\u3001\u5de5\u5177\u7ed3\u679c\u6709\u6ca1\u6709\u56de\u586b\u3002&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">\u624b\u5199\u5faa\u73af\u91cc\uff0c\u56de\u586b\u957f\u8fd9\u6837\uff08\u771f\u4ee3\u7801\u8282\u594f\uff09\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\">messages.append(ai)  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># AIMessage\uff0c\u53ef\u80fd\u5e26 tool_calls<\/span>\n<span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># ...<\/span>\nmessages.append(ToolMessage(content=<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>(result), tool_call_id=tc[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"id\"<\/span>]))\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;ToolMessage \u5fc5\u987b\u5e26 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">tool_call_id<\/code>\uff0c\u548c\u5f53\u521d\u7684 tool_call \u914d\u5bf9\u2014\u2014\u8fd9\u662f\u534f\u8bae\u94c1\u5f8b\uff0c\u548c\u65e9\u671f Function Calling \u7bc7\u540c\u4e00\u4e2a\u9053\u7406\u3002&#8221;<\/p>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\"><span>3. \u591a\u6a21\u6001\uff1a\u5728\u7ebf\u56fe\u7247\uff08URL\uff09<\/span><\/h3>\n<p style=\"margin: 1em 0px;\">\u5bfc\u56fe\uff1a\u300c\u5728\u7ebf\u56fe\u7247\u300d\u7528\u56fe\u7247 URL\u3002Human \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; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">content<\/code> \u6539\u6210<strong>\u5757\u5217\u8868<\/strong>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\"><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\n\nvision_msg = HumanMessage(\n  content=[\n    {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"type\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"text\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"text\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u8bf7\u7528\u4e00\u53e5\u8bdd\u63cf\u8ff0\u56fe\u7247\u91cc\u7684\u98df\u6750\u3002\"<\/span>},\n    {\n      <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"type\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"image_url\"<\/span>,\n      <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"image_url\"<\/span>: {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"url\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"https:\/\/\u793a\u4f8b\u57df\u540d\/demo-fridge.jpg\"<\/span>},\n    },\n  ]\n)\n\nai = model.invoke(\n  [\n    SystemMessage(content=<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4f60\u662f\u53a8\u623f\u52a9\u624b\uff0c\u53ea\u63cf\u8ff0\u770b\u5f97\u89c1\u7684\u98df\u6750\uff0c\u4e0d\u7f16\u9020\u3002\"<\/span>),\n    vision_msg,\n  ]\n)\n<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(ai.content)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u8981\u70b9\uff1a<\/p>\n<ol style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: decimal;\">\n<li>\n<section>\u591a\u6a21\u6001\u4ecd\u8d70 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">model.invoke([SystemMessage, HumanMessage])<\/code>  <\/section>\n<\/li>\n<li>\n<section>\u56fe\u7247\u6302\u5728 <strong>HumanMessage.content \u5217\u8868<\/strong>\u91cc\uff0c\u4e0d\u662f\u65b0\u7684 Message \u5b50\u7c7b  <\/section>\n<\/li>\n<li>\n<section>Smoke \u9a8c\u6536\uff1a\u6362\u4e00\u5f20<strong>\u516c\u7f51\u53ef\u8bbf\u95ee<\/strong>\u7684\u56fe\u7247 URL\uff08\u5927\u7eb2\u8981\u6c42\uff09<\/section>\n<\/li>\n<\/ol>\n<p style=\"margin: 1em 0px;\">\u6a21\u578b\u9700\u652f\u6301\u89c6\u89c9\uff1b\u7eaf\u6587\u672c\u6a21\u578b\u4f1a\u65e0\u89c6\u6216\u62a5\u9519\u2014\u2014\u6362\u5f15\u64ce\u662f Models \u7bc7\u5de5\u5382\u7684\u4e8b\u3002&#8221;<\/p>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\"><span>4. \u591a\u6a21\u6001\uff1a\u672c\u5730\u56fe\u7247\uff08base64\uff09\u4e0e OSS<\/span><\/h3>\n<p style=\"margin: 1em 0px;\">\u5bfc\u56fe\u539f\u8bdd\uff1a<\/p>\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid rgb(239, 112, 96); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; background: rgb(255, 249, 249);\">\n<p style=\"margin: 1em 0px;\">\u6240\u8c13\u672c\u5730\u56fe\u7247\uff0c\u5c31\u662f\u7528\u6237\u4e0a\u4f20\u7684\u56fe\u7247\u6570\u636e\u6216\u8005\u672c\u5730\u5b58\u5728\u7684\u56fe\u7247\uff0c\u800c\u4e0d\u662f\u56fe\u7247\u7684 url \u5730\u5740\u3002<br \/>\n\u6211\u4eec\u9700\u8981\u5c06\u56fe\u7247\u6570\u636e\u8f6c\u6362\u6210 base64 \u5b57\u7b26\u4e32\uff0c\u7136\u540e\u53d1\u9001\u7ed9\u6a21\u578b\u3002<br \/>\n\u53e6\u4e00\u65b9\u5f0f\uff1a\u4e0a\u4f20 OSS \u8f6c\u6210\u5728\u7ebf\u56fe\u7247\u3002<\/p>\n<\/blockquote>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">import<\/span> base64\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">from<\/span> pathlib <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">import<\/span> Path\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);\">image_file_to_data_url<\/span>(<span class=\"hljs-params\">path: <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  raw = Path(path).read_bytes()\n  b64 = base64.b64encode(raw).decode(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"ascii\"<\/span>)\n  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># jpeg\/png \u6309\u5b9e\u9645\u7c7b\u578b\u6539<\/span>\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">f\"data:image\/jpeg;base64,<span class=\"hljs-subst\" style=\"color: rgb(147, 161, 161);\">{b64}<\/span>\"<\/span>\n\n\nlocal_msg = HumanMessage(\n  content=[\n    {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"type\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"text\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"text\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u51b0\u7bb1\u91cc\u6709\u54ea\u4e9b\u98df\u6750\uff1f\u5217\u51fa\u540d\u79f0\u5373\u53ef\u3002\"<\/span>},\n    {\n      <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"type\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"image_url\"<\/span>,\n      <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"image_url\"<\/span>: {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"url\"<\/span>: image_file_to_data_url(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">r\"D:\\fridge.jpg\"<\/span>)},\n    },\n  ]\n)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u4e24\u6761\u8def\u600e\u4e48\u9009\uff1a<\/p>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all;\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top; font-weight: bold; background-color: rgb(255, 249, 249); color: rgb(239, 112, 96);\">\u65b9\u5f0f<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top; font-weight: bold; background-color: rgb(255, 249, 249); color: rgb(239, 112, 96);\">\u505a\u6cd5<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top; font-weight: bold; background-color: rgb(255, 249, 249); color: rgb(239, 112, 96);\">\u9002\u5408<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u5728\u7ebf URL<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\"><code>image_url.url = https:\/\/...<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u5df2\u6709\u516c\u7f51\u56fe\u3001CDN<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u672c\u5730 base64<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\"><code>data:image\/...;base64,...<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u7528\u6237\u4e0a\u4f20\u3001\u672c\u5730\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u5148 OSS \u518d URL<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u4e0a\u4f20\u540e\u5f53\u5728\u7ebf\u56fe\u7247<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid rgb(239, 112, 96); vertical-align: top;\">\u5927\u56fe\u3001\u8981\u590d\u7528\u3001\u63a7\u8bf7\u6c42\u4f53\u4f53\u79ef<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\u590d\u8ff0\uff1a&#8221;\u89d2\u8272\u8fd8\u662f\u90a3\u51e0\u7c7b\uff1b\u770b\u56fe\u53ea\u662f Human \u7684 content \u53d8\u5217\u8868\uff1b\u672c\u5730\u5c31 base64\uff0c\u6216\u8005\u5148\u53d8 URL\u3002&#8221;<\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid rgb(239, 112, 96); display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u603b\u7ed3<\/span><\/p>\n<section style=\"border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent; align-self: flex-end; height: 0px;\"><\/section>\n<\/h2>\n<p style=\"margin: 1em 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u7b2c\u56db\u7bc7\u53ea\u529e\u4e00\u4ef6\u4e8b\u2014\u2014\u8ba9\u6d88\u606f\u534f\u8bae\u80fd\u627f\u8f7d\u6587\u672c\u548c\u56fe\u7247\u3002&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">&#8220;\u4e09\u4e2a\u6838\u5fc3\u7406\u89e3\uff1a<\/p>\n<ol style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: decimal;\">\n<li>\n<section><strong>Messages \u662f\u5bf9\u8bdd\u7684\u5267\u672c<\/strong> \u2014\u2014 System \/ Human \/ AI \/ Tool \u5404\u53f8\u5176\u804c  <\/section>\n<\/li>\n<li>\n<section><strong>\u591a\u6a21\u6001\u4e0d\u6362\u89d2\u8272<\/strong> \u2014\u2014 \u5728 Human \u7684 content \u5217\u8868\u91cc\u6302 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(239, 112, 96); background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">image_url<\/code>  <\/section>\n<\/li>\n<li>\n<section><strong>\u672c\u5730\u56fe\u4e24\u6761\u8def<\/strong> \u2014\u2014 base64 data URL\uff0c\u6216 OSS \u8f6c\u5728\u7ebf URL&#8221;<\/section>\n<\/li>\n<\/ol>\n<p style=\"margin: 1em 0px;\">LangChain \u652f\u7ebf\u8fdb\u5ea6\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: rgb(0, 43, 54); max-width: 100%; overflow-wrap: normal;\"><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=\"word-break: normal; white-space: nowrap; 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; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: rgb(147, 161, 161); background: rgb(0, 43, 54); overflow-wrap: normal;\">\u8ba4\u8bc6 LangChain \u2192 Agent \u5feb\u901f\u5165\u95e8 \u2192 Models\n    \u2193\nMessages \u4e0e\u591a\u6a21\u6001\uff08\u672c\u7bc7\uff09\n    \u2193\nPrompts \/ LCEL \/ \u7ed3\u6784\u5316\u8f93\u51fa \u2192 Tools \u2192 Memory \u2192 AI\u79c1\u53a8\u2026\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\u8bf4\uff1a&#8221;\u4e0b\u4e00\u7bc7\u8be5\u628a Prompt \u6a21\u677f\u548c LCEL \u7ba1\u9053\u7cfb\u7edf\u5316\u4e86\u2014\u2014\u73b0\u5728 Messages \u624b\u5199\u5217\u8868\uff0c\u7528\u6a21\u677f\u4f1a\u66f4\u7701\u4e8b\u3002&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">&#8220;\u5bf9\u3002\u4e0b\u4e00\u7bc7\uff1a<strong>Prompts \/ LCEL \/ \u7ed3\u6784\u5316\u8f93\u51fa<\/strong>\u3002&#8221;<\/p>\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid rgb(239, 112, 96); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; background: rgb(255, 249, 249);\">\n<p style=\"margin: 1em 0px;\"><strong>\u5b57\u7b26\u4e32\u53ea\u80fd\u5bd2\u6684\uff1bMessages \u624d\u662f\u5e94\u7528\u534f\u8bae\u3002\u4f1a\u770b\u56fe\uff0c\u5148\u5b66\u4f1a\u628a\u56fe\u653e\u8fdb HumanMessage \u7684 content \u91cc\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u7bc7\u4f60\u628a\u5927\u8111\u63a5\u53e3\u9489\u6b7b\u4e86\u2014\u2014invoke \u65e2\u80fd\u5403\u5b57\u7b26\u4e32\uff0c\u4e5f\u80fd\u5403 Messages \u5217\u8868\u3002\u5b57\u7b26\u4e32\u53ea\u591f\u6253\u62db\u547c\uff1b\u6b63\u5f0f\u5bf9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3809,"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\/3808"}],"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=3808"}],"version-history":[{"count":1,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3808\/revisions"}],"predecessor-version":[{"id":3810,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3808\/revisions\/3810"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/media\/3809"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}