{"id":3769,"date":"2026-08-17T15:05:55","date_gmt":"2026-08-17T07:05:55","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=3769"},"modified":"2026-08-17T15:05:55","modified_gmt":"2026-08-17T07:05:55","slug":"agent%e4%b9%8b%e8%ae%b0%e5%bf%86memory-%e6%b6%88%e6%81%af%e9%93%be%e5%b0%b1%e6%98%af%e5%a4%a7%e8%84%91","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3769","title":{"rendered":"Agent\u4e4b\u8bb0\u5fc6memory-\u6d88\u606f\u94fe\u5c31\u662f\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\u5b66\u4f1a\u4e86 MCP\u2014\u2014\u7528\u6807\u51c6\u534f\u8bae\u63a5\u5165\u5168\u4e16\u754c\u7684\u5de5\u5177\u3002\u4f46\u5de5\u5177\u591a\u4e86\u3001\u5bf9\u8bdd\u957f\u4e86\uff0c\u4e00\u4e2a\u65b0\u95ee\u9898\u5192\u51fa\u6765\uff1a<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">Agent \u8bb0\u4e0d\u4f4f\u521a\u624d\u8bf4\u8fc7\u4ec0\u4e48<\/strong>\u3002\u8fd9\u7bc7\u8bb2 Agent \u7684\u8bb0\u5fc6\u673a\u5236\u2014\u2014\u4e3a\u4ec0\u4e48\u6d88\u606f\u5217\u8868\u5c31\u662f Agent \u7684\u5927\u8111\uff0c\u4ee5\u53ca Function Calling \u4e4b\u540e\u8bb0\u5fc6\u600e\u4e48\u7ef4\u62a4\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 AI \u5931\u5fc6\u4e86<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u5c0f\u660e\u7684 Agent \u8dd1\u5f97\u5f88\u597d\u3002\u67e5\u5929\u6c14\u3001\u641c\u65b0\u95fb\u3001\u7b97\u6570\u5b66\uff0c\u6837\u6837\u90fd\u884c\u3002<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u4f46\u4eca\u5929\u6d4b\u8bd5\u65f6\u9047\u5230\u4e86\u4e00\u4e2a\u5947\u602a\u7684\u73b0\u8c61\u2014\u2014<\/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);\">\u4f60\uff1a\u6211\u53eb\u5c0f\u660e\nAgent\uff1a\u4f60\u597d\u5c0f\u660e\uff0c\u6709\u4ec0\u4e48\u53ef\u4ee5\u5e2e\u4f60\u7684\uff1f\n\n\u4f60\uff1a\u5e2e\u6211\u67e5\u4e00\u4e0b\u6210\u90fd\u5929\u6c14\nAgent\uff1a\u6210\u90fd\u591a\u4e91\uff0c16\u00b0C\uff0c\u5fae\u98ce\u3002\n\n\u4f60\uff1a\u6211\u521a\u624d\u8bf4\u6211\u53eb\u4ec0\u4e48\u540d\u5b57\uff1f\nAgent\uff1a\u4f60\u6ca1\u6709\u544a\u8bc9\u6211\u4f60\u7684\u540d\u5b57\u3002\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\u6123\u4f4f\u4e86\u3002&#8221;\u6211\u521a\u624d\u7b2c\u4e00\u53e5\u8bdd\u5c31\u8bf4\u4e86\u554a\uff01\u5b83\u600e\u4e48\u5c31\u5fd8\u4e86\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u4ed6\u53bb\u627e\u8001\u5f20\u3002\u8001\u5f20\u8bf4\uff1a&#8221;\u56e0\u4e3a\u5927\u6a21\u578b<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u6ca1\u6709\u8bb0\u5fc6<\/strong>\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u4ec0\u4e48\u610f\u601d\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u6bcf\u4e00\u6b21 API \u8c03\u7528\u90fd\u662f\u72ec\u7acb\u7684\u3002\u4f60\u7b2c\u4e00\u6b21\u53d1&#8217;\u6211\u53eb\u5c0f\u660e&#8217;\u548c\u7b2c\u4e8c\u6b21\u53d1&#8217;\u6211\u521a\u624d\u8bf4\u6211\u53eb\u4ec0\u4e48\u540d\u5b57&#8217;\u2014\u2014\u8fd9\u4e24\u6b21\u8c03\u7528\u4e4b\u95f4\u6ca1\u6709\u4efb\u4f55\u5173\u8054\u3002\u6a21\u578b\u4e0d\u8bb0\u5f97\u4e0a\u4e00\u8f6e\u7684\u5bf9\u8bdd\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\u8bf4\uff1a&#8221;\u53ef\u6211\u4e4b\u524d\u7684 Agent \u660e\u660e\u80fd\u8bb0\u4f4f\u4e0a\u4e0b\u6587\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u90a3\u4f60\u8981\u68c0\u67e5\u4e00\u4e0b\u2014\u2014\u4f60\u6bcf\u6b21\u8c03\u7528 API \u65f6\uff0c\u4f20\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">messages<\/code> \u5217\u8868\u91cc\u5230\u5e95\u6709\u51e0\u79cd\u6d88\u606f\u3002\u5982\u679c\u53ea\u4f20\u4e86\u5f53\u524d\u7528\u6237\u8f93\u5165\u8fd9\u4e00\u6761\uff0c\u6a21\u578b\u5f53\u7136\u53ea\u80fd\u6839\u636e\u8fd9\u4e00\u6761\u56de\u7b54\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;\">\u6838\u5fc3\u8ba4\u77e5\uff1aLLM \u65e0\u72b6\u6001\uff0c\u8bb0\u5fc6\u662f\u4f60\u4f20\u7684<\/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\u4e86\u56db\u4e2a\u5b57\uff1a<\/p>\n<blockquote style=\"color: rgb(85, 85, 85); background-color: rgb(255, 249, 235); background-image: none; padding: 16px 20px; margin: 20px 0px; border-width: 0px 0px 0px 4px; border-style: none none none solid; border-color: currentcolor currentcolor currentcolor rgb(248, 180, 63); border-radius: 6px; font-style: normal; quotes: none;\">\n<p style=\"margin: 0.55em 0px; color: rgb(85, 85, 85); text-indent: 0px; padding: 0px; line-height: 1.75; font-style: normal; background: transparent;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u6a21\u578b\u65e0\u72b6\u6001<\/strong><\/p>\n<\/blockquote>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5927\u6a21\u578b\u672c\u8eab\u4e0d\u5b58\u50a8\u4efb\u4f55\u5bf9\u8bdd\u5386\u53f2\u3002\u6bcf\u6b21 API \u8c03\u7528\u90fd\u662f\u4e00\u6b21&#8217;\u521d\u6b21\u89c1\u9762&#8217;\u3002\u6a21\u578b\u80fd&#8217;\u8bb0\u4f4f&#8217;\u4e4b\u524d\u8bf4\u8fc7\u4ec0\u4e48\uff0c\u662f\u56e0\u4e3a<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4f60\u628a\u5b8c\u6574\u7684\u5386\u53f2\u6d88\u606f\u90fd\u653e\u8fdb\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;\">messages<\/code> \u5217\u8868\u91cc\uff0c\u6bcf\u6b21\u90fd\u91cd\u65b0\u4f20\u4e00\u904d\u3002<\/strong>&#8220;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u4ed6\u753b\u4e86\u5f20\u56fe\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);\">\u7b2c 1 \u8f6e\uff1a\n  \u4f60\u53d1\u7ed9\u6a21\u578b \u2192 [{\"role\":\"user\",\"content\":\"\u6211\u53eb\u5c0f\u660e\"}]\n  \u6a21\u578b\u8fd4\u56de   \u2192 \"\u4f60\u597d\u5c0f\u660e\"\n  \u2705 \u6a21\u578b\u77e5\u9053\u7528\u6237\u53eb\u5c0f\u660e\uff08\u56e0\u4e3a\u6d88\u606f\u91cc\u6709\uff09\n\n\u7b2c 2 \u8f6e\uff08\u6ca1\u4f20\u5386\u53f2\uff09\uff1a\n  \u4f60\u53d1\u7ed9\u6a21\u578b \u2192 [{\"role\":\"user\",\"content\":\"\u6211\u521a\u624d\u8bf4\u6211\u53eb\u4ec0\u4e48\u540d\u5b57\uff1f\"}]\n  \u6a21\u578b\u8fd4\u56de   \u2192 \"\u4f60\u6ca1\u6709\u544a\u8bc9\u6211\u4f60\u7684\u540d\u5b57\u3002\"\n  \u274c \u6a21\u578b\u4e0d\u77e5\u9053\uff08\u56e0\u4e3a\u4e0a\u8f6e\u7684\u6d88\u606f\u6ca1\u4f20\u8fc7\u53bb\uff09\n\n\u7b2c 2 \u8f6e\uff08\u4f20\u4e86\u5386\u53f2\uff09\uff1a\n  \u4f60\u53d1\u7ed9\u6a21\u578b \u2192 [\n  {\"role\":\"user\",\"content\":\"\u6211\u53eb\u5c0f\u660e\"},\n  {\"role\":\"assistant\",\"content\":\"\u4f60\u597d\u5c0f\u660e\"},\n  {\"role\":\"user\",\"content\":\"\u6211\u521a\u624d\u8bf4\u6211\u53eb\u4ec0\u4e48\u540d\u5b57\uff1f\"}\n  ]\n  \u6a21\u578b\u8fd4\u56de   \u2192 \"\u4f60\u521a\u624d\u8bf4\u4f60\u53eb\u5c0f\u660e\u3002\"\n  \u2705 \u6a21\u578b\u77e5\u9053\uff08\u56e0\u4e3a\u5b8c\u6574\u5386\u53f2\u90fd\u4f20\u4e86\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;\u770b\u660e\u767d\u6ca1\uff1f\u6a21\u578b\u80fd\u4e0d\u80fd&#8217;\u8bb0\u4f4f&#8217;\uff0c\u4e0d\u53d6\u51b3\u4e8e\u6a21\u578b\u672c\u8eab\uff0c\u53d6\u51b3\u4e8e<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4f60\u7684\u7a0b\u5e8f\u6709\u6ca1\u6709\u628a\u5386\u53f2\u6d88\u606f\u5e26\u4e0a<\/strong>\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\u604d\u7136\u5927\u609f\uff1a&#8221;\u6240\u4ee5 Agent \u7684\u8bb0\u5fc6\u672c\u8d28\u4e0a\u5c31\u662f\u4e00\u4e2a\u5217\u8868\u2014\u2014\u6bcf\u6b21\u8bf7\u6c42\u628a\u6574\u4e2a\u5217\u8868\u4f20\u7ed9\u6a21\u578b\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<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u6d88\u606f\u5217\u8868\u5c31\u662f Agent \u7684\u77ed\u671f\u8bb0\u5fc6\u3002<\/strong> \u4f60\u5199\u4e0d\u5199\u6570\u636e\u5e93\u3001\u7528\u4e0d\u7528\u5411\u91cf\u5b58\u50a8\u90fd\u4e0d\u91cd\u8981\u2014\u2014\u53ea\u8981\u4f60\u6bcf\u6b21 API \u8c03\u7528\u90fd\u4f20\u5b8c\u6574\u7684\u5386\u53f2\u6d88\u606f\uff0cAgent \u5c31\u80fd\u5b9e\u73b0\u6700\u57fa\u672c\u7684&#8217;\u591a\u8f6e\u5bf9\u8bdd\u8bb0\u5fc6&#8217;\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;\">\u666e\u901a\u5bf9\u8bdd\u7684\u8bb0\u5fc6\u5f88\u7b80\u5355<\/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;\u5728\u6ca1\u6709 Function Calling \u65f6\uff0c\u6d88\u606f\u5217\u8868\u7684\u7ed3\u6784\u5f88\u7b80\u5355\u2014\u2014\u4e09\u79cd\u89d2\u8272\u8f6e\u8f6c\uff1a&#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);\">messages = [\n  {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"system\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4f60\u662f\u4e00\u4e2a\u667a\u80fd\u52a9\u624b...\"<\/span>},\n  {<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>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6211\u53eb\u5c0f\u660e\"<\/span>},\n  {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"assistant\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4f60\u597d\u5c0f\u660e\uff01\"<\/span>},\n  {<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>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u5e2e\u6211\u67e5\u5929\u6c14\"<\/span>},\n  {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"assistant\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u597d\u7684\uff0c\u8bf7\u544a\u8bc9\u6211\u8981\u67e5\u54ea\u4e2a\u57ce\u5e02\uff1f\"<\/span>},\n  {<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>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6210\u90fd\"<\/span>},\n  {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"assistant\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6210\u90fd\u4eca\u5929\u591a\u4e91...\"<\/span>},\n]\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 align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u8f6e\u6b21<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">messages \u65b0\u589e<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u7b2c 1 \u8f6e<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>user(\"\u6211\u53eb\u5c0f\u660e\")<\/code> \u2192 <code>assistant(\"\u4f60\u597d\u5c0f\u660e\")<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u4e00\u95ee\u4e00\u7b54<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u7b2c 2 \u8f6e<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>user(\"\u67e5\u5929\u6c14\")<\/code> \u2192 <code>assistant(\"\u54ea\u4e2a\u57ce\u5e02\uff1f\")<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u8ffd\u95ee<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u7b2c 3 \u8f6e<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>user(\"\u6210\u90fd\")<\/code> \u2192 <code>assistant(\"\u591a\u4e91\")<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u8865\u5145\u4fe1\u606f<\/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;\">&#8220;\u6d41\u7a0b\u5f88\u7b80\u5355\u2014\u2014\u6bcf\u6b21\u5bf9\u8bdd\u8ffd\u52a0\u4e24\u6761\u6d88\u606f\uff08user + assistant\uff09\uff0c\u8c03\u7528 API \u65f6\u628a\u6574\u4e2a\u5217\u8868\u4f20\u8fc7\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;\">Function Calling \u8ba9\u8bb0\u5fc6\u53d8\u590d\u6742\u4e86<\/span><\/h2>\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;\u4f46\u8fd9\u548c\u666e\u901a\u7684\u804a\u5929\u8bb0\u5f55\u5dee\u4e0d\u591a\u554a\u3002\u4e3a\u4ec0\u4e48\u8bf4 Function Calling \u4e4b\u540e\u8bb0\u5fc6\u53d8\u590d\u6742\u4e86\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u56e0\u4e3a Function Calling \u5728\u4e00\u8f6e\u5bf9\u8bdd\u91cc\uff0c\u6d88\u606f\u7ed3\u6784\u4e0d\u518d\u662f\u7b80\u5355\u7684 user \u2192 assistant\u3002<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4e2d\u95f4\u591a\u4e86\u4e00\u5c42\u5de5\u5177\u8c03\u7528\u94fe\u3002<\/strong>&#8220;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u4ed6\u5728\u767d\u677f\u4e0a\u753b\u51fa\u5b8c\u6574\u7684\u4e00\u8f6e Function Calling \u6d88\u606f\u6d41\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);\">\u666e\u901a\u5bf9\u8bdd\uff08\u65e0\u5de5\u5177\uff09\uff1a\n  user \u2192 assistant(\u56de\u7b54)\n\nFunction Calling\uff08\u6709\u5de5\u5177\uff09\uff1a\n  user\n  \u2192 assistant(tool_calls: get_weather, args: {city:\"\u6210\u90fd\"})  \u2190 \u6a21\u578b\u51b3\u5b9a\u8c03\u5de5\u5177\n  \u2192 tool(tool_call_id: \"xxx\", name: \"get_weather\", content: \"\u591a\u4e91 16\u00b0C\")  \u2190 \u4f60\u7684\u4ee3\u7801\u6267\u884c\u7ed3\u679c\n  \u2192 assistant(\u56de\u7b54: \"\u6210\u90fd\u4eca\u5929\u591a\u4e91\uff0c16\u00b0C\uff0c\u5fae\u98ce\")  \u2190 \u6a21\u578b\u57fa\u4e8e\u7ed3\u679c\u751f\u6210\u56de\u7b54\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u4e00\u8f6e Function Calling \u53ef\u80fd\u4ea7\u751f <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">4 \u6761\u6d88\u606f<\/strong>\u2014\u2014\u6bd4\u4f60\u60f3\u8c61\u7684\u591a\u4e86\u4e24\u500d\u3002&#8221;<\/p>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u6d88\u606f<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">role<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u5185\u5bb9<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u8c01\u4ea7\u751f\u7684<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">1<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>user<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">&#8220;\u6210\u90fd\u5929\u6c14\uff1f&#8221;<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u7528\u6237\u8f93\u5165<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">2<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>assistant<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>tool_calls: get_weather(...)<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6a21\u578b\u8fd4\u56de\uff08content \u4e3a\u7a7a\uff09<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">3<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>tool<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>\"\u591a\u4e91 16\u00b0C\"<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u4f60\u7684\u4ee3\u7801\u6267\u884c\u7ed3\u679c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">4<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>assistant<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">&#8220;\u6210\u90fd\u591a\u4e91\u2026&#8221;<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6a21\u578b\u57fa\u4e8e\u7ed3\u679c\u751f\u6210<\/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;\">&#8220;\u4f60\u4ee5\u4e3a\u95ee\u4e00\u53e5\u8bdd\u5c31\u52a0\u4e24\u6761\u6d88\u606f\uff0c\u5b9e\u9645\u4e0a\u52a0\u4e86\u56db\u6761\u3002\u5982\u679c\u4f60\u7684\u8bb0\u5fc6\u5b9e\u73b0\u5f97\u4e0d\u597d\uff0c\u8fd9\u4e9b\u6d88\u606f\u7684\u987a\u5e8f\u548c\u914d\u5bf9\u5173\u7cfb\u5c31\u53ef\u80fd\u51fa\u95ee\u9898\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;\">\u534f\u8bae\u786c\u89c4\u5219\uff1aassistant(tool_calls) \u548c tool \u6d88\u606f\u5fc5\u987b\u6210\u5bf9<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u7684\u8868\u60c5\u4e25\u8083\u8d77\u6765\uff1a&#8221;\u5b98\u65b9\u7684 Function Calling \u534f\u8bae\u6709\u4e00\u6761<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u94c1\u5f8b<\/strong>\u2014\u2014&#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;\">assistant \u6d88\u606f\u91cc\u7684 tool_calls \u5fc5\u987b\u5728 messages \u5217\u8868\u4e2d\u7d27\u8ddf\u5bf9\u5e94\u7684 tool\uff08\u7ed3\u679c\uff09\u6d88\u606f\u3002<\/strong><br \/>\n\u4e0d\u80fd\u62c6\u6563\uff0c\u4e0d\u80fd\u6f0f\u6389\uff0c\u4e0d\u80fd\u4e71\u5e8f\u3002<\/p>\n<\/blockquote>\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-comment\" style=\"color: rgb(101, 123, 131);\"># \u2705 \u6b63\u786e\uff1aassistant(tool_calls) \u7d27\u63a5 tool \u7ed3\u679c<\/span>\n[\n  {<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>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6210\u90fd\u5929\u6c14\uff1f\"<\/span>},\n  {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"assistant\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool_calls\"<\/span>: [...]},  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># 1. \u8c03\u7528\u8bf7\u6c42<\/span>\n  {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool_call_id\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"xxx\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u591a\u4e91\"<\/span>},  <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># 2. \u5de5\u5177\u7ed3\u679c\uff08\u7d27\u63a5\uff09<\/span>\n]\n\n<span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u274c \u9519\u8bef\uff1aassistant \u548c tool \u4e4b\u95f4\u63d2\u4e86\u522b\u7684\u6d88\u606f<\/span>\n[\n  {<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>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u6210\u90fd\u5929\u6c14\uff1f\"<\/span>},\n  {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"assistant\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool_calls\"<\/span>: [...]},\n  {<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>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4e0a\u6d77\u5462\uff1f\"<\/span>},       <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u2190 \u7834\u574f\u4e86\u914d\u5bf9\uff01<\/span>\n  {<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool_call_id\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"xxx\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u591a\u4e91\"<\/span>},\n]\n<span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u2192 API \u62a5\u9519\uff1aAn assistant message with 'tool_calls'<\/span>\n<span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\">#       must be followed by tool messages<\/span>\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\u95ee\uff1a&#8221;\u5982\u679c\u7b2c\u4e8c\u8f6e\u7684 user \u6d88\u606f\u4e0d\u5c0f\u5fc3\u63d2\u5728 assistant(tool_calls) \u548c tool \u4e4b\u95f4\uff0c\u5c31\u70b8\u4e86\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5bf9\u3002API \u76f4\u63a5\u62a5\u9519\u2014\u2014\u534f\u8bae\u89c4\u5b9a <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;\">tool_calls<\/code> \u4e4b\u540e\u53ea\u80fd\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;\">tool<\/code> \u6d88\u606f\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u8bb0\u5fc6\u7ba1\u7406\u4e0d\u53ea\u662f\u7b80\u5355\u7684 append\u2014\u2014<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4f60\u5f97\u4fdd\u8bc1\u6d88\u606f\u987a\u5e8f\u5408\u6cd5\u3002<\/strong>&#8220;<\/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;\">\u5b9e\u73b0\u77ed\u671f\u8bb0\u5fc6\uff1aShortTermMemory \u7c7b<\/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;\u641e\u6e05\u4e86\u89c4\u5219\uff0c\u770b\u4ee3\u7801\u5b9e\u73b0\u3002\u6838\u5fc3\u5c31\u662f\u4e00\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;\">ShortTermMemory<\/code> \u7c7b\uff0c\u5e95\u5c42\u662f\u4e00\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;\">list[dict]<\/code>\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-meta\" style=\"color: rgb(211, 54, 130);\">@dataclass<\/span>\n<span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">class<\/span> <span class=\"hljs-title class_\" style=\"color: rgb(181, 137, 0);\">ShortTermMemory<\/span>:\n  max_messages: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">int<\/span> = <span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">40<\/span>      <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u6700\u591a\u4fdd\u7559\u591a\u5c11\u6761\u6d88\u606f<\/span>\n  _messages: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">list<\/span>[<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>] = field(default_factory=<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">list<\/span>)\n\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">add<\/span>(<span class=\"hljs-params\">self, message: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span><\/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);\">\"\"\"\u8ffd\u52a0\u4e00\u6761\u6d88\u606f\uff0c\u8d85\u8fc7\u4e0a\u9650\u65f6\u81ea\u52a8\u88c1\u526a\"\"\"<\/span>\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages.append(message)\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._trim()\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);\">to_api_format<\/span>(<span class=\"hljs-params\">self<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">list<\/span>[<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>]:\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"\"\u8fd4\u56de\u5b8c\u6574\u6d88\u606f\u5217\u8868\uff0c\u4f20\u7ed9 OpenAI API\"\"\"<\/span>\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">list<\/span>(<span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages)\n\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">clear_non_system<\/span>(<span class=\"hljs-params\">self<\/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);\">\"\"\"\u6e05\u7a7a\u9664 system \u5916\u7684\u6240\u6709\u6d88\u606f\"\"\"<\/span>\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages = [m <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> <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> m.get(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>) == <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"system\"<\/span>]\n<\/code><\/pre>\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\u65b9\u6cd5\uff1a&#8221;<\/p>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u65b9\u6cd5<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u4f5c\u7528<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u4ec0\u4e48\u65f6\u5019\u8c03<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>add()<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u8ffd\u52a0\u4e00\u6761\u6d88\u606f + \u81ea\u52a8\u88c1\u526a<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6bcf\u4ea7\u751f\u4e00\u6761\u65b0\u6d88\u606f\u90fd\u8c03<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>to_api_format()<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u8fd4\u56de\u5b8c\u6574\u6d88\u606f\u5217\u8868<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6bcf\u6b21\u8c03\u7528 API \u524d\u8c03<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>clear_non_system()<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6e05\u7a7a\u8bb0\u5fc6\uff08\u4fdd\u7559 system\uff09<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u7528\u6237\u8f93\u5165 <code>\/clear<\/code> \u65f6\u8c03<\/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;\">&#8220;\u8bb0\u5fc6\u7684\u6838\u5fc3\u5c31\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;\">_messages<\/code> \u8fd9\u4e2a\u5217\u8868\u3002\u6bcf\u6b21\u5bf9\u8bdd\u4ea7\u751f\u7684\u65b0\u6d88\u606f\u901a\u8fc7 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">add()<\/code> \u8ffd\u52a0\u8fdb\u53bb\uff0c\u8c03\u7528 API \u65f6\u901a\u8fc7 <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;\">to_api_format()<\/code> \u628a\u6574\u4e2a\u5217\u8868\u4f20\u8fc7\u53bb\u3002\u6a21\u578b\u56e0\u4e3a\u770b\u5230\u4e86\u5168\u90e8\u5386\u53f2\uff0c\u5c31\u80fd&#8217;\u8bb0\u4f4f&#8217;\u4e4b\u524d\u7684\u5bf9\u8bdd\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;\">\u88c1\u526a\u7b56\u7565\uff1a\u5220\u4e00\u6761\u5c31\u591f\uff1f\u4e0d\u591f<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u5c0f\u660e\u95ee\uff1a&#8221;<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;\">_trim()<\/code> \u662f\u505a\u4ec0\u4e48\u7684\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u6d88\u606f\u5217\u8868\u4e0d\u80fd\u65e0\u9650\u589e\u957f\u3002&#8221;\u8001\u5f20\u8bf4\uff0c&#8221;\u5047\u8bbe\u4f60\u8bbe\u7f6e\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;\">max_messages=40<\/code>\uff0c\u8d85\u8fc7 40 \u6761\u540e\uff0c<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;\">_trim()<\/code> \u81ea\u52a8\u5220\u9664\u6700\u65e7\u7684\u6d88\u606f\u3002\u4f46\u8fd9\u91cc\u6709\u4e2a\u5751\u2014\u2014<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4e0d\u80fd\u53ea\u5220\u4e00\u6761\u3002<\/strong>&#8220;<\/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);\">\u5047\u8bbe messages \u5217\u8868\u8d85\u5927\u4e86\uff0c\u6700\u524d\u9762\u662f\u8fd9\u51e0\u6761\uff1a\n\n[0] {\"role\":\"system\",\"content\":\"\u4f60\u662f\u667a\u80fd\u52a9\u624b\"}     \u2190 system\uff0c\u4e0d\u80fd\u5220\n[1] {\"role\":\"user\",\"content\":\"\u6210\u90fd\u5929\u6c14\uff1f\"}      \u2190 \u6700\u65e7\u7684\u975e system\n[2] {\"role\":\"assistant\",\"content\":None,\"tool_calls\":[...]}  \u2190 \u8981\u5220\n[3] {\"role\":\"tool\",\"tool_call_id\":\"xxx\",\"content\":\"\u591a\u4e91\"}  \u2190 \u4e5f\u8981\u5220\uff01\n[4] {\"role\":\"assistant\",\"content\":\"\u6210\u90fd\u591a\u4e91...\"}       \u2190 \u4e5f\u8981\u5220\uff01\u5220\u5b8c\u8fd9\u7ec4\n[5] {\"role\":\"user\",\"content\":\"\u4e0a\u6d77\u5462\uff1f\"}\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5982\u679c\u53ea\u5220 <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;\">[1]<\/code>\uff08user \u6d88\u606f\uff09\uff0c<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;\">[2]<\/code> \u7684 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">tool_calls<\/code> \u5b64\u96f6\u96f6\u7559\u5728\u524d\u9762\uff0c<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;\">[3]<\/code> \u7684 tool \u7ed3\u679c\u5c31\u6ca1\u6709\u524d\u7f6e\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">tool_calls<\/code> \u4e86\u2014\u2014\u534f\u8bae\u76f4\u63a5\u62a5\u9519\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u6b63\u786e\u7684\u88c1\u526a\u7b56\u7565<\/strong>\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);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">_trim<\/span>(<span class=\"hljs-params\">self<\/span>) -&gt; <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">while<\/span> <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.message_count() &gt; <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.max_messages:\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># 1. \u627e\u5230\u6700\u65e7\u7684\u975e system \u6d88\u606f<\/span>\n    idx = <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">next<\/span>(\n      (i <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">for<\/span> i, m <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">enumerate<\/span>(<span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages)\n       <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> m.get(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>) != <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"system\"<\/span>),\n      <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>,\n    )\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> idx <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">is<\/span> <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n      <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">break<\/span>\n\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># 2. \u5220\u9664\u5b83<\/span>\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages.pop(idx)\n\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># 3. \u5220\u9664\u4e4b\u540e\uff0c\u628a\u7d27\u8ddf\u5728\u540e\u9762\u7684 tool \u6d88\u606f\u4e00\u5e76\u5220\u6389<\/span>\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\">#   \uff08\u907f\u514d\u7559\u4e0b\"\u5b64\u513f\"tool \u6d88\u606f\uff09<\/span>\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">while<\/span> idx &lt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">len<\/span>(<span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages) <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">and<\/span> \\\n        <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages[idx].get(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>) == <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool\"<\/span>:\n      <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages.pop(idx)\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u9010\u884c\u89e3\u91ca\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;\">\u8df3\u8fc7 system<\/strong> \u2014 system \u6d88\u606f\u662f Agent \u7684\u89d2\u8272\u8bbe\u5b9a\uff0c\u4e0d\u80fd\u5220<\/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;\">\u627e\u6700\u65e7\u7684\u975e system<\/strong> \u2014 \u4ece\u5217\u8868\u5934\u90e8\u5f00\u59cb\uff0c\u627e\u5230\u7b2c\u4e00\u6761\u975e system \u7684\u6d88\u606f<\/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;\">\u5f39\u51fa\u5b83<\/strong> \u2014 \u5220\u6389\u8fd9\u6761\u6d88\u606f<\/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;\">\u541e\u6389\u7d27\u8ddf\u7684 tool \u6d88\u606f<\/strong> \u2014 \u5982\u679c\u88ab\u5220\u7684\u6d88\u606f\u540e\u9762\u7d27\u8ddf\u7740 <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;\">role=tool<\/code>\uff0c\u4e00\u5e76\u5220\u9664<\/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;\">&#8220;\u8fd9\u4e2a\u7b56\u7565\u53eb&#8217;<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5220\u5f53\u524d + \u5411\u540e\u541e tool \u7ec4<\/strong>&#8216;\u3002\u6838\u5fc3\u76ee\u7684\u53ea\u6709\u4e00\u4e2a\u2014\u2014<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4fdd\u8bc1\u4e0d\u4f1a\u7559\u4e0b orphan tool \u6d88\u606f\u7834\u574f\u534f\u8bae\u3002<\/strong>&#8220;<\/p>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u88c1\u526a\u65b9\u5f0f<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u7ed3\u679c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u53ea\u5220\u6700\u65e7\u4e00\u6761<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u53ef\u80fd\u7559\u5b64\u513f tool \u2192 API \u62a5\u9519<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u5220\u5f53\u524d + \u541e\u540e\u9762 tool<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u59cb\u7ec8\u4fdd\u6301\u534f\u8bae\u5408\u6cd5\u6027 \u2705<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5b8c\u6574\u7684\u4e00\u6761\u5bf9\u8bdd\u6d41<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u628a Agent \u7684\u4e00\u8f6e\u5bf9\u8bdd\u5b8c\u6574\u5c55\u5f00\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);\">class<\/span> <span class=\"hljs-title class_\" style=\"color: rgb(181, 137, 0);\">Agent<\/span>:\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">def<\/span> <span class=\"hljs-title function_\" style=\"color: rgb(38, 139, 210);\">__init__<\/span>(<span class=\"hljs-params\">self<\/span>):\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.memory = ShortTermMemory(max_messages=<span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">40<\/span>)\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.memory.add_system(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u4f60\u662f\u4e00\u4e2a\u667a\u80fd\u52a9\u624b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177...\"<\/span>)\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.tools = get_tools_schema()\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);\">chat<\/span>(<span class=\"hljs-params\">self, user_input: <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span><\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">str<\/span>:\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u7b2c 0 \u6b65\uff1a\u7528\u6237\u8f93\u5165\u5199\u5165\u8bb0\u5fc6<\/span>\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.memory.add({<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>: user_input})\n\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u7b2c 1 \u6b65\uff1a\u7b2c\u4e00\u8f6e API \u8c03\u7528\uff08\u5e26 tools\uff0c\u8ba9\u6a21\u578b\u51b3\u5b9a\u8981\u4e0d\u8981\u8c03\u5de5\u5177\uff09<\/span>\n    message = chat(<span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.memory.to_api_format(), tools=<span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.tools)\n\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u5982\u679c\u6a21\u578b\u4e0d\u9700\u8981\u5de5\u5177\uff0c\u6d88\u606f\u94fe\u5230\u6b64\u7ed3\u675f<\/span>\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">not<\/span> message.tool_calls:\n      <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.memory.add({<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"assistant\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: message.content})\n      <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> message.content\n\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u7b2c 2 \u6b65\uff1a\u628a\u6a21\u578b\u7684 tool_calls \u8bf7\u6c42\u5199\u5165\u8bb0\u5fc6<\/span>\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.memory.add(assistant_to_dict(message))\n\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u7b2c 3 \u6b65\uff1a\u6267\u884c\u5de5\u5177\uff0c\u6bcf\u6761\u7ed3\u679c\u5199\u5165\u8bb0\u5fc6<\/span>\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">for<\/span> tool_call <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> message.tool_calls:\n      result = execute_tool(tool_call.function.name,\n                  tool_call.function.arguments)\n      <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.memory.add({\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool\"<\/span>,\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool_call_id\"<\/span>: tool_call.<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">id<\/span>,\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: result,\n      })\n\n    <span class=\"hljs-comment\" style=\"color: rgb(101, 123, 131);\"># \u7b2c 4 \u6b65\uff1a\u7b2c\u4e8c\u8f6e API \u8c03\u7528\uff08\u4e0d\u5e26 tools\uff09<\/span>\n    final = chat(<span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.memory.to_api_format(), tools=<span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>)\n    <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>.memory.add({<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"assistant\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: final.content})\n    <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> final.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;\u6ce8\u610f<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u6bcf\u6b21\u5bf9\u8bdd\u56de\u5408\u90fd\u8c03 <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;\">self.memory.add()<\/code><\/strong>\uff0c\u628a\u65b0\u6d88\u606f\u8ffd\u52a0\u8fdb\u53bb\u3002\u5173\u952e\u64cd\u4f5c\u90fd\u662f\u5bf9 <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;\">self.memory<\/code> \u7684 <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u8bfb<\/strong>\uff08<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;\">to_api_format()<\/code>\uff09\u548c <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u5199<\/strong>\uff08<code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">add()<\/code>\uff09\u2014\u2014Agent \u672c\u8eab\u4e0d\u518d\u76f4\u63a5\u64cd\u4f5c <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">messages<\/code> \u5217\u8868\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\u5bf9\u7167\u7740\u65f6\u5e8f\u56fe\u770b\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);\">\u7b2c1\u8f6e\u5bf9\u8bdd\uff1a\"\u6211\u53eb\u5c0f\u660e\"\n  memory.add(user: \"\u6211\u53eb\u5c0f\u660e\")\n  API \u8c03\u7528 \u2192 \u6a21\u578b\u76f4\u63a5\u56de\u7b54\uff08\u4e0d\u9700\u8981\u5de5\u5177\uff09\n  memory.add(assistant: \"\u4f60\u597d\u5c0f\u660e\")\n\n  memory \u72b6\u6001\uff1a[system, user(\"\u6211\u53eb\u5c0f\u660e\"), assistant(\"\u4f60\u597d\u5c0f\u660e\")]\n\n\u7b2c2\u8f6e\u5bf9\u8bdd\uff1a\"\u6210\u90fd\u5929\u6c14\uff1f\"\n  memory.add(user: \"\u6210\u90fd\u5929\u6c14\uff1f\")\n  API \u8c03\u7528 \u2192 \u6a21\u578b\u51b3\u5b9a\u8c03 get_weather(\"\u6210\u90fd\")\n  memory.add(assistant with tool_calls)\n  \u6267\u884c get_weather(\"\u6210\u90fd\") \u2192 \"\u591a\u4e91 16\u00b0C\"\n  memory.add(tool: \"\u591a\u4e91 16\u00b0C\")\n  API \u8c03\u7528 \u2192 \u6a21\u578b\u57fa\u4e8e\u7ed3\u679c\u56de\u7b54\n  memory.add(assistant: \"\u6210\u90fd\u591a\u4e91 16\u00b0C\")\n\n  memory \u72b6\u6001\uff1a[system,\n          user(\"\u6211\u53eb\u5c0f\u660e\"), assistant(\"\u4f60\u597d\u5c0f\u660e\"),\n          user(\"\u6210\u90fd\u5929\u6c14\uff1f\"), assistant(tool_calls),\n          tool(\"\u591a\u4e91\"), assistant(\"\u6210\u90fd\u591a\u4e91\")]\n\n\u7b2c3\u8f6e\u5bf9\u8bdd\uff1a\"\u6211\u521a\u624d\u8bf4\u6211\u53eb\u4ec0\u4e48\u540d\u5b57\"\n  memory.add(user: \"\u6211\u521a\u624d\u8bf4\u6211\u53eb\u4ec0\u4e48\u540d\u5b57\")\n  API \u8c03\u7528 \u2192 \u6a21\u578b\u770b\u5230\u5b8c\u6574\u5386\u53f2\uff0c\u56de\u7b54\"\u5c0f\u660e\"\n  memory.add(assistant: \"\u4f60\u521a\u624d\u8bf4\u4f60\u53eb\u5c0f\u660e\")\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u7b2c\u4e09\u8f6e\u8c03\u7528\u65f6\uff0c\u6a21\u578b\u770b\u5230\u6574\u4e2a message \u5217\u8868\u91cc\u6709&#8217;\u6211\u53eb\u5c0f\u660e&#8217;\u548c&#8217;\u4f60\u597d\u5c0f\u660e&#8217;\uff0c\u6240\u4ee5\u77e5\u9053\u7528\u6237\u53eb\u5c0f\u660e\u3002\u8bb0\u5fc6\u5c31\u662f\u9760\u8fd9\u4e2a\u5217\u8868\u2014\u2014<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4e0d\u662f\u6a21\u578b\u8bb0\u4f4f\u4e86\uff0c\u662f\u4f60\u4f20\u8fc7\u53bb\u7684\u5386\u53f2\u8ba9\u5b83\u770b\u5230\u4e86\u3002<\/strong>&#8220;<\/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;\">\/clear\uff1a\u53ef\u63a7\u7684\u9057\u5fd8<\/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;\u8bb0\u5fc6\u9664\u4e86\u4f1a&#8217;\u8bb0&#8217;\uff0c\u8fd8\u8981\u4f1a&#8217;\u5fd8&#8217;\u3002Agent \u9700\u8981\u63d0\u4f9b <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u91cd\u7f6e\u8bb0\u5fc6<\/strong> \u7684\u529f\u80fd\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u4e3a\u4ec0\u4e48\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u6bd4\u5982\u7528\u6237\u60f3\u5f00\u59cb\u4e00\u6bb5\u5168\u65b0\u7684\u5bf9\u8bdd\uff0c\u4e0d\u60f3\u88ab\u4e4b\u524d\u7684\u8bdd\u9898\u5e72\u6270\u3002\u518d\u6bd4\u5982\u6d4b\u8bd5\u7684\u65f6\u5019\uff0c\u4f60\u60f3\u9a8c\u8bc1\u65b0\u529f\u80fd\u800c\u4e0d\u53d7\u65e7\u5bf9\u8bdd\u5f71\u54cd\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5b9e\u73b0\u5f88\u7b80\u5355\u2014\u2014\u4fdd\u7559 system \u6d88\u606f\uff0c\u6e05\u7a7a\u5176\u4f59\uff1a&#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);\">clear_non_system<\/span>(<span class=\"hljs-params\">self<\/span>) -&gt; <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n  <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages = [m <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> <span class=\"hljs-variable language_\" style=\"color: rgb(220, 50, 47);\">self<\/span>._messages\n            <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> m.get(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>) == <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"system\"<\/span>]\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5728 CLI \u91cc\u7ed1\u4e00\u4e2a\u547d\u4ee4\uff1a&#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);\">if<\/span> user_input.lower() == <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\/clear\"<\/span>:\n  agent.clear()\n  <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">print<\/span>(<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\u8bb0\u5fc6\u5df2\u6e05\u9664\uff0c\u5f00\u59cb\u65b0\u5bf9\u8bdd\u3002\"<\/span>)\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">continue<\/span>\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u6e05\u7a7a\u524d\uff1a&#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\" 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);\">[system, user(\"\u6211\u53eb\u5c0f\u660e\"), assistant(\"\u4f60\u597d\u5c0f\u660e\"),\n user(\"\u6210\u90fd\u5929\u6c14\uff1f\"), assistant(tool_calls), tool(\"\u591a\u4e91\"), assistant(\"\u591a\u4e9116\u00b0C\")]\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u6e05\u7a7a\u540e\uff1a&#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\" 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);\">[system]\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u76f8\u5f53\u4e8e Agent \u91cd\u542f\u2014\u2014\u53ea\u8bb0\u5f97\u81ea\u5df1\u7684\u89d2\u8272\u8bbe\u5b9a\uff0c\u5bf9\u8bdd\u5386\u53f2\u5168\u5fd8\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\u8bd5\u4e86\u4e00\u4e0b\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);\">\u4f60\uff1a\u6211\u53eb\u5c0f\u660e\nAgent\uff1a\u4f60\u597d\u5c0f\u660e\uff01\n\uff08\u5f53\u524d\u8bb0\u5fc6\uff1a2 \u6761\u6d88\u606f\uff09\n\n\/clear\n\u8bb0\u5fc6\u5df2\u6e05\u9664\uff0c\u5f00\u59cb\u65b0\u5bf9\u8bdd\u3002\n\n\u4f60\uff1a\u6211\u521a\u624d\u8bf4\u6211\u53eb\u4ec0\u4e48\u540d\u5b57\uff1f\nAgent\uff1a\u4f60\u6ca1\u6709\u544a\u8bc9\u6211\u4f60\u7684\u540d\u5b57\u3002\n<\/code><\/pre>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">assistant_to_dict\uff1a\u628a SDK \u5bf9\u8c61\u8f6c\u6210\u53ef\u5b58\u50a8\u7684 dict<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u6307\u7740\u4e00\u5904\u7ec6\u8282\u8bf4\uff1a&#8221;<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;\">assistant_to_dict()<\/code> \u8fd9\u4e2a\u51fd\u6570\u503c\u5f97\u5355\u72ec\u8bb2\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u4e3a\u4ec0\u4e48\uff1f\u76f4\u63a5\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;\">message.to_dict()<\/code> \u4e0d\u884c\u5417\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;OpenAI SDK \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; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">message<\/code> \u5bf9\u8c61\u53ef\u4ee5\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;\">.to_dict()<\/code>\uff0c\u4f46\u4e0d\u540c\u5382\u5546\u7684\u8fd4\u56de\u683c\u5f0f\u6709\u5dee\u5f02\u3002\u800c\u4e14 <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> \u53ef\u80fd\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;\">None<\/code>\uff08\u5f53\u6d88\u606f\u662f tool_calls \u65f6\uff09\u3002\u4e3a\u4e86\u517c\u5bb9\u66f4\u591a\u5382\u5546\uff0c\u6211\u4eec\u624b\u5199\u8f6c\u6362\uff1a&#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);\">assistant_to_dict<\/span>(<span class=\"hljs-params\">message<\/span>) -&gt; <span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">dict<\/span>:\n  item = {\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"role\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"assistant\"<\/span>,\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"content\"<\/span>: message.content <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> message.content <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">is<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">not<\/span> <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">else<\/span> <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"\"<\/span>,\n  }\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> message.tool_calls:\n    item[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool_calls\"<\/span>] = [\n      {\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"id\"<\/span>: tc.<span class=\"hljs-built_in\" style=\"color: rgb(42, 161, 152);\">id<\/span>,\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"type\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"function\"<\/span>,\n        <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"function\"<\/span>: {\n          <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"name\"<\/span>: tc.function.name,\n          <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"arguments\"<\/span>: tc.function.arguments,\n        },\n      }\n      <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">for<\/span> tc <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">in<\/span> message.tool_calls\n    ]\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> item\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\u8981\u70b9\uff1a&#8221;<\/p>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u8981\u70b9<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>content<\/code> \u7528\u7a7a\u5b57\u7b26\u4e32\u515c\u5e95<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u907f\u514d <code>None<\/code> \u88ab\u4e0b\u6e38\u4ee3\u7801\u5f53\u4f5c <code>\"None\"<\/code> \u5b57\u7b26\u4e32<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>tool_calls<\/code> \u7ed3\u6784\u6241\u5e73\u5f88\u660e\u786e<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u4e0d\u7528 SDK \u7684\u5d4c\u5957\u5bf9\u8c61\uff0c\u7528\u7eaf dict\u2014\u2014\u5b58\u8d77\u6765\u65b9\u4fbf\uff0c\u4f20\u56de API \u4e5f\u517c\u5bb9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">LLM \u5c01\u88c5\uff1a\u7b2c\u4e8c\u8f6e\u4f20 tools=None<\/span><\/h2>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u53c8\u6307\u7740 <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;\">llm.py<\/code> \u8bf4\uff1a&#8221;\u8fd8\u6709\u4e00\u4e2a\u5bb9\u6613\u88ab\u5ffd\u7565\u7684\u53c2\u6570\u2014\u2014<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u7b2c\u4e8c\u8f6e API \u8c03\u7528\u65f6 <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;\">tools<\/code> \u5fc5\u987b\u4f20 <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<\/strong>&#8220;<\/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);\">chat<\/span>(<span class=\"hljs-params\">messages, tools=<span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>, tool_choice=<span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span><\/span>):\n  kwargs = {\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"model\"<\/span>: MODEL,\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"messages\"<\/span>: messages,\n    <span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"temperature\"<\/span>: <span class=\"hljs-number\" style=\"color: rgb(203, 75, 22);\">0<\/span>,\n  }\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> tools <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">is<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">not<\/span> <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n    kwargs[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tools\"<\/span>] = tools\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">if<\/span> tool_choice <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">is<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">not<\/span> <span class=\"hljs-literal\" style=\"color: rgb(203, 75, 22);\">None<\/span>:\n    kwargs[<span class=\"hljs-string\" style=\"color: rgb(133, 153, 0);\">\"tool_choice\"<\/span>] = tool_choice\n  <span class=\"hljs-keyword\" style=\"color: rgb(108, 113, 196);\">return<\/span> client.chat.completions.create(**kwargs)\n<\/code><\/pre>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u7b2c\u4e00\u8f6e\u8c03\u7528\u65f6 <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;\">tools=self.tools<\/code>\uff0c\u6a21\u578b\u53ef\u4ee5\u51b3\u5b9a\u8c03\u4e0d\u8c03\u5de5\u5177\u3002\u7b2c\u4e8c\u8f6e\u8c03\u7528\u65f6 <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;\">tools=None<\/code>\u2014\u2014<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u544a\u8bc9\u6a21\u578b&#8217;\u5de5\u5177\u7ed3\u679c\u5df2\u7ecf\u7ed9\u4f60\u4e86\uff0c\u4e0d\u8bb8\u518d\u8c03\u5de5\u5177\uff0c\u76f4\u63a5\u751f\u6210\u56de\u7b54&#8217;\u3002<\/strong>&#8220;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5982\u679c\u7b2c\u4e8c\u8f6e\u8fd8\u4f20 tools\uff0c\u6a21\u578b\u53ef\u80fd\u89c9\u5f97&#8217;\u8fd9\u4e2a\u5de5\u5177\u7ed3\u679c\u4e0d\u591f\uff0c\u6211\u518d\u8c03\u4e00\u4e2a&#8217;\u2014\u2014\u9677\u5165\u65e0\u9650\u5faa\u73af\u3002Day4 \u7684\u89c4\u5b9a\u662f<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u6bcf\u8f6e\u7528\u6237\u8f93\u5165\u6700\u591a\u4e00\u6b21\u5de5\u5177\u56de\u5408<\/strong>\uff0c\u6240\u4ee5\u7b2c\u4e8c\u8f6e\u5fc5\u987b\u7981\u6b62\u5de5\u5177\u8c03\u7528\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;\">\u4e0d\u540c\u5c42\u7684\u8bb0\u5fc6<\/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;\u4eca\u5929\u8bb2\u7684\u662f<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u77ed\u671f\u8bb0\u5fc6<\/strong>\u2014\u2014\u5b58\u5728 Agent \u8fdb\u7a0b\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">list<\/code> \u91cc\uff0c\u8fdb\u7a0b\u91cd\u542f\u5c31\u6ca1\u4e86\u3002\u8fd9\u662f\u6700\u57fa\u672c\u7684\u8bb0\u5fc6\u5c42\u3002\u4f46\u5b8c\u6574\u7684 Agent \u8bb0\u5fc6\u4f53\u7cfb\u6709\u4e09\u5c42\uff1a&#8221;<\/p>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u8bb0\u5fc6\u5c42<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u5b58\u50a8\u4f4d\u7f6e<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u751f\u547d\u5468\u671f<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u793a\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u77ed\u671f\u8bb0\u5fc6<\/strong><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u8fdb\u7a0b\u5185\u5b58\uff08<code>list[dict]<\/code>\uff09<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u4f1a\u8bdd\u671f\u95f4<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u5bf9\u8bdd\u5386\u53f2\u3001\u5de5\u5177\u8c03\u7528\u94fe<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u4e2d\u671f\u8bb0\u5fc6<\/strong><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6587\u4ef6\/\u6570\u636e\u5e93<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u8de8\u4f1a\u8bdd<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u7528\u6237\u504f\u597d\u3001\u9879\u76ee\u4e0a\u4e0b\u6587<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">\u957f\u671f\u8bb0\u5fc6<\/strong><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u5411\u91cf\u6570\u636e\u5e93 + RAG<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6c38\u4e45<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u77e5\u8bc6\u5e93\u3001\u6587\u6863\u3001\u7ecf\u9a8c<\/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;\">&#8220;\u4eca\u5929\u4f60\u5b66\u7684\u662f\u7b2c\u4e00\u5c42\u3002\u8fd9\u662f\u57fa\u7840\u2014\u2014\u6d88\u606f\u94fe\u8bb0\u4e0d\u4f4f\uff0c\u540e\u9762\u4e24\u5c42\u65e0\u4ece\u8c08\u8d77\u3002\u4f46\u53ea\u8981\u6d88\u606f\u94fe\u673a\u5236\u641e\u6e05\u695a\u4e86\uff0c\u540e\u9762\u7684\u8bb0\u5fc6\u5c42\u90fd\u662f\u5728\u5b83\u7684\u57fa\u7840\u4e0a\u6269\u5c55\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;\">\u8fd9\u7bc7\u6587\u7ae0\u7684\u6838\u5fc3<\/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\u7b14\u8bb0\u6574\u7406\u6210\u4e86\u4e00\u5f20\u901f\u67e5\u8868\uff1a<\/p>\n<table style=\"display: inline-block !important; width: auto; max-width: 100%; overflow: auto; border-spacing: 0px; border-collapse: collapse; margin: 1rem 0px;\">\n<thead style=\"background: rgb(255, 249, 235); color: rgb(51, 51, 51); text-align: left;\">\n<tr>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u6982\u5ff5<\/th>\n<th align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200);\">\u4e00\u53e5\u8bdd<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">LLM \u65e0\u72b6\u6001<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6a21\u578b\u4e0d\u5b58\u50a8\u5bf9\u8bdd\uff0c\u9760\u4f60\u7684 <code>messages<\/code> \u5217\u8868\u6bcf\u6b21\u91cd\u65b0\u4f20<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u6d88\u606f\u5217\u8868 = \u77ed\u671f\u8bb0\u5fc6<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>ShortTermMemory<\/code> \u672c\u8d28\u662f <code>list[dict]<\/code>\uff0c<code>add()<\/code> \u5199\u3001<code>to_api_format()<\/code> \u8bfb<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">tool_calls \u548c tool \u914d\u5bf9<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u534f\u8bae\u94c1\u5f8b\uff1a\u4e0d\u80fd\u62c6\u6563\u3001\u4e0d\u80fd\u6f0f\u6389\u3001\u4e0d\u80fd\u4e71\u5e8f<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u88c1\u526a\u7b56\u7565<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u5220\u6700\u65e7 + \u541e\u7d27\u8ddf\u7684 tool \u6d88\u606f\uff0c\u4e0d\u7559\u5b64\u513f<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u7b2c\u4e8c\u8f6e tools=None<\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u4e0d\u8ba9\u6a21\u578b\u7ee7\u7eed\u8c03\u5de5\u5177\uff0c\u5f3a\u5236\u751f\u6210\u6700\u7ec8\u56de\u7b54<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>\/clear<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">\u4fdd\u7559 system\uff0c\u6e05\u7a7a\u5176\u4f59\uff0c\u76f8\u5f53\u4e8e\u91cd\u7f6e\u4f1a\u8bdd<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\"><code>assistant_to_dict()<\/code><\/td>\n<td align=\"left\" style=\"font-size: 0.75em; padding: 10px 12px; line-height: 1.6; border: 1px solid rgb(245, 230, 200); min-width: 100px;\">SDK \u5bf9\u8c61\u8f6c\u7eaf dict\uff0c\u517c\u5bb9\u591a\u5382\u5546<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr style=\"border-width: 1px medium medium; border-style: solid none none; border-color: rgb(240, 230, 208) currentcolor currentcolor; border-image: none; margin: 24px 0px;\">\n<h2 style=\"display: inline-block; position: relative; font-weight: bold; color: rgb(51, 51, 51); line-height: 1.5; margin-top: 32px; margin-bottom: 16px; padding: 0px 6px 2px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; text-align: left; background: linear-gradient(to top, rgb(248, 180, 63) 42%, transparent 42%); box-decoration-break: clone; -webkit-box-decoration-break: clone; font-size: 17px;\"><span style=\"color: rgb(51, 51, 51); font-weight: bold;\">\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\u6700\u540e\u5728\u767d\u677f\u4e0a\u5199\u4e86\u4e00\u53e5\u8bdd\uff1a<\/p>\n<blockquote style=\"color: rgb(85, 85, 85); background-color: rgb(255, 249, 235); background-image: none; padding: 16px 20px; margin: 20px 0px; border-width: 0px 0px 0px 4px; border-style: none none none solid; border-color: currentcolor currentcolor currentcolor rgb(248, 180, 63); border-radius: 6px; font-style: normal; quotes: none;\">\n<p style=\"margin: 0.55em 0px; color: rgb(85, 85, 85); text-indent: 0px; padding: 0px; line-height: 1.75; font-style: normal; background: transparent;\"><strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">Agent \u7684\u8bb0\u5fc6\u4e0d\u662f\u6a21\u578b\u7684\u529f\u80fd\uff0c\u662f\u4f60\u7684\u7a0b\u5e8f\u5199\u51fa\u6765\u7684\u3002\u6d88\u606f\u5217\u8868\u600e\u4e48\u7ba1\u7406\uff0c\u8bb0\u5fc6\u5c31\u591a\u597d\u3002<\/strong><\/p>\n<\/blockquote>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u4e0a\u4e24\u7bc7\u4f60\u5b66\u4f1a\u4e86\u5de5\u7a0b\u5316\u7ba1\u7406\u591a\u4e2a\u5de5\u5177\u3001\u7528 MCP \u63a5\u5165\u5916\u90e8\u670d\u52a1\u3002\u8fd9\u7bc7\u4f60\u5b66\u4f1a\u4e86\u7ed9 Agent \u52a0\u8bb0\u5fc6\u2014\u2014\u8ba9\u5b83\u8bb0\u4f4f\u6574\u4e2a\u4f1a\u8bdd\u7684\u5386\u53f2\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u6838\u5fc3\u4e09\u4ef6\u4e8b\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;\">\u6d88\u606f\u5217\u8868\u5c31\u662f\u8bb0\u5fc6<\/strong> \u2014 \u6bcf\u6b21 API \u8c03\u7528\u628a\u5b8c\u6574\u5386\u53f2\u4f20\u8fc7\u53bb<\/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;\">Function Calling \u8ba9\u8bb0\u5fc6\u53d8\u590d\u6742<\/strong> \u2014 assistant(tool_calls) \u548c tool \u5fc5\u987b\u914d\u5bf9\uff0c\u88c1\u526a\u65f6\u4e0d\u80fd\u7559\u5b64\u513f<\/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;\">\u7528 ShortTermMemory \u5c01\u88c5<\/strong> \u2014 \u7edf\u4e00\u7ba1\u7406\u6d88\u606f\u7684\u8bfb\u3001\u5199\u3001\u88c1\u526a\u3001\u6e05\u7a7a\uff0cAgent \u4ee3\u7801\u4e0d\u76f4\u63a5\u78b0 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">messages<\/code> \u5217\u8868&#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;\">\u5c0f\u660e\u8bf4\uff1a&#8221;\u6240\u4ee5\u4e4b\u524d\u6211\u4eec\u5199\u7684 Function Calling \u4ee3\u7801\uff0c\u672c\u8d28\u4e0a\u5c31\u662f\u5728\u64cd\u4f5c Agent \u7684\u8bb0\u5fc6\uff1f&#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;\">messages.append()<\/code> \u6bcf\u6b21\u90fd\u662f\u5728\u5f80\u8bb0\u5fc6\u91cc\u5199\u4e1c\u897f\u3002\u53ea\u4e0d\u8fc7\u6211\u4eec\u4e4b\u524d\u6ca1\u6709\u628a\u8fd9\u90e8\u5206\u903b\u8f91\u5c01\u88c5\u51fa\u6765\u2014\u2014\u8bb0\u5fc6\u903b\u8f91\u548c\u5bf9\u8bdd\u903b\u8f91\u6df7\u5728\u4e00\u8d77\u3002\u73b0\u5728\u628a\u8bb0\u5fc6\u62bd\u6210\u72ec\u7acb\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">ShortTermMemory<\/code> \u7c7b\uff0c\u804c\u8d23\u6e05\u6670\u4e86\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u4e0b\u4e00\u6b65\u5462\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">\u8001\u5f20\u8bf4\uff1a&#8221;\u4e0b\u4e00\u6b65\u662f <strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">Agent \u5faa\u73af<\/strong>\u3002\u4f60\u6ce8\u610f\u5230\u4e86\uff0c\u4eca\u5929\u7684\u4e00\u8f6e\u5bf9\u8bdd\u6700\u591a\u8c03\u4e00\u6b21\u5de5\u5177\u2014\u2014\u6a21\u578b\u8bf4&#8217;\u9700\u8981\u5929\u6c14&#8217;\uff0c\u4f60\u8c03\u4e86\uff0c\u5582\u7ed3\u679c\uff0c\u6a21\u578b\u5c31\u56de\u7b54\u4e86\u3002\u4f46\u6709\u65f6\u5019\uff0c\u6a21\u578b\u7684\u7b2c\u4e00\u6b21\u5de5\u5177\u7ed3\u679c\u4e0d\u591f\uff0c\u5b83\u9700\u8981\u518d\u8c03\u4e00\u4e2a\u5de5\u5177\u624d\u80fd\u56de\u7b54\u2014\u2014\u8fd9\u5c31\u9700\u8981 &#8216;\u591a\u6b65\u5de5\u5177\u94fe&#8217;\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u600e\u4e48\u5b9e\u73b0\uff1f&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u5f88\u7b80\u5355\u2014\u2014\u628a\u4eca\u5929\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">if tool_calls \u2192 \u6267\u884c \u2192 \u56de\u7b54<\/code> \u6362\u6210 <code style=\"font-family: Menlo, Monaco, Consolas, &quot;Liberation Mono&quot;, &quot;Roboto Mono&quot;, &quot;Courier New&quot;, &quot;Microsoft YaHei&quot;, monospace; background-color: rgb(255, 244, 230); color: rgb(217, 72, 15); border-radius: 2px; font-size: 14px; padding: 2px 5px; word-break: break-word;\">while tool_calls \u2192 \u6267\u884c \u2192 \u518d\u95ee\u6a21\u578b<\/code>\u3002\u8ba9\u6a21\u578b\u5728\u5224\u65ad&#8217;\u6211\u8fd8\u9700\u8981\u66f4\u591a\u4fe1\u606f&#8217;\u65f6\u7ee7\u7eed\u8c03\u5de5\u5177\uff0c\u76f4\u5230\u5b83\u89c9\u5f97\u591f\u4e86\u3001\u7ed9\u51fa\u6700\u7ec8\u56de\u7b54\u3002&#8221;<\/p>\n<p style=\"margin-top: 12px; margin-bottom: 12px; color: rgb(51, 51, 51); text-indent: 0px; padding-left: 0px;\">&#8220;\u8fd9\u5c31\u662f\u4e0b\u4e00\u7bc7\u6587\u7ae0\u7684\u5185\u5bb9\u2014\u2014<strong style=\"color: rgb(51, 51, 51); font-weight: bold;\">Agent Loop \u591a\u6b65\u5de5\u5177\u8c03\u7528<\/strong>\u3002&#8221;<\/p>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u7bc7\u4f60\u5b66\u4f1a\u4e86 MCP\u2014\u2014\u7528\u6807\u51c6\u534f\u8bae\u63a5\u5165\u5168\u4e16\u754c\u7684\u5de5\u5177\u3002\u4f46\u5de5\u5177\u591a\u4e86\u3001\u5bf9\u8bdd\u957f\u4e86\uff0c\u4e00\u4e2a\u65b0\u95ee\u9898\u5192\u51fa\u6765\uff1aAgent \u8bb0\u4e0d\u4f4f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3770,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[163,164],"tags":[167,168],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3769"}],"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=3769"}],"version-history":[{"count":1,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3769\/revisions"}],"predecessor-version":[{"id":3771,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3769\/revisions\/3771"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/media\/3770"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}