{"id":3821,"date":"2026-08-18T06:54:24","date_gmt":"2026-08-17T22:54:24","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=3821"},"modified":"2026-08-18T07:10:24","modified_gmt":"2026-08-17T23:10:24","slug":"prompts-%e4%b8%8e-lcel%ef%bc%9a%e6%8f%90%e7%a4%ba%e8%af%8d%e5%b7%a5%e7%a8%8b-%e7%bb%93%e6%9e%84%e5%8c%96%e8%be%93%e5%87%ba","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3821","title":{"rendered":"Prompts \u4e0e LCEL\uff1a\u63d0\u793a\u8bcd\u5de5\u7a0b + \u7ed3\u6784\u5316\u8f93\u51fa"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\">\u4e0a\u7bc7\u4f60\u628a Messages \u534f\u8bae\u5403\u900f\u4e86\u2014\u2014System \/ Human \/ AI \/ Tool\uff0c\u56fe\u6587\u4e5f\u80fd\u585e\u8fdb Human\u3002\u4f46\u6bcf\u8f6e\u624b\u5199\u6d88\u606f\u5217\u8868\u53c8\u81ed\u53c8\u957f\u3002\u8fd9\u7bc7\u8bb2 <strong>Prompt \u6a21\u677f<\/strong>\u3001<strong>LCEL \u7ba1\u9053<\/strong>\uff0c\u4ee5\u53ca\u600e\u6837\u7528\u6570\u636e\u7c7b\u578b\u62ff\u5230<strong>\u7ed3\u6784\u5316\u8f93\u51fa<\/strong>\u3002<\/p>\n<\/blockquote>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u5c0f\u660e\u70e6\u900f\u4e86\u300c\u590d\u5236\u7c98\u8d34\u4eba\u8bbe\u300d<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\u5199\u4e86\u4e09\u4e2a\u5c0f\u529f\u80fd\uff1a\u89e3\u91ca\u6982\u5ff5\u3001\u6539\u5199\u7528\u6237\u95ee\u9898\u3001\u751f\u6210\u6982\u5ff5\u5361\u7247\u3002\u6bcf\u4e2a\u6587\u4ef6\u90fd\u8fd9\u6837\u5f00\u5934\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">SystemMessage(content=<span class=\"hljs-string\" style=\"color: #859900;\">\"\u4f60\u662f\u7b80\u6d01\u7684\u52a9\u6559\u3002\u7528\u4e2d\u6587\u56de\u7b54\uff0c\u63a7\u5236\u5728 80 \u5b57\u4ee5\u5185\u3002\"<\/span>)\nHumanMessage(content=<span class=\"hljs-string\" style=\"color: #859900;\">\"\u8bf7\u89e3\u91ca\u6982\u5ff5\uff1aLCEL\"<\/span>)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6539\u4eba\u8bbe\u8981\u6539\u4e09\u5904\uff1b\u7528\u6237\u8f93\u5165\u5e26\u7a7a\u683c\u8fd8\u5f97\u81ea\u5df1 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">.strip()<\/code>\uff1b\u8981\u524d\u7aef\u8868\u683c\u5b57\u6bb5\u65f6\uff0c\u4ed6\u53c8\u8ba9\u6a21\u578b\u300c\u8f93\u51fa JSON\u300d\uff0c\u7136\u540e <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">json.loads<\/code>\u2014\u2014\u6a21\u578b\u5076\u5c14\u591a\u4e00\u53e5\u5e9f\u8bdd\uff0c\u89e3\u6790\u76f4\u63a5\u70b8\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4ed6\u53bb\u627e\u8001\u5f20\uff1a&#8221;Messages \u6211\u4f1a\u62fc\u4e86\uff0c\u6709\u6ca1\u6709\u6a21\u677f + \u7ba1\u9053\uff1f\u7ed3\u6784\u5316\u80fd\u4e0d\u80fd\u522b\u624b\u5199\u89e3\u6790\uff1f&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u6709\u3002\u63d0\u793a\u8bcd\u5de5\u7a0b + LCEL\uff1a\u4eba\u8bbe\u8fdb\u6a21\u677f\uff0c\u53d8\u91cf\u8fdb\u5360\u4f4d\u7b26\uff0c<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">|<\/code> \u4e32\u6210\u94fe\uff1b\u8981\u5b57\u6bb5\u5c31\u5148\u5b9a\u4e49\u6570\u636e\u7c7b\u578b\uff0c\u518d <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">with_structured_output<\/code>\u3002&#8221;<\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4ec0\u4e48\u662f Prompts\u3001LCEL\u3001\u7ed3\u6784\u5316\u8f93\u51fa<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u8001\u5f20\u5728\u767d\u677f\u4e0a\u5206\u4e09\u5757\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">1) System Prompt\n   \u521b\u5efa Agent \u65f6\u53ef system_prompt= \u4e00\u6b21\u8bbe\u5b9a\n   \u4e0d\u5fc5\u6bcf\u8f6e\u5728 Messages \u91cc\u91cd\u590d\u8d34\n\n2) \u63d0\u793a\u8bcd\u5de5\u7a0b\uff08Prompt Engineering\uff09\n   \u4f18\u5316 System \/ \u6307\u4ee4\uff0c\u8ba9\u8f93\u51fa\u66f4\u7406\u60f3\n   - \u8bbe\u5b9a\u89d2\u8272\u4e0e\u8be6\u7ec6\u6307\u4ee4\n   - Few-shot\uff1a\u7ed9\u51e0\u4e2a\u8f93\u5165\u2192\u8f93\u51fa\u6837\u4f8b\n   - \u7ed3\u6784\u5316\u8f93\u51fa\uff1a\u522b\u53ea\u9760\u300c\u8bf7\u8f93\u51fa JSON\u300d\n\n3) LCEL\n   ChatPromptTemplate | model | parser\n   \u94fe\u4e0a\u540c\u6837\u6709 invoke \/ stream\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6bd4\u55bb\uff1a<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section><strong>\u624b\u5199 Messages<\/strong> = \u6bcf\u6b21\u70b9\u83dc\u90fd\u628a\u5e97\u89c4\u5ff5\u4e00\u904d<\/section>\n<\/li>\n<li>\n<section><strong>ChatPromptTemplate<\/strong> = \u628a\u5e97\u89c4\u5370\u5728\u83dc\u5355\u6a21\u677f\u4e0a\uff0c\u53ea\u586b <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">{topic}<\/code><\/section>\n<\/li>\n<li>\n<section><strong>LCEL <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">|<\/code><\/strong> = \u4f20\u83dc\u6d41\u6c34\u7ebf\uff1a\u586b\u5355 \u2192 \u53a8\u5e08 \u2192 \u88c5\u76d8<\/section>\n<\/li>\n<li>\n<section><strong>\u7ed3\u6784\u5316\u8f93\u51fa<\/strong> = \u4e0d\u8981\u6563\u6587\u8bd7\uff0c\u76f4\u63a5\u6309\u8868\u683c\u5b57\u6bb5\u51fa\u83dc<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u5728 LangChain \u91cc\u505a\u7ed3\u6784\u5316\uff0c\u5f80\u5f80<strong>\u4e0d\u5fc5<\/strong>\u81ea\u5df1\u5728\u63d0\u793a\u8bcd\u91cc\u63cf\u8ff0 JSON \u5f62\u72b6\uff0c\u800c\u662f<strong>\u8bbe\u5b9a\u597d\u4e00\u4e2a\u6570\u636e\u7c7b\u578b<\/strong>\u3002<\/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; height: 238px;\" width=\"817\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u65b9\u5f0f<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u4f60\u5199\u4ec0\u4e48<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u5f97\u5230\u4ec0\u4e48<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u624b\u5199 Messages<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u6bcf\u8f6e System+Human<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">AIMessage \u6587\u672c<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Prompt \u6a21\u677f<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><code>(\"system\",...)<\/code> + <code>{var}<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u586b\u53d8\u91cf\u540e\u53d8 Messages<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">LCEL \u94fe<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\"><code>prompt | model | parser<\/code><\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5e38\u4e3a <code>str<\/code> \u6216\u7ee7\u7eed\u5f80\u540e\u63a5<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">with_structured_output<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Pydantic \/ schema<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5bf9\u8c61\u5b57\u6bb5\uff0c\u53ef\u76f4\u63a5\u8bfb<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\uff1a&#8221;\u548c Agent \u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">system_prompt<\/code> \u5565\u5173\u7cfb\uff1f&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">&#8220;\u540c\u4e00\u4ef6\u4e8b\u7684\u4e24\u79cd\u6302\u6cd5\uff1a\u94fe\u7528\u6a21\u677f\u91cc\u7684 system \u53e5\uff1bAgent \u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">create_agent(..., system_prompt=...)<\/code>\u3002\u90fd\u662f\u4eba\u8bbe\uff0c\u53ea\u662f\u5165\u53e3\u4e0d\u540c\u3002&#8221;<\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4ee3\u7801\u62c6\u89e3\uff1a\u6a21\u677f \u2192 \u7ba1\u9053 \u2192 \u7ed3\u6784\u5316<\/span><\/h2>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">1. ChatPromptTemplate + LCEL<\/h3>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">from<\/span> langchain_core.output_parsers <span class=\"hljs-keyword\" style=\"color: #6c71c4;\">import<\/span> StrOutputParser\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">from<\/span> langchain_core.prompts <span class=\"hljs-keyword\" style=\"color: #6c71c4;\">import<\/span> ChatPromptTemplate\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">from<\/span> llm <span class=\"hljs-keyword\" style=\"color: #6c71c4;\">import<\/span> get_chat_model\n\n\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span> <span class=\"hljs-title function_\" style=\"color: #268bd2;\">build_explain_chain<\/span>():\n  <span class=\"hljs-string\" style=\"color: #859900;\">\"\"\"\u6a21\u677f \u2192 \u6a21\u578b \u2192 \u5b57\u7b26\u4e32\u3002\"\"\"<\/span>\n  model = get_chat_model(temperature=<span class=\"hljs-number\" style=\"color: #cb4b16;\">0.4<\/span>)\n\n  prompt = ChatPromptTemplate.from_messages(\n    [\n      (<span class=\"hljs-string\" style=\"color: #859900;\">\"system\"<\/span>, <span class=\"hljs-string\" style=\"color: #859900;\">\"\u4f60\u662f\u7b80\u6d01\u7684\u52a9\u6559\u3002\u7528\u4e2d\u6587\u56de\u7b54\uff0c\u63a7\u5236\u5728 80 \u5b57\u4ee5\u5185\u3002\"<\/span>),\n      (<span class=\"hljs-string\" style=\"color: #859900;\">\"human\"<\/span>, <span class=\"hljs-string\" style=\"color: #859900;\">\"\u8bf7\u89e3\u91ca\u6982\u5ff5\uff1a{topic}\"<\/span>),\n    ]\n  )\n\n  <span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span> prompt | model | StrOutputParser()\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u4e09\u6b65\uff1a<\/p>\n<ol style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: decimal;\">\n<li>\n<section><strong>\u6a21\u677f<\/strong> \u2014\u2014 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">(\"system\", ...)<\/code> \/ <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">(\"human\", \"{topic}\")<\/code>\uff0c\u5143\u7ec4\u5199\u6cd5\u5bf9\u5e94\u4e0a\u7bc7\u7684\u6d88\u606f\u89d2\u8272<\/section>\n<\/li>\n<li>\n<section><strong>\u7ba1\u9053<\/strong> \u2014\u2014 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">prompt | model | StrOutputParser()<\/code>\uff1a\u586b\u53d8\u91cf \u2192 \u8c03\u6a21\u578b \u2192 \u53ea\u8981 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">.content<\/code> \u5b57\u7b26\u4e32<\/section>\n<\/li>\n<li>\n<section><strong>\u8c03\u7528<\/strong> \u2014\u2014 \u4f20\u5165\u5b57\u5178\uff0c\u4e0d\u662f\u88f8\u5b57\u7b26\u4e32\uff1a&#8221;<\/section>\n<\/li>\n<\/ol>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">chain = build_explain_chain()\n<span class=\"hljs-built_in\" style=\"color: #2aa198;\">print<\/span>(chain.invoke({<span class=\"hljs-string\" style=\"color: #859900;\">\"topic\"<\/span>: <span class=\"hljs-string\" style=\"color: #859900;\">\"LCEL \u7ba1\u9053 |\"<\/span>}))\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6d41\u5f0f\u540c\u6837\u6302\u5728\u94fe\u4e0a\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">for<\/span> chunk <span class=\"hljs-keyword\" style=\"color: #6c71c4;\">in<\/span> chain.stream({<span class=\"hljs-string\" style=\"color: #859900;\">\"topic\"<\/span>: <span class=\"hljs-string\" style=\"color: #859900;\">\"PromptTemplate\"<\/span>}):\n  <span class=\"hljs-built_in\" style=\"color: #2aa198;\">print<\/span>(chunk, end=<span class=\"hljs-string\" style=\"color: #859900;\">\"\"<\/span>, flush=<span class=\"hljs-literal\" style=\"color: #cb4b16;\">True<\/span>)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;\u5b66\u4e60\u76ee\u6807\u5bf9\u4e0a\u4e86\uff1a\u89e3\u91ca\u7f16\u6392\u5c42\u5b9a\u4f4d\uff1b\u5199\u51fa\u5e26\u53d8\u91cf\u7684 ChatPromptTemplate\uff1b\u8dd1\u901a\u94fe\u4e0a invoke \u4e0e stream\u3002&#8221;<\/p>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">2. Runnable \u9884\u5904\u7406\u518d\u8fdb Prompt<\/h3>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span> <span class=\"hljs-title function_\" style=\"color: #268bd2;\">build_rewrite_chain<\/span>():\n  model = get_chat_model(temperature=<span class=\"hljs-number\" style=\"color: #cb4b16;\">0.2<\/span>)\n  prompt = ChatPromptTemplate.from_messages(\n    [\n      (<span class=\"hljs-string\" style=\"color: #859900;\">\"system\"<\/span>, <span class=\"hljs-string\" style=\"color: #859900;\">\"\u628a\u7528\u6237\u8f93\u5165\u6539\u5199\u6210\u66f4\u6e05\u6670\u7684\u4e2d\u6587\u95ee\u9898\uff0c\u4e0d\u8981\u56de\u7b54\u95ee\u9898\u3002\u4e0d\u8d85\u8fc7 40 \u5b57\u3002\"<\/span>),\n      (<span class=\"hljs-string\" style=\"color: #859900;\">\"human\"<\/span>, <span class=\"hljs-string\" style=\"color: #859900;\">\"{raw}\"<\/span>),\n    ]\n  )\n\n  <span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span> (\n    RunnablePassthrough.assign(raw=RunnableLambda(<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">lambda<\/span> x: x[<span class=\"hljs-string\" style=\"color: #859900;\">\"raw\"<\/span>].strip()))\n    | prompt\n    | model\n    | StrOutputParser()\n  )\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;System \u5199\u6b7b\u884c\u4e3a\uff1a<strong>\u53ea\u6539\u5199\u3001\u4e0d\u56de\u7b54\u3001\u9650\u957f<\/strong>\u2014\u2014\u8fd9\u5c31\u662f\u63d0\u793a\u8bcd\u5de5\u7a0b\u91cc\u7684\u300c\u8be6\u7ec6\u6307\u4ee4\u300d\u3002<br \/>\n<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">assign + strip<\/code> \u628a\u810f\u8f93\u5165\u6d17\u5e72\u51c0\uff0c\u518d\u8fdb\u6a21\u677f\u3002Messages\u3001Runnable\u3001Prompt \u5728\u4e00\u6761\u94fe\u91cc\u78b0\u5934\u3002&#8221;<\/p>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">3. \u7ed3\u6784\u5316\u8f93\u51fa\uff1a\u5148\u5b9a\u4e49\u7c7b\u578b<\/h3>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">schemas.py<\/code>\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">from<\/span> pydantic <span class=\"hljs-keyword\" style=\"color: #6c71c4;\">import<\/span> BaseModel, Field\n\n\n<span class=\"hljs-keyword\" style=\"color: #6c71c4;\">class<\/span> <span class=\"hljs-title class_\" style=\"color: #b58900;\">ConceptCard<\/span>(<span class=\"hljs-title class_ inherited__\" style=\"color: #859900;\">BaseModel<\/span>):\n  name: <span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span> = Field(description=<span class=\"hljs-string\" style=\"color: #859900;\">\"\u6982\u5ff5\u540d\u79f0\"<\/span>)\n  one_liner: <span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span> = Field(description=<span class=\"hljs-string\" style=\"color: #859900;\">\"\u4e00\u53e5\u8bdd\u89e3\u91ca\"<\/span>)\n  when_to_use: <span class=\"hljs-built_in\" style=\"color: #2aa198;\">str<\/span> = Field(description=<span class=\"hljs-string\" style=\"color: #859900;\">\"\u9002\u7528\u573a\u666f\"<\/span>)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">llm.py<\/code>\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span> <span class=\"hljs-title function_\" style=\"color: #268bd2;\">get_structured_model<\/span>(<span class=\"hljs-params\">schema: <span class=\"hljs-type\" style=\"color: #6c71c4;\">Type<\/span>[BaseModel], *, temperature: <span class=\"hljs-built_in\" style=\"color: #2aa198;\">float<\/span> = <span class=\"hljs-number\" style=\"color: #cb4b16;\">0<\/span><\/span>):\n  <span class=\"hljs-string\" style=\"color: #859900;\">\"\"\"\u8fd4\u56de with_structured_output \u540e\u7684\u6a21\u578b\u3002\"\"\"<\/span>\n  <span class=\"hljs-keyword\" style=\"color: #6c71c4;\">return<\/span> get_chat_model(temperature=temperature).with_structured_output(schema)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">main.py<\/code> \u6f14\u793a C\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"><span class=\"hljs-keyword\" style=\"color: #6c71c4;\">def<\/span> <span class=\"hljs-title function_\" style=\"color: #268bd2;\">demo_structured_output<\/span>() -&gt; <span class=\"hljs-literal\" style=\"color: #cb4b16;\">None<\/span>:\n  card = get_structured_model(ConceptCard).invoke(\n    <span class=\"hljs-string\" style=\"color: #859900;\">\"\u8bf7\u7528\u7ed3\u6784\u5316\u5b57\u6bb5\u89e3\u91ca\uff1aLangChain \u7684 Runnable \u662f\u4ec0\u4e48\u3002\"<\/span>\n  )\n  <span class=\"hljs-built_in\" style=\"color: #2aa198;\">print<\/span>(card.model_dump_json(indent=<span class=\"hljs-number\" style=\"color: #cb4b16;\">2<\/span>, ensure_ascii=<span class=\"hljs-literal\" style=\"color: #cb4b16;\">False<\/span>))\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u7528\u6cd5\u5fc3\u667a\uff1a<\/p>\n<ol style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: decimal;\">\n<li>\n<section><strong>\u5c01\u88c5\u8981\u8f93\u51fa\u7684\u6570\u636e<\/strong> \u2014\u2014 Pydantic \u6a21\u578b + Field \u63cf\u8ff0<\/section>\n<\/li>\n<li>\n<section><strong>with_structured_output(schema)<\/strong> \u2014\u2014 \u6a21\u578b\u6309 schema \u5410\u5bf9\u8c61<\/section>\n<\/li>\n<li>\n<section><strong>\u8bfb\u5b57\u6bb5<\/strong> \u2014\u2014 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">card.name<\/code> \/ <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">card.one_liner<\/code>\uff0c\u6216 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">model_dump_json<\/code><\/section>\n<\/li>\n<\/ol>\n<p style=\"margin: 1em 0px;\">\u6ce8\u91ca\u5199\u5f97\u5f88\u6e05\u695a\uff1a\u5e95\u5c42\u53ef\u80fd\u8d70 tool \/ JSON mode\uff0c\u6bd4\u300c\u7eaf\u6587\u672c\u518d json.loads\u300d\u7a33\u3002\u6559\u5b66\u4e0a\u4ecd\u53ef\u5b66 Output Parser\uff1b\u751f\u4ea7\u4f18\u5148 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">with_structured_output<\/code>\u3002<\/p>\n<p style=\"margin: 1em 0px;\">Agent \u8def\u7ebf\u8fd8\u4f1a\u89c1\u5230 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">response['structured_response']<\/code>\u2014\u2014\u90a3\u662f\u521b\u5efa Agent \u65f6\u6302\u8f93\u51fa\u683c\u5f0f\u540e\u7684\u5b57\u6bb5\u540d\u3002<\/p>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">4. Agent \u4e0a\u7684 System Prompt\uff08\u5bf9\u7167\uff09<\/h3>\n<p style=\"margin: 1em 0px;\">\u4e0a\u7bc7\u7cfb\u5217 \u5df2\u51fa\u73b0\u8fc7\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs language-python\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">agent = create_agent(\n  get_chat_model(temperature=<span class=\"hljs-number\" style=\"color: #cb4b16;\">0<\/span>),\n  tools=TOOLS,\n  system_prompt=<span class=\"hljs-string\" style=\"color: #859900;\">\"\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)\n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">&#8220;\u94fe\uff1a\u4eba\u8bbe\u5728 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">ChatPromptTemplate<\/code> \u7684 system \u53e5\u3002<br \/>\nAgent\uff1a\u4eba\u8bbe\u5728 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">system_prompt=<\/code>\u3002<br \/>\nFew-shot\uff1a\u53ef\u5728\u6a21\u677f\u91cc\u591a\u51e0\u8f6e <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">(\"human\", ...)<\/code>, <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">(\"ai\", ...)<\/code> \u6837\u4f8b\u2014\u2014\u672c\u7bc7\u5148\u638c\u63e1\u6a21\u677f\u53d8\u91cf + \u7ed3\u6784\u5316\uff0cFew-shot \u4f5c\u63d0\u793a\u8bcd\u5de5\u7a0b\u83dc\u5355\u9879\u8bb0\u4f4f\u5373\u53ef\u3002&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">\u5c0f\u660e\u590d\u8ff0\uff1a&#8221;\u6a21\u677f\u586b\u53d8\u91cf\uff1b\u7ad6\u7ebf\u7ec4\u6d41\u6c34\u7ebf\uff1b\u8981\u8868\u683c\u5c31\u5148\u5199 Pydantic\u3002&#8221;<\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u603b\u7ed3<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u7b2c\u4e94\u7bc7\u53ea\u529e\u4e00\u4ef6\u4e8b\u2014\u2014\u7528\u6a21\u677f\u548c\u7c7b\u578b\uff0c\u53d6\u4ee3\u590d\u5236\u7c98\u8d34\u4e0e\u8106\u5f31 JSON\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>ChatPromptTemplate<\/strong> \u2014\u2014 \u4eba\u8bbe\u4e0e\u6307\u4ee4\u8fdb\u6a21\u677f\uff0c\u53d8\u91cf\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">{\u5360\u4f4d\u7b26}<\/code><\/section>\n<\/li>\n<li>\n<section><strong>LCEL<\/strong> \u2014\u2014 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">prompt | model | parser<\/code>\uff0c\u94fe\u4e0a invoke \/ stream<\/section>\n<\/li>\n<li>\n<section><strong>\u7ed3\u6784\u5316\u8f93\u51fa<\/strong> \u2014\u2014 \u5148\u5b9a\u4e49\u6570\u636e\u7c7b\u578b\uff0c\u518d <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">with_structured_output<\/code>\uff0c\u76f4\u63a5\u8bfb\u5b57\u6bb5&#8221;<\/section>\n<\/li>\n<\/ol>\n<p style=\"margin: 1em 0px;\">LangChain \u652f\u7ebf\u8fdb\u5ea6\uff1a<\/p>\n<section style=\"display: block; background-repeat: no-repeat; width: 100%; height: 16px;\"><\/section>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\u2026 \u2192 Messages \u4e0e\u591a\u6a21\u6001\n    \u2193\nPrompts \/ LCEL \/ \u7ed3\u6784\u5316\u8f93\u51fa\uff08\u672c\u7bc7\uff09\n    \u2193\nTools \u4e0e Tool Agent \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\u7cfb\u7edf\u770b Tools \u4e86\u2014\u2014<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">@tool<\/code>\u3001\u591a\u5de5\u5177\u3001\u548c Agent \u5faa\u73af\u600e\u4e48\u5de5\u7a0b\u5316\u3002&#8221;<\/p>\n<p style=\"margin: 1em 0px;\">&#8220;\u5bf9\u3002\u4e0b\u4e00\u7bc7\uff1a<strong>Tools \u4e0e Tool Agent<\/strong>\u3002&#8221;<\/p>\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\"><strong>\u63d0\u793a\u8bcd\u5de5\u7a0b\u4e0d\u662f\u7384\u5b66\u5806\u5f62\u5bb9\u8bcd\uff1b\u662f\u628a\u4eba\u8bbe\u3001\u6837\u4f8b\u3001\u8f93\u51fa\u5f62\u72b6\u5199\u8fdb\u53ef\u590d\u7528\u7684\u6a21\u677f\u4e0e\u7c7b\u578b\u91cc\u3002LCEL \u8ba9\u8fd9\u4e9b\u96f6\u4ef6\u53d8\u6210\u7ba1\u9053\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u7bc7\u4f60\u628a Messages \u534f\u8bae\u5403\u900f\u4e86\u2014\u2014System \/ Human \/ AI \/ Tool\uff0c\u56fe\u6587\u4e5f\u80fd\u585e\u8fdb  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3822,"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\/3821"}],"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=3821"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3821\/revisions"}],"predecessor-version":[{"id":3828,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3821\/revisions\/3828"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/media\/3822"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}