{"id":110097,"date":"2026-09-25T22:41:05","date_gmt":"2026-09-25T14:41:05","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/110097.html"},"modified":"2026-09-25T22:41:05","modified_gmt":"2026-09-25T14:41:05","slug":"agent%e5%b7%a5%e5%85%b7%e8%b0%83%e7%94%a8%e5%ae%9e%e6%88%98%ef%bc%9a%e7%bb%99%e5%a4%a7%e6%a8%a1%e5%9e%8b%e8%a3%85%e4%b8%8a%e8%83%bd%e8%af%bb%e5%86%99%e6%96%87%e4%bb%b6%e7%9a%84%e6%89%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/110097.html","title":{"rendered":"Agent\u5de5\u5177\u8c03\u7528\u5b9e\u6218\uff1a\u7ed9\u5927\u6a21\u578b\u88c5\u4e0a\u80fd\u8bfb\u5199\u6587\u4ef6\u7684\u624b"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\n<ul>\n<li>1. \u5148\u5206\u6e05\u56db\u4e2a\u89d2\u8272&#xff0c;\u522b\u628a&#034;\u70b9\u83dc&#034;\u5f53\u6210&#034;\u4e0a\u83dc&#034;<\/li>\n<li>\n<ul>\n<li>1.1 \u5de5\u5177\u5b9a\u4e49 AgentTool&#xff1a;\u8d34\u5728\u95e8\u53e3\u7684\u83dc\u5355<\/li>\n<li>1.2 \u8c03\u7528\u8bf7\u6c42 ToolCall&#xff1a;\u6a21\u578b\u7684&#034;\u53e3\u5934\u627f\u8bfa&#034;<\/li>\n<li>1.3 \u8fd4\u56de\u503c AgentToolResult&#xff1a;\u4ea4\u4e0a\u6765\u7684\u4f5c\u4e1a<\/li>\n<li>1.4 \u7ed3\u679c\u6d88\u606f ToolResultMessage&#xff1a;\u8d34\u4e0a\u59d3\u540d\u8d34\u7684\u4f5c\u4e1a<\/li>\n<\/ul>\n<\/li>\n<li>2. \u628a\u5de5\u5177\u6ce8\u518c\u8fdb Agent&#xff1a;\u4ee5 read \u4e3a\u4f8b<\/li>\n<li>3. \u4ece\u5de5\u5177\u8bf4\u660e\u5230\u6267\u884c\u7ed3\u679c&#xff0c;\u518d\u56de\u5230\u6a21\u578b<\/li>\n<li>\n<ul>\n<li>3.1 \u5de5\u5177\u662f\u600e\u4e48\u6df7\u8fdb\u6a21\u578b\u89c6\u91ce\u7684<\/li>\n<li>3.2 \u6a21\u578b\u8fd4\u56de\u7684\u4e0d\u662f\u7b54\u6848&#xff0c;\u662f&#034;\u8bf7\u6c42&#034;<\/li>\n<li>3.3 Agent \u6309\u540d\u5b57\u627e\u4eba&#xff0c;\u7528\u6821\u9a8c\u8fc7\u7684\u53c2\u6570\u5e72\u6d3b<\/li>\n<li>3.4 \u8fd4\u56de\u503c\u600e\u4e48\u53d8\u6210\u4e00\u6761\u80fd\u5bf9\u4e0a\u53f7\u7684\u6d88\u606f<\/li>\n<li>3.5 \u5de5\u5177\u90fd\u5e72\u5b8c\u4e86&#xff0c;\u4e3a\u4ec0\u4e48\u8fd8\u8981\u518d\u95ee\u4e00\u6b21\u6a21\u578b<\/li>\n<\/ul>\n<\/li>\n<li>4. \u8dd1\u4e00\u628a Lab&#xff0c;\u9a8c\u8bc1\u5de5\u5177\u771f\u7684\u5728\u5e72\u6d3b<\/li>\n<li>5. \u5c0f\u7ed3<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925144103-6ab687ff0d2bf.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><br \/>\n P.S. \u63a8\u8350\u4e00\u4e2a\u5927\u795e\u7684\u6559\u7a0b\u7ed9\u60f3\u8981\u4e86\u89e3\u6216\u8005\u5b66\u4e60\u4eba\u5de5\u667a\u80fd\u77e5\u8bc6\u7684\u8bfb\u8005&#xff0c;\u8fd9\u4e2a\u6559\u7a0b\u91cc\u5185\u5bb9\u8bb2\u89e3\u901a\u4fd7\u6613\u61c2\u4e14\u98ce\u8da3\u5e7d\u9ed8&#xff0c;\u5bf9\u6211\u5e2e\u52a9\u5f88\u5927\u3002\u6211\u60f3\u4e0e\u5927\u5bb6\u5206\u4eab\u8fd9\u4e2a\u5b9d\u85cf\u6559\u7a0b&#xff0c;\u8bf7\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u67e5\u770b&#xff0c;<br \/>\n\u4f20\u9001\u95e8https:\/\/blog.csdn.net\/qq_74013365<\/p>\n<p>\u5148\u8bf4\u4e2a\u6709\u70b9\u624e\u5fc3\u7684\u4e8b\u5b9e&#xff1a;\u5f88\u591a\u4eba\u9020\u7684 Agent&#xff0c;\u662f\u4e2a\u5634\u5f3a\u738b\u8005\u3002<\/p>\n<p>\u4f60\u95ee\u5b83&#034;\u5e2e\u6211\u8bfb\u4e00\u4e0b note.txt&#034;&#xff0c;\u5b83\u80fd\u7ed9\u4f60\u4ece&#034;\u6587\u4ef6\u7cfb\u7edf\u7684\u54f2\u5b66\u610f\u4e49&#034;\u4e00\u8def\u804a\u5230&#034;\u4e3a\u4ec0\u4e48\u6362\u884c\u7b26\u8981\u5206\u4e24\u5957\u6807\u51c6&#034;&#xff0c;\u804a\u5f97\u4f60\u70ed\u6cea\u76c8\u7736\u2014\u2014\u4f46\u5c31\u662f\u8bfb\u4e0d\u5230\u6587\u4ef6\u3002\u56e0\u4e3a\u5b83\u6ca1\u624b\u3002<\/p>\n<p>\u6a21\u578b\u8fd9\u73a9\u610f\u513f\u5c31\u8fd9\u6837&#xff1a;\u4e0a\u77e5\u5929\u6587\u4e0b\u77e5\u5730\u7406&#xff0c;\u53ef\u60dc\u662f\u4e2a\u4e91\u73a9\u5bb6\u3002\u5b83\u77e5\u9053\u5168\u4e16\u754c&#xff0c;\u5c31\u662f\u78b0\u4e0d\u5230\u4f60\u786c\u76d8\u4e0a\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u8282\u3002\u4eca\u5929\u8981\u5e72\u7684\u4e8b&#xff0c;\u5c31\u662f\u7ed9\u5b83\u88c5\u4e00\u53cc\u624b\u2014\u2014\u5de5\u5177\u8c03\u7528\u3002<\/p>\n<p>\u5148\u58f0\u660e&#xff0c;\u6211\u4e0d\u662f\u5728\u9a82\u6a21\u578b\u3002\u6a21\u578b\u662f\u771f\u7684\u5f3a&#xff0c;\u5f3a\u5230\u80fd\u628a\u4e00\u672c\u5341\u4e07\u5b57\u7684\u6587\u6863\u603b\u7ed3\u6210\u4e09\u53e5\u8bdd&#xff0c;\u7136\u540e\u8ba9\u4f60\u53bb\u731c\u5b83\u6f0f\u4e86\u54ea\u4e5d\u4e07\u4e5d\u5343\u5b57\u3002<\/p>\n<p>\u4e00\u53e5\u8bdd\u6d41\u7a0b&#xff1a;\u6a21\u578b\u8d1f\u8d23\u70b9\u5355&#xff0c;Agent \u8d1f\u8d23\u4f20\u8bdd&#xff0c;\u5de5\u5177\u8d1f\u8d23\u505a\u996d\u3002\u8c03\u7528\u65b9\u8fd8\u662f\u8001\u89c4\u77e9&#xff0c;\u53ea\u558a\u4e00\u6b21 prompt()\u3002<\/p>\n<p>\u6d41\u7a0b\u662f\u771f\u7684\u7b80\u5355&#xff0c;\u4f46\u522b\u9ad8\u5174\u592a\u65e9\u2014\u2014\u6d41\u7a0b\u8d8a\u7b80\u5355\u7684\u5730\u65b9&#xff0c;\u5751\u5f80\u5f80\u8d8a\u6df1\u3002\u5c31\u50cf\u5916\u5356 App \u754c\u9762\u8d8a\u7b80\u6d01&#xff0c;\u4f60\u8981\u7b49\u7684\u914d\u9001\u65f6\u95f4\u8d8a\u7384\u5b66\u3002<\/p>\n<p>     \u5de5\u5177<\/p>\n<p>     \u6a21\u578b<\/p>\n<p>     Agent<\/p>\n<p>     \u8c03\u7528\u65b9<\/p>\n<p>      \u5de5\u5177<\/p>\n<p>      \u6a21\u578b<\/p>\n<p>      Agent<\/p>\n<p>      \u8c03\u7528\u65b9<\/p>\n<p>  #mermaid-svg-3Ae9sRDmioAvmMdR{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-3Ae9sRDmioAvmMdR .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-3Ae9sRDmioAvmMdR .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-3Ae9sRDmioAvmMdR .error-icon{fill:#552222;}#mermaid-svg-3Ae9sRDmioAvmMdR .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-3Ae9sRDmioAvmMdR .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-3Ae9sRDmioAvmMdR .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-3Ae9sRDmioAvmMdR .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-3Ae9sRDmioAvmMdR .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-3Ae9sRDmioAvmMdR .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-3Ae9sRDmioAvmMdR .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-3Ae9sRDmioAvmMdR .marker{fill:#333333;stroke:#333333;}#mermaid-svg-3Ae9sRDmioAvmMdR .marker.cross{stroke:#333333;}#mermaid-svg-3Ae9sRDmioAvmMdR svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-3Ae9sRDmioAvmMdR p{margin:0;}#mermaid-svg-3Ae9sRDmioAvmMdR .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-3Ae9sRDmioAvmMdR text.actor&gt;tspan{fill:black;stroke:none;}#mermaid-svg-3Ae9sRDmioAvmMdR .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-3Ae9sRDmioAvmMdR .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-3Ae9sRDmioAvmMdR .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-3Ae9sRDmioAvmMdR .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-3Ae9sRDmioAvmMdR #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-3Ae9sRDmioAvmMdR .sequenceNumber{fill:white;}#mermaid-svg-3Ae9sRDmioAvmMdR #sequencenumber{fill:#333;}#mermaid-svg-3Ae9sRDmioAvmMdR #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-3Ae9sRDmioAvmMdR .messageText{fill:#333;stroke:none;}#mermaid-svg-3Ae9sRDmioAvmMdR .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-3Ae9sRDmioAvmMdR .labelText,#mermaid-svg-3Ae9sRDmioAvmMdR .labelText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-3Ae9sRDmioAvmMdR .loopText,#mermaid-svg-3Ae9sRDmioAvmMdR .loopText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-3Ae9sRDmioAvmMdR .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-3Ae9sRDmioAvmMdR .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-3Ae9sRDmioAvmMdR .noteText,#mermaid-svg-3Ae9sRDmioAvmMdR .noteText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-3Ae9sRDmioAvmMdR .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-3Ae9sRDmioAvmMdR .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-3Ae9sRDmioAvmMdR .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-3Ae9sRDmioAvmMdR .actorPopupMenu{position:absolute;}#mermaid-svg-3Ae9sRDmioAvmMdR .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 \/ 0.4));}#mermaid-svg-3Ae9sRDmioAvmMdR .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-3Ae9sRDmioAvmMdR .actor-man circle,#mermaid-svg-3Ae9sRDmioAvmMdR line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-3Ae9sRDmioAvmMdR :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>   \u63d0\u4ea4\u4efb\u52a1<\/p>\n<p>   \u8f93\u5165 &#043; \u5de5\u5177\u8bf4\u660e<\/p>\n<p>   \u5de5\u5177\u540d &#043; \u53c2\u6570 &#043; \u8c03\u7528 ID<\/p>\n<p>   \u8c03\u7528 execute()<\/p>\n<p>   \u8fd4\u56de\u6267\u884c\u7ed3\u679c<\/p>\n<p>   \u8f93\u5165 &#043; \u5de5\u5177\u8c03\u7528 &#043; \u5de5\u5177\u7ed3\u679c<\/p>\n<p>   \u6839\u636e\u5de5\u5177\u7ed3\u679c\u56de\u7b54<\/p>\n<p>   \u4ea4\u4ed8\u56de\u7b54&#xff0c;\u7ed3\u675f\u672c\u6b21\u5904\u7406<\/p>\n<p>\u8fd9\u5f20\u56fe\u7ffb\u8bd1\u6210\u4eba\u8bdd\u5c31\u662f&#xff1a;\u4f60\u8fdb\u9910\u5385\u5750\u4e0b&#xff0c;\u670d\u52a1\u5458&#xff08;Agent&#xff09;\u62ff\u7740\u83dc\u5355&#xff08;\u5de5\u5177\u8bf4\u660e&#xff09;\u53bb\u95ee\u540e\u53a8&#xff08;\u6a21\u578b&#xff09;\u60f3\u5403\u5565&#xff0c;\u540e\u53a8\u558a&#034;\u6211\u8981\u4e00\u4efd read&#xff0c;\u52a0\u4e2a path \u53c2\u6570&#034;&#xff0c;\u670d\u52a1\u5458\u5c31\u53bb\u8ba9\u53a8\u5e08&#xff08;\u5de5\u5177&#xff09;\u505a&#xff0c;\u505a\u5b8c\u7aef\u56de\u6765\u7ed9\u540e\u53a8\u8fc7\u76ee&#xff0c;\u540e\u53a8\u6ee1\u610f\u4e86&#xff0c;\u624d\u628a\u83dc\u7aef\u7ed9\u4f60\u3002\u4ece\u5934\u5230\u5c3e\u53ea\u6709\u4f60\u4e00\u4e2a\u4eba\u70b9\u4e86\u5355&#xff0c;\u5269\u4e0b\u7684\u5168\u5728\u540e\u53f0\u5077\u5077\u5fd9\u6d3b\u2014\u2014\u8fd9\u670d\u52a1\u6001\u5ea6&#xff0c;\u6d77\u5e95\u635e\u770b\u4e86\u90fd\u6c89\u9ed8\u3002<\/p>\n<h3>1. \u5148\u5206\u6e05\u56db\u4e2a\u89d2\u8272&#xff0c;\u522b\u628a&#034;\u70b9\u83dc&#034;\u5f53\u6210&#034;\u4e0a\u83dc&#034;<\/h3>\n<p>\u5f88\u591a\u4eba\u7b2c\u4e00\u6b21\u63a5\u89e6\u5de5\u5177\u8c03\u7528&#xff0c;\u5bb9\u6613\u72af\u4e00\u4e2a\u9519\u8bef&#xff1a;\u6a21\u578b\u4e00\u8bf4&#034;\u6211\u8981\u8c03\u5de5\u5177&#034;&#xff0c;\u5c31\u89c9\u5f97\u5de5\u5177\u5df2\u7ecf\u8dd1\u4e86\u3002\u9519&#xff01;\u8fd9\u4e2d\u95f4\u9694\u7740\u56db\u5c42\u3002\u8c01\u8d1f\u8d23\u4ec0\u4e48&#xff0c;\u5fc5\u987b\u62ce\u6e05\u695a&#xff0c;\u4e0d\u7136\u8c03 bug \u7684\u65f6\u5019\u4f60\u4f1a\u5bf9\u7740\u5c4f\u5e55\u6000\u7591\u4eba\u751f&#xff1a;\u8fd9\u5230\u5e95\u662f\u6a21\u578b\u6ca1\u8c03&#xff0c;\u8fd8\u662f\u5de5\u5177\u6ca1\u8dd1&#xff0c;\u8fd8\u662f\u8dd1\u4e86\u6ca1\u8fd4\u56de&#xff1f;<\/p>\n<table>\n<tr>\u5bf9\u8c61\u7531\u8c01\u63d0\u4f9b\u5728\u8c03\u7528\u8fc7\u7a0b\u4e2d\u7684\u4f5c\u7528<\/tr>\n<tbody>\n<tr>\n<td>\u5de5\u5177\u5b9a\u4e49 AgentTool<\/td>\n<td>\u5e94\u7528\u6ce8\u518c\u5230 Agent \u7684\u5de5\u5177\u5bf9\u8c61<\/td>\n<td>\u5de5\u5177\u540d\u3001\u7528\u9014\u3001\u53c2\u6570\u683c\u5f0f&#xff0c;\u4ee5\u53ca\u672c\u5730 execute() \u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>\u8c03\u7528\u8bf7\u6c42 ToolCall<\/td>\n<td>\u6a21\u578b\u56de\u590d<\/td>\n<td>\u6307\u5b9a\u5de5\u5177\u540d\u3001\u53c2\u6570\u548c\u672c\u6b21\u8c03\u7528\u7684 ID<\/td>\n<\/tr>\n<tr>\n<td>\u51fd\u6570\u8fd4\u56de\u503c AgentToolResult<\/td>\n<td>execute()<\/td>\n<td>\u7ed9\u6a21\u578b\u8bfb\u53d6\u7684 content \u548c\u7ed9\u7a0b\u5e8f\u4f7f\u7528\u7684 details<\/td>\n<\/tr>\n<tr>\n<td>\u7ed3\u679c\u6d88\u606f ToolResultMessage<\/td>\n<td>Agent<\/td>\n<td>\u7ed9\u8fd4\u56de\u503c\u8865\u4e0a\u8c03\u7528 ID\u3001\u5de5\u5177\u540d\u548c\u6210\u529f\u6216\u5931\u8d25\u6807\u8bb0&#xff0c;\u52a0\u5165\u5bf9\u8bdd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u5f20\u8868\u5efa\u8bae\u622a\u56fe\u4fdd\u5b58&#xff0c;\u9762\u8bd5\u524d\u770b\u4e00\u904d&#xff0c;\u80fd\u5c11\u6389\u4e00\u5c42\u5934\u53d1\u3002\u771f\u7684&#xff0c;\u6211\u4e0a\u6b21\u9762\u8bd5\u7b54\u5de5\u5177\u8c03\u7528&#xff0c;\u5168\u9760\u8fd9\u5f20\u8868\u7eed\u547d\u3002<\/p>\n<h4>1.1 \u5de5\u5177\u5b9a\u4e49 AgentTool&#xff1a;\u8d34\u5728\u95e8\u53e3\u7684\u83dc\u5355<\/h4>\n<p>\u83dc\u5355\u4e0a\u5199\u4ec0\u4e48&#xff1f;\u83dc\u540d&#xff08;name&#xff09;\u3001\u62db\u724c\u4ecb\u7ecd&#xff08;description&#xff09;\u3001\u914d\u6599\u8868&#xff08;parameters&#xff09;&#xff0c;\u6700\u540e\u8fd8\u6302\u7740\u4e00\u4e2a\u672c\u5730 execute()\u2014\u2014\u76f8\u5f53\u4e8e\u540e\u53a8\u7684\u7076\u53f0&#xff1a;\u4f60\u770b\u5f97\u89c1&#xff0c;\u4f46\u4f60\u81ea\u5df1\u8fdb\u4e0d\u53bb\u540e\u53a8\u3002<\/p>\n<p><span class=\"token comment\">\/\/ pi-ai&#xff1a;\u6a21\u578b\u9700\u8981\u7684\u5de5\u5177\u8bf4\u660e<\/span><br \/>\n<span class=\"token keyword\">export<\/span> <span class=\"token keyword\">interface<\/span> <span class=\"token class-name\">Tool<span class=\"token operator\">&lt;<\/span>TParameters <span class=\"token keyword\">extends<\/span> TSchema <span class=\"token operator\">&#061;<\/span> TSchema<span class=\"token operator\">&gt;<\/span><\/span> <span class=\"token punctuation\">{<\/span><br \/>\nname<span class=\"token operator\">:<\/span> <span class=\"token builtin\">string<\/span><span class=\"token punctuation\">;<\/span><br \/>\ndescription<span class=\"token operator\">:<\/span> <span class=\"token builtin\">string<\/span><span class=\"token punctuation\">;<\/span><br \/>\nparameters<span class=\"token operator\">:<\/span> TParameters<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\">\/\/ pi-agent-core&#xff1a;\u5728\u5de5\u5177\u8bf4\u660e\u4e0a\u589e\u52a0\u672c\u5730\u6267\u884c\u51fd\u6570<\/span><br \/>\n<span class=\"token keyword\">export<\/span> <span class=\"token keyword\">interface<\/span> <span class=\"token class-name\">AgentTool<span class=\"token operator\">&lt;<\/span>TParameters <span class=\"token keyword\">extends<\/span> TSchema <span class=\"token operator\">&#061;<\/span> TSchema<span class=\"token punctuation\">,<\/span> TDetails <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">any<\/span><span class=\"token operator\">&gt;<\/span><\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">Tool<span class=\"token operator\">&lt;<\/span>TParameters<span class=\"token operator\">&gt;<\/span><\/span> <span class=\"token punctuation\">{<\/span><br \/>\nlabel<span class=\"token operator\">:<\/span> <span class=\"token builtin\">string<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\nexecute<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">(<\/span><br \/>\ntoolCallId<span class=\"token operator\">:<\/span> <span class=\"token builtin\">string<\/span><span class=\"token punctuation\">,<\/span><br \/>\nparams<span class=\"token operator\">:<\/span> Static<span class=\"token operator\">&lt;<\/span>TParameters<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token builtin\">Promise<\/span><span class=\"token operator\">&lt;<\/span>AgentToolResult<span class=\"token operator\">&lt;<\/span>TDetails<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6ce8\u610f&#xff0c;\u83dc\u5355\u662f\u7ed9\u8c01\u770b\u7684&#xff1f;\u7ed9\u6a21\u578b\u770b\u7684\u3002\u6a21\u578b\u6839\u636e\u83dc\u540d\u548c\u4ecb\u7ecd\u5224\u65ad&#034;\u8fd9\u83dc\u5408\u4e0d\u5408\u53e3\u5473&#034;&#xff0c;\u800c execute() \u662f\u7ed9 Agent \u7528\u7684\u3002\u4e00\u4e2a\u4e1c\u897f\u4e24\u5934\u7528&#xff0c;\u8ddf\u516c\u53f8\u91cc\u90a3\u79cd&#034;\u5bf9\u5916\u4e00\u5957\u8bf4\u8f9e\u3001\u5bf9\u5185\u4e00\u5957\u8bf4\u8f9e&#034;\u7684\u5468\u62a5&#xff0c;\u662f\u4e00\u4e2a\u9053\u7406\u3002<\/p>\n<h4>1.2 \u8c03\u7528\u8bf7\u6c42 ToolCall&#xff1a;\u6a21\u578b\u7684&#034;\u53e3\u5934\u627f\u8bfa&#034;<\/h4>\n<p>\u6a21\u578b\u8bf4&#xff1a;\u201c\u6211\u8981\u7528 read \u8bfb note.txt\u3002\u201d\u2014\u2014\u8fd9\u5c31\u662f ToolCall&#xff0c;\u5305\u542b\u5de5\u5177\u540d\u3001\u53c2\u6570\u3001\u8fd8\u6709\u672c\u6b21\u8c03\u7528\u7684 ID\u3002<\/p>\n<p>\u91cd\u70b9\u6765\u4e86&#xff1a;\u8fd9\u53ea\u662f\u8bf7\u6c42&#xff0c;\u6587\u4ef6\u8fd8\u6ca1\u6253\u5f00\u3002\u8fd9\u5c31\u50cf\u4f60\u558a&#034;\u660e\u5929\u5f00\u59cb\u51cf\u80a5&#034;&#xff0c;\u627f\u8bfa\u63b7\u5730\u6709\u58f0&#xff0c;\u884c\u52a8\u5206\u6587\u6ca1\u6709\u3002\u6a21\u578b\u4e5f\u662f&#xff0c;\u5634\u4e0a\u8bf4\u5f97\u597d\u597d\u7684&#xff0c;\u624b\u662f\u4e00\u70b9\u6ca1\u52a8\u2014\u2014\u54e6\u5bf9&#xff0c;\u5b83\u672c\u6765\u5c31\u6ca1\u624b\u3002<\/p>\n<h4>1.3 \u8fd4\u56de\u503c AgentToolResult&#xff1a;\u4ea4\u4e0a\u6765\u7684\u4f5c\u4e1a<\/h4>\n<p>\u5de5\u5177\u5e72\u5b8c\u6d3b&#xff0c;\u628a\u7ed3\u679c\u4ea4\u56de\u6765\u3002content \u662f\u7ed9\u6a21\u578b\u770b\u7684\u6b63\u6587&#xff0c;details \u662f\u7ed9\u7a0b\u5e8f\u7528\u7684\u7ed3\u6784\u5316\u6570\u636e\u3002\u4e00\u4efd\u4f5c\u4e1a\u5199\u4e24\u904d&#xff1a;\u4e00\u904d\u4ea4\u8001\u5e08\u6279\u6539&#xff0c;\u4e00\u904d\u81ea\u5df1\u5b58\u6863\u3002<\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">interface<\/span> <span class=\"token class-name\">AgentToolResult<span class=\"token operator\">&lt;<\/span><span class=\"token constant\">T<\/span><span class=\"token operator\">&gt;<\/span><\/span> <span class=\"token punctuation\">{<\/span><br \/>\ncontent<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">(<\/span>TextContent <span class=\"token operator\">|<\/span> ImageContent<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\ndetails<span class=\"token operator\">:<\/span> <span class=\"token constant\">T<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6ca1\u6709\u9644\u52a0\u4fe1\u606f\u7684\u65f6\u5019&#xff0c;details \u53ef\u4ee5\u4e3a undefined\u2014\u2014\u7ffb\u8bd1\u4e00\u4e0b&#xff1a;\u6ca1\u5199\u5b58\u6863&#xff0c;\u7eaf\u4ea4\u4f5c\u4e1a\u3002\u8001\u5e08\u770b\u4e86\u90fd\u5f97\u5938\u4e00\u53e5&#xff1a;\u884c&#xff0c;\u81f3\u5c11\u4ea4\u7684\u662f\u4f5c\u4e1a&#xff0c;\u4e0d\u662f\u767d\u7eb8\u3002<\/p>\n<h4>1.4 \u7ed3\u679c\u6d88\u606f ToolResultMessage&#xff1a;\u8d34\u4e0a\u59d3\u540d\u8d34\u7684\u4f5c\u4e1a<\/h4>\n<p>Agent \u62ff\u5230\u8fd4\u56de\u503c&#xff0c;\u8865\u4e0a\u8c03\u7528 ID\u3001\u5de5\u5177\u540d\u3001\u6210\u529f\u5931\u8d25\u6807\u8bb0&#xff0c;\u53d8\u6210\u4e00\u6761\u6d88\u606f&#xff0c;\u624d\u80fd\u8fdb\u5bf9\u8bdd\u5386\u53f2\u3002<\/p>\n<p>\u8fd9\u64cd\u4f5c\u50cf\u6781\u4e86\u73ed\u4e3b\u4efb&#xff1a;\u6536\u4f5c\u4e1a\u5148\u8ba9\u4f60\u5199\u540d\u5b57&#xff0c;\u4e0d\u7136\u4ea4\u4e0a\u6765\u7684\u5168\u662f\u65e0\u540d\u6c0f\u3002\u5230\u65f6\u5019\u4f5c\u4e1a\u53d1\u4e0b\u6765&#xff0c;\u4f60\u90fd\u4e0d\u77e5\u9053\u54ea\u4efd\u662f\u4f60\u7684\u3002<\/p>\n<h3>2. \u628a\u5de5\u5177\u6ce8\u518c\u8fdb Agent&#xff1a;\u4ee5 read \u4e3a\u4f8b<\/h3>\n<p>\u63a5\u5165\u7684\u5165\u53e3\u662f initialState.tools\u3002\u628a\u7b26\u5408 AgentTool \u5951\u7ea6\u7684\u5bf9\u8c61\u4e22\u8fdb\u8fd9\u4e2a\u6570\u7ec4&#xff0c;Agent \u5c31\u4f1a\u81ea\u52a8\u628a\u5de5\u5177\u8bf4\u660e\u5582\u7ed9\u6a21\u578b&#xff0c;\u7136\u540e\u6267\u884c\u6a21\u578b\u4e0b\u8fbe\u7684\u8c03\u7528\u8bf7\u6c42\u3002<\/p>\n<p>\u5148\u4ea4\u4ee3\u4e00\u4e0b\u573a\u666f&#xff1a;\u5f53\u524d\u76ee\u5f55\u4e0b\u6709\u4e2a note.txt&#xff0c;\u91cc\u9762\u5199\u7740&#034;\u672c\u6b21\u9a8c\u8bc1\u4ee3\u53f7&#xff1a;read-643219&#034;\u3002\u4efb\u52a1\u662f\u8ba9\u6a21\u578b\u628a\u8fd9\u4e2a\u4ee3\u53f7\u8bfb\u51fa\u6765\u3002\u8fd9\u4efb\u52a1\u8bbe\u8ba1\u5f97\u5f88\u9e21\u8d3c&#xff1a;\u6a21\u578b\u4e0d\u8c03\u7528\u5de5\u5177&#xff0c;\u5b83\u5c31\u6c38\u8fdc\u4e0d\u77e5\u9053\u7b54\u6848\u2014\u2014\u5c31\u50cf\u9762\u8bd5\u5b98\u628a\u7b54\u6848\u85cf\u5728\u684c\u5b50\u91cc&#xff0c;\u4f60\u4e0d\u4f38\u624b&#xff0c;\u5c31\u6c38\u8fdc\u62ff\u4e0d\u5230 offer\u3002<\/p>\n<p>\u8fd9\u914d\u7f6e\u5c31\u8ddf\u7ed9\u624b\u673a\u88c5 App \u4e00\u6837&#xff1a;\u88c5\u4e0a\u4e86&#xff0c;\u6a21\u578b\u5c31&#034;\u77e5\u9053\u4f60\u6709\u8fd9\u4e2a\u529f\u80fd&#034;&#xff1b;\u6ca1\u88c5&#xff0c;\u6a21\u578b\u8fde\u4f60\u6709\u8fd9\u529f\u80fd\u90fd\u4e0d\u77e5\u9053&#xff0c;\u53ea\u80fd\u9760\u8111\u8865\u3002\u8111\u8865\u7684\u7ed3\u679c\u561b&#xff0c;\u5927\u5bb6\u90fd\u77e5\u9053&#xff0c;\u6a21\u578b\u8111\u8865\u8d77\u6765&#xff0c;\u80fd\u628a 404 \u8bf4\u6210&#034;\u6587\u4ef6\u53bb\u5ea6\u5047\u4e86&#034;\u3002<\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> Agent <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#034;&#064;earendil-works\/pi-agent-core&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ read \u662f Lab \u4e2d\u5df2\u521b\u5efa\u5e76\u7ed1\u5b9a\u672c\u5730\u6267\u884c\u73af\u5883\u7684\u539f\u751f\u5de5\u5177\u3002<\/span><br \/>\n<span class=\"token keyword\">const<\/span> agent <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Agent<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span><br \/>\ninitialState<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\nmodel<span class=\"token punctuation\">,<\/span><br \/>\nsystemPrompt<span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;\u4e25\u683c\u6309\u7528\u6237\u8981\u6c42\u56de\u7b54\u3002\u8bfb\u53d6\u6587\u4ef6\u5fc5\u987b\u8c03\u7528 read&#xff0c;\u53d6\u5f97\u7ed3\u679c\u540e\u53ea\u56de\u590d\u6587\u4ef6\u4e2d\u7684\u9a8c\u8bc1\u4ee3\u53f7&#xff0c;\u4e0d\u8981\u91cd\u590d\u8bfb\u53d6\u3002&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\nmessages<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\ntools<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span>read<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token function-variable function\">streamFn<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">(<\/span>model<span class=\"token punctuation\">,<\/span> context<span class=\"token punctuation\">,<\/span> options<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span><br \/>\nmodels<span class=\"token punctuation\">.<\/span><span class=\"token function\">streamSimple<\/span><span class=\"token punctuation\">(<\/span>model<span class=\"token punctuation\">,<\/span> context<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token operator\">&#8230;<\/span>options<span class=\"token punctuation\">,<\/span> maxTokens<span class=\"token operator\">:<\/span> <span class=\"token number\">256<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u5b8c\u6574 Lab \u901a\u8fc7 subscribe() \u8bb0\u5f55\u5de5\u5177\u6267\u884c\u548c\u6d88\u606f\u7ed3\u675f\u4e8b\u4ef6\u3002<\/span><br \/>\n<span class=\"token keyword\">await<\/span> agent<span class=\"token punctuation\">.<\/span><span class=\"token function\">prompt<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8bf7\u7528 read \u8bfb\u53d6 note.txt&#xff0c;\u53ea\u56de\u590d\u5176\u4e2d\u7684\u9a8c\u8bc1\u4ee3\u53f7\u3002&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7cfb\u7edf\u63d0\u793a\u8bcd\u91cc\u5199\u5f97\u5f88\u76f4\u767d&#xff1a;\u201c\u8bfb\u53d6\u6587\u4ef6\u5fc5\u987b\u8c03\u7528 read\u201d\u3002\u4e3a\u4ec0\u4e48&#xff1f;\u56e0\u4e3a\u4f60\u4e0d\u8bf4&#xff0c;\u6a21\u578b\u53ef\u80fd\u89c9\u5f97\u5b83\u81ea\u5df1\u5c31\u80fd\u8bfb\u6587\u4ef6\u2014\u2014\u6bd5\u7adf\u5b83\u5e73\u65f6\u5c31\u7231\u51ed\u7a7a\u53d1\u6325\u3002\u54e6\u4e0d\u5bf9&#xff0c;\u53eb&#034;\u53d1\u6325\u60f3\u8c61\u529b&#034;\u3002<\/p>\n<p>\u7136\u540e\u8c03\u7528\u65b9\u5c31\u5e72\u4e00\u4ef6\u4e8b&#xff1a;await agent.prompt()\u3002\u5269\u4e0b\u7684 Agent \u5168\u5305\u4e86\u3002\u4f60\u70b9\u5b8c\u83dc\u5c31\u5750\u7740&#xff0c;\u83dc\u600e\u4e48\u505a\u7684\u3001\u8c01\u505a\u7684\u3001\u76d8\u5b50\u8c01\u6d17\u7684&#xff0c;\u90fd\u4e0d\u7528\u4f60\u7ba1\u3002\u8fd9\u5927\u6982\u5c31\u662f\u7a0b\u5e8f\u5458\u80fd\u4eab\u53d7\u5230\u7684\u6700\u9ad8\u7ea7\u522b\u670d\u52a1\u4e86\u3002<\/p>\n<h3>3. \u4ece\u5de5\u5177\u8bf4\u660e\u5230\u6267\u884c\u7ed3\u679c&#xff0c;\u518d\u56de\u5230\u6a21\u578b<\/h3>\n<p>\u524d\u9762\u7ae0\u8282\u7684\u8f93\u5165\u6574\u7406\u3001\u5386\u53f2\u5408\u5e76\u3001\u6a21\u578b\u8c03\u7528\u5165\u53e3\u5168\u90fd\u4e0d\u52a8&#xff0c;\u5de5\u5177\u8c03\u7528\u53d1\u751f\u5728 runLoop() \u5185\u90e8\u3002\u4e3b\u8def\u5f84\u957f\u8fd9\u6837&#xff1a;<\/p>\n<p>runLoop()<br \/>\n\u251c\u2500 streamAssistantResponse() \u2192 \u7b2c\u4e00\u6b21\u8bf7\u6c42\u6a21\u578b&#xff0c;\u5f97\u5230\u5305\u542b\u5de5\u5177\u8c03\u7528\u7684\u6d88\u606f<br \/>\n\u251c\u2500 executeToolCalls() \u2192 \u8c03\u5ea6\u5de5\u5177\u6267\u884c<br \/>\n\u2502  \u251c\u2500 prepareToolCall() \u2192 \u627e\u5230\u5de5\u5177&#xff0c;\u6821\u9a8c\u53c2\u6570<br \/>\n\u2502  \u251c\u2500 executePreparedToolCall() \u2192 \u8c03\u7528\u672c\u5730 execute()<br \/>\n\u2502  \u2514\u2500 createToolResultMessage() \/ emitToolResultMessage() \u2192 \u5f62\u6210\u5e76\u4fdd\u5b58\u7ed3\u679c\u6d88\u606f<br \/>\n\u2514\u2500 streamAssistantResponse() \u2192 \u5e26\u4e0a\u8c03\u7528\u548c\u7ed3\u679c&#xff0c;\u518d\u6b21\u8bf7\u6c42\u6a21\u578b<\/p>\n<h4>3.1 \u5de5\u5177\u662f\u600e\u4e48\u6df7\u8fdb\u6a21\u578b\u89c6\u91ce\u7684<\/h4>\n<p>createContextSnapshot() \u505a\u5feb\u7167\u7684\u65f6\u5019&#xff0c;\u987a\u624b\u628a\u5de5\u5177\u6570\u7ec4\u4e5f\u590d\u5236\u4e86\u4e00\u4efd&#xff1a;<\/p>\n<p><span class=\"token keyword\">private<\/span> <span class=\"token function\">createContextSnapshot<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span> AgentContext <span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span><br \/>\nsystemPrompt<span class=\"token operator\">:<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>_state<span class=\"token punctuation\">.<\/span>systemPrompt<span class=\"token punctuation\">,<\/span><br \/>\nmessages<span class=\"token operator\">:<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>_state<span class=\"token punctuation\">.<\/span>messages<span class=\"token punctuation\">.<\/span><span class=\"token function\">slice<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\ntools<span class=\"token operator\">:<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>_state<span class=\"token punctuation\">.<\/span>tools<span class=\"token punctuation\">.<\/span><span class=\"token function\">slice<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7136\u540e streamAssistantResponse() \u628a\u5de5\u5177\u548c\u6d88\u606f\u4e00\u8d77\u4ea4\u7ed9\u6a21\u578b\u8c03\u7528\u51fd\u6570&#xff1a;<\/p>\n<p><span class=\"token keyword\">const<\/span> llmContext<span class=\"token operator\">:<\/span> Context <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\nsystemPrompt<span class=\"token operator\">:<\/span> context<span class=\"token punctuation\">.<\/span>systemPrompt<span class=\"token punctuation\">,<\/span><br \/>\nmessages<span class=\"token operator\">:<\/span> llmMessages<span class=\"token punctuation\">,<\/span><br \/>\ntools<span class=\"token operator\">:<\/span> context<span class=\"token punctuation\">.<\/span>tools<span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> response <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> <span class=\"token function\">streamFunction<\/span><span class=\"token punctuation\">(<\/span>config<span class=\"token punctuation\">.<\/span>model<span class=\"token punctuation\">,<\/span> llmContext<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token operator\">&#8230;<\/span>config<span class=\"token punctuation\">,<\/span><br \/>\napiKey<span class=\"token operator\">:<\/span> resolvedApiKey<span class=\"token punctuation\">,<\/span><br \/>\nsignal<span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u91cc\u5212\u4e2a\u91cd\u70b9&#xff1a;\u53d1\u7ed9\u6a21\u578b\u7684\u53ea\u662f\u5de5\u5177\u7684&#034;\u7b80\u5386&#034;\u2014\u2014\u540d\u5b57\u3001\u4ecb\u7ecd\u3001\u53c2\u6570\u7ed3\u6784&#xff0c;\u7531 convertTools() \u63d0\u53d6&#xff1b;\u771f\u6b63\u7684 execute() \u51fd\u6570\u7559\u5728\u672c\u5730\u3002\u6a21\u578b\u770b\u5230\u7684\u662f\u4ecb\u7ecd\u4fe1&#xff0c;\u52a8\u624b\u7684\u662f\u4f60\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u8fd9\u8bbe\u8ba1\u50cf\u6781\u4e86\u76f8\u4eb2&#xff1a;\u9012\u8fc7\u53bb\u7684\u662f\u4e00\u4efd\u7b80\u5386&#xff0c;\u771f\u6b63\u8ddf\u4f60\u8fc7\u65e5\u5b50\u7684\u662f\u7b80\u5386\u80cc\u540e\u90a3\u4e2a\u4eba\u3002\u6a21\u578b\u4ee5\u4e3a\u81ea\u5df1\u662f\u5728\u8ddf read \u5bf9\u8bdd&#xff0c;\u5176\u5b9e\u5bf9\u9762\u662f Agent \u7684\u672c\u5730\u51fd\u6570\u3002\u7f51\u604b\u5954\u73b0\u73b0\u573a\u3002<\/p>\n<h4>3.2 \u6a21\u578b\u8fd4\u56de\u7684\u4e0d\u662f\u7b54\u6848&#xff0c;\u662f&#034;\u8bf7\u6c42&#034;<\/h4>\n<p>\u7b2c\u4e00\u6b21\u8bf7\u6c42\u6a21\u578b&#xff0c;\u56de\u590d\u7684 content \u91cc\u9664\u4e86\u6587\u5b57&#xff0c;\u53ef\u80fd\u591a\u51fa\u8fd9\u6837\u4e00\u4e2a\u5185\u5bb9\u5757\u3002\u8fd9\u662f ToolCall \u7684\u6838\u5fc3\u5b9a\u4e49&#xff1a;<\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">interface<\/span> <span class=\"token class-name\">ToolCall<\/span> <span class=\"token punctuation\">{<\/span><br \/>\ntype<span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;toolCall&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\nid<span class=\"token operator\">:<\/span> <span class=\"token builtin\">string<\/span><span class=\"token punctuation\">;<\/span><br \/>\nname<span class=\"token operator\">:<\/span> <span class=\"token builtin\">string<\/span><span class=\"token punctuation\">;<\/span><br \/>\narguments<span class=\"token operator\">:<\/span> Record<span class=\"token operator\">&lt;<\/span><span class=\"token builtin\">string<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">any<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4f8b\u5982\u6a21\u578b\u8981\u6c42\u8bfb\u53d6\u6587\u4ef6\u65f6&#xff0c;\u6d88\u606f\u91cc\u4f1a\u5305\u542b\u8fd9\u6837\u7684\u6570\u636e&#xff0c;\u8c03\u7528 ID \u4ec5\u4f5c\u793a\u610f&#xff1a;<\/p>\n<p><span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token literal-property property\">type<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;toolCall&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token literal-property property\">id<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;call_1&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token literal-property property\">name<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;read&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token literal-property property\">arguments<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token literal-property property\">path<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;note.txt&#034;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7ffb\u8bd1\u4e00\u4e0b&#xff1a;\u6a21\u578b\u8bf4&#034;\u6211\u60f3\u8bfb\u8fd9\u4e2a\u6587\u4ef6&#034;\u3002\u5b83\u53ea\u662f\u8868\u8fbe\u4e86\u610f\u613f\u3002\u6ce8\u610f&#xff0c;\u8fd9\u6761\u6d88\u606f\u7684 role \u8fd8\u662f assistant&#xff0c;\u4f1a\u7167\u5e38\u8fdb\u5165\u5386\u53f2\u3002\u6b64\u65f6\u6a21\u578b\u7684\u72b6\u6001&#xff0c;\u5c31\u662f\u90a3\u53e5\u7ecf\u5178\u540d\u8a00&#xff1a;\u6211\u53ea\u662f\u95ee\u95ee&#xff0c;\u53c8\u6ca1\u8ba9\u4f60\u771f\u5e72\u3002<\/p>\n<h4>3.3 Agent \u6309\u540d\u5b57\u627e\u4eba&#xff0c;\u7528\u6821\u9a8c\u8fc7\u7684\u53c2\u6570\u5e72\u6d3b<\/h4>\n<p>executeToolCalls() \u5f00\u5de5\u3002\u6bcf\u4e2a\u8c03\u7528\u5148\u8fdb prepareToolCall()&#xff1a;\u5148\u6309 name \u627e\u5de5\u5177&#xff0c;\u518d\u51c6\u5907\u53c2\u6570&#xff1a;<\/p>\n<p><span class=\"token keyword\">const<\/span> tool <span class=\"token operator\">&#061;<\/span> currentContext<span class=\"token punctuation\">.<\/span>tools<span class=\"token operator\">?.<\/span><span class=\"token function\">find<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>t<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> t<span class=\"token punctuation\">.<\/span>name <span class=\"token operator\">&#061;&#061;&#061;<\/span> toolCall<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> preparedToolCall <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">prepareToolCallArguments<\/span><span class=\"token punctuation\">(<\/span>tool<span class=\"token punctuation\">,<\/span> toolCall<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> validatedArgs <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">validateToolArguments<\/span><span class=\"token punctuation\">(<\/span>tool<span class=\"token punctuation\">,<\/span> preparedToolCall<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span><br \/>\nkind<span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;prepared&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\ntoolCall<span class=\"token punctuation\">,<\/span><br \/>\ntool<span class=\"token punctuation\">,<\/span><br \/>\nargs<span class=\"token operator\">:<\/span> validatedArgs<span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6ce8\u610f\u662f\u6309\u540d\u5b57\u627e&#xff0c;\u6a21\u578b\u8981\u662f\u628a read \u62fc\u6210 reed&#xff0c;\u76f4\u63a5\u67e5\u65e0\u6b64\u4eba\u3002\u518d\u6821\u9a8c\u53c2\u6570&#xff0c;validateToolArguments() \u7528\u53c2\u6570\u7ed3\u6784\u628a\u8f93\u5165\u8fc7\u4e00\u904d&#xff0c;\u9632\u6b62\u6a21\u578b\u4f20\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u8def\u5f84\u3002\u8fd9\u4e00\u6b65\u50cf\u4ec0\u4e48&#xff1f;\u50cf\u5916\u5356\u5e73\u53f0&#xff1a;\u5148\u770b\u4f60\u70b9\u7684\u5e97\u5728\u4e0d\u5728\u914d\u9001\u8303\u56f4&#xff0c;\u4e0d\u5728\u76f4\u63a5\u63d0\u793a&#034;\u8d85\u51fa\u914d\u9001\u8303\u56f4&#034;&#xff0c;\u4e0d\u4f1a\u50bb\u4e4e\u4e4e\u6d3e\u4e2a\u9a91\u624b\u53bb\u706b\u661f\u3002<\/p>\n<p>\u51c6\u5907\u901a\u8fc7\u540e&#xff0c;executePreparedToolCall() \u8c03\u7528\u5de5\u5177\u7684 execute()\u3002\u4e0b\u9762\u7528\u4f2a\u4ee3\u7801\u4fdd\u7559\u5b9e\u9645\u7684\u8c03\u7528\u540d\u79f0\u548c\u4e3b\u8981\u53c2\u6570&#xff1a;<\/p>\n<p><span class=\"token keyword\">const<\/span> result <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> prepared<span class=\"token punctuation\">.<\/span>tool<span class=\"token punctuation\">.<\/span><span class=\"token function\">execute<\/span><span class=\"token punctuation\">(<\/span><br \/>\nprepared<span class=\"token punctuation\">.<\/span>toolCall<span class=\"token punctuation\">.<\/span>id<span class=\"token punctuation\">,<\/span><br \/>\nprepared<span class=\"token punctuation\">.<\/span>args<span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span> result<span class=\"token punctuation\">,<\/span> isError<span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u627e\u5230\u7684\u662f read&#xff0c;\u53c2\u6570\u662f { path: &#034;note.txt&#034; }&#xff0c;\u5177\u4f53\u600e\u4e48\u8bfb&#xff0c;\u5de5\u5177\u81ea\u5df1\u5fc3\u91cc\u6709\u6570\u3002\u4f60\u53ea\u9700\u8981\u77e5\u9053&#xff1a;\u4eba\u5bb6\u662f\u4e13\u4e1a\u7684&#xff0c;\u522b\u95ee&#xff0c;\u95ee\u5c31\u662f\u5e95\u5c42\u5b9e\u73b0\u3002<\/p>\n<p>\u8fd9\u6b21\u6267\u884c\u5f97\u5230\u7684\u8fd4\u56de\u503c\u957f\u8fd9\u6837&#xff1a;<\/p>\n<p>\u770b\u5230\u8fd9\u91cc\u4f60\u53ef\u80fd\u60f3\u95ee&#xff1a;\u90a3 execute() \u91cc\u9762\u5230\u5e95\u5e72\u4e86\u5565&#xff1f;\u7b54\u6848\u662f&#xff1a;\u4e0d\u5173\u4f60\u4e8b\u3002\u5de5\u5177\u8d1f\u8d23\u628a\u6d3b\u5e72\u5b8c&#xff0c;\u4f60\u8d1f\u8d23\u770b\u7ed3\u679c\u3002\u5c31\u50cf\u4f60\u53bb\u7406\u53d1\u5e97&#xff0c;\u4e0d\u4f1a\u8981\u6c42\u7406\u53d1\u5e08\u73b0\u573a\u76f4\u64ad\u4ed6\u7684\u526a\u5200\u662f\u600e\u4e48\u52a8\u7684\u3002<\/p>\n<p><span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token literal-property property\">content<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">{<\/span> <span class=\"token literal-property property\">type<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;text&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token literal-property property\">text<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;\u672c\u6b21\u9a8c\u8bc1\u4ee3\u53f7&#xff1a;read-643219&#034;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token literal-property property\">details<\/span><span class=\"token operator\">:<\/span> <span class=\"token keyword\">undefined<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>3.4 \u8fd4\u56de\u503c\u600e\u4e48\u53d8\u6210\u4e00\u6761\u80fd\u5bf9\u4e0a\u53f7\u7684\u6d88\u606f<\/h4>\n<p>createToolResultMessage() \u51fa\u573a&#xff0c;\u628a\u8fd4\u56de\u503c\u52a0\u5de5\u6210 toolResult \u6d88\u606f&#xff1a;toolCallId \u76f4\u63a5\u590d\u5236\u6a21\u578b\u8bf7\u6c42\u7684 id\u2014\u2014\u201c\u8fd9\u6761\u7ed3\u679c\u662f\u8c01\u8981\u7684\u201d&#xff0c;\u4e00\u76ee\u4e86\u7136\u3002<\/p>\n<p><span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span><br \/>\nrole<span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;toolResult&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\ntoolCallId<span class=\"token operator\">:<\/span> finalized<span class=\"token punctuation\">.<\/span>toolCall<span class=\"token punctuation\">.<\/span>id<span class=\"token punctuation\">,<\/span><br \/>\ntoolName<span class=\"token operator\">:<\/span> finalized<span class=\"token punctuation\">.<\/span>toolCall<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">,<\/span><br \/>\ncontent<span class=\"token operator\">:<\/span> finalized<span class=\"token punctuation\">.<\/span>result<span class=\"token punctuation\">.<\/span>content <span class=\"token operator\">??<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\ndetails<span class=\"token operator\">:<\/span> finalized<span class=\"token punctuation\">.<\/span>result<span class=\"token punctuation\">.<\/span>details<span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\nisError<span class=\"token operator\">:<\/span> finalized<span class=\"token punctuation\">.<\/span>isError<span class=\"token punctuation\">,<\/span><br \/>\ntimestamp<span class=\"token operator\">:<\/span> Date<span class=\"token punctuation\">.<\/span><span class=\"token function\">now<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u63a5\u7740 emitToolResultMessage() \u53d1\u4e8b\u4ef6&#xff1a;<\/p>\n<p><span class=\"token keyword\">await<\/span> <span class=\"token function\">emit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span> type<span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;message_start&#034;<\/span><span class=\"token punctuation\">,<\/span> message<span class=\"token operator\">:<\/span> toolResultMessage <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">await<\/span> <span class=\"token function\">emit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span> type<span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;message_end&#034;<\/span><span class=\"token punctuation\">,<\/span> message<span class=\"token operator\">:<\/span> toolResultMessage <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7b2c\u4e03\u7ae0\u8bf4\u8fc7&#xff0c;message_end \u4f1a\u89e6\u53d1\u5386\u53f2\u4fdd\u5b58&#xff0c;\u6240\u4ee5\u5de5\u5177\u7ed3\u679c\u4e5f\u8fdb\u4e86\u5386\u53f2\u3002\u6b64\u65f6\u5386\u53f2\u957f\u8fd9\u6837&#xff1a;<\/p>\n<p>user        \u8bf7\u7528 read \u8bfb\u53d6 note.txt\u3002<br \/>\nassistant   toolCall: read({ path: &#034;note.txt&#034; }), id &#061; call_1<br \/>\ntoolResult  \u672c\u6b21\u9a8c\u8bc1\u4ee3\u53f7&#xff1a;read-643219, toolCallId &#061; call_1<\/p>\n<p>\u770b\u8fd9\u6bb5\u5386\u53f2&#xff0c;\u50cf\u4e0d\u50cf\u4f20\u8bdd\u6e38\u620f&#xff1a;\u4f60\u95ee Agent&#xff0c;Agent \u95ee\u6a21\u578b&#xff0c;\u6a21\u578b\u95ee\u5de5\u5177&#xff0c;\u5de5\u5177\u628a\u7b54\u6848\u9012\u56de\u6765&#xff0c;\u6a21\u578b\u518d\u590d\u8ff0\u7ed9\u4f60\u3002\u4e2d\u95f4\u8c01\u90fd\u4e0d\u80fd\u6389\u94fe\u5b50&#xff0c;\u6389\u4e86\u5c31\u662f&#034;\u6211\u521a\u521a\u8bf4\u7684\u662f\u90a3\u4e2a\u2026\u2026\u8bf6&#xff0c;\u6211\u5fd8\u4e86\u6211\u521a\u8bf4\u5565\u4e86&#034;\u3002<\/p>\n<h4>3.5 \u5de5\u5177\u90fd\u5e72\u5b8c\u4e86&#xff0c;\u4e3a\u4ec0\u4e48\u8fd8\u8981\u518d\u95ee\u4e00\u6b21\u6a21\u578b<\/h4>\n<p>\u8fd9\u662f\u5f88\u591a\u4eba\u7b2c\u4e00\u6b21\u770b\u4f1a\u61f5\u7684\u5730\u65b9&#xff1a;\u5de5\u5177\u90fd\u6267\u884c\u5b8c\u4e86&#xff0c;\u7ed3\u679c\u4e5f\u62ff\u5230\u4e86&#xff0c;\u600e\u4e48\u53c8\u8bf7\u6c42\u4e86\u4e00\u6b21\u6a21\u578b&#xff1f;<\/p>\n<p>\u7b54\u6848\u5f88\u7b80\u5355&#xff1a;\u5de5\u5177\u53ea\u8d1f\u8d23\u67e5\u8d44\u6599&#xff0c;&#034;\u5199\u62a5\u544a&#034;\u7684\u662f\u6a21\u578b\u3002\u4f60\u8ba9\u540c\u4e8b\u5e2e\u4f60\u67e5\u4e2a\u6570\u636e&#xff0c;\u4ed6\u67e5\u5b8c\u56de\u6765&#xff0c;\u4f60\u4e0d\u8fd8\u5f97\u770b\u5b8c\u6570\u636e\u628a\u8bdd\u8bf4\u5b8c&#xff1f;\u603b\u4e0d\u80fd\u8ba9\u6570\u636e\u81ea\u5df1\u53d8\u6210\u4e00\u53e5\u8bdd\u5427\u2014\u2014\u5b83\u8981\u662f\u80fd&#xff0c;\u90a3\u6a21\u578b\u65e9\u5c31\u96c6\u4f53\u5931\u4e1a\u4e86\u3002<\/p>\n<p>\u5de5\u5177\u6267\u884c\u5b8c\u6210\u540e&#xff0c;runLoop() \u5148\u628a\u7ed3\u679c\u6d88\u606f\u8ffd\u52a0\u5230\u672c\u8f6e\u4e0a\u4e0b\u6587&#xff1a;<\/p>\n<p>toolResults<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&#8230;<\/span>executedToolBatch<span class=\"token punctuation\">.<\/span>messages<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> result <span class=\"token keyword\">of<\/span> toolResults<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\ncurrentContext<span class=\"token punctuation\">.<\/span>messages<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nnewMessages<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e0b\u9762\u7528\u4f2a\u4ee3\u7801\u4e32\u8d77\u5de5\u5177\u6b63\u5e38\u6267\u884c\u65f6\u7684\u5faa\u73af&#xff1a;<\/p>\n<p><span class=\"token keyword\">let<\/span> hasMoreToolCalls <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span>hasMoreToolCalls<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">const<\/span> message <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> <span class=\"token function\">streamAssistantResponse<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&#8230;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> toolCalls <span class=\"token operator\">&#061;<\/span> message<span class=\"token punctuation\">.<\/span>content<span class=\"token punctuation\">.<\/span><span class=\"token function\">filter<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>c<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> c<span class=\"token punctuation\">.<\/span>type <span class=\"token operator\">&#061;&#061;&#061;<\/span> <span class=\"token string\">&#034;toolCall&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nhasMoreToolCalls <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>toolCalls<span class=\"token punctuation\">.<\/span>length <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">const<\/span> executedToolBatch <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> <span class=\"token function\">executeToolCalls<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&#8230;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u5c06\u7ed3\u679c\u6d88\u606f\u8ffd\u52a0\u5230 currentContext.messages \u548c newMessages<\/span><br \/>\nhasMoreToolCalls <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5e26\u4e0a\u5de5\u5177\u7ed3\u679c&#xff0c;\u518d\u8bf7\u6c42\u4e00\u6b21\u6a21\u578b<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7b2c\u4e8c\u6b21\u8bf7\u6c42&#xff0c;\u6a21\u578b\u770b\u5230\u7684\u95ee\u9898\u3001\u8c03\u7528\u3001\u7ed3\u679c\u5168\u90fd\u9f50\u4e86&#xff0c;\u7ec8\u4e8e\u618b\u51fa\u6700\u7ec8\u7b54\u6848&#xff0c;\u5faa\u73af\u7ed3\u675f\u3002\u8981\u662f\u5b83\u8fd8\u60f3\u8981\u5de5\u5177&#xff0c;\u5c31\u7ee7\u7eed\u5faa\u73af\u2014\u2014\u8ddf\u901b\u8857\u7684\u4eba\u4e00\u6837&#xff0c;\u8bd5\u4e86\u4e00\u4ef6\u53c8\u4e00\u4ef6&#xff0c;\u4f60\u4e5f\u4e0d\u77e5\u9053\u5b83\u5565\u65f6\u5019\u6536\u624b\u3002<\/p>\n<p>\u4e00\u6b21 prompt() \u4e2d\u7684\u6d88\u606f\u53d8\u5316\u56e0\u6b64\u662f&#xff1a;<\/p>\n<table>\n<tr>\u65f6\u523b\u672c\u8f6e\u6d88\u606f\u5217\u8868\u63a5\u4e0b\u6765\u7684\u52a8\u4f5c<\/tr>\n<tbody>\n<tr>\n<td>\u7b2c\u4e00\u6b21\u8bf7\u6c42\u524d<\/td>\n<td>[\u7528\u6237\u95ee\u9898]<\/td>\n<td>\u6a21\u578b\u51b3\u5b9a\u8c03\u7528\u5de5\u5177<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c\u4e00\u6b21\u6a21\u578b\u56de\u590d\u5b8c\u6210<\/td>\n<td>[\u7528\u6237\u95ee\u9898, \u5de5\u5177\u8c03\u7528\u6d88\u606f]<\/td>\n<td>Agent \u6267\u884c\u5bf9\u5e94\u5de5\u5177<\/td>\n<\/tr>\n<tr>\n<td>\u5de5\u5177\u7ed3\u679c\u8ffd\u52a0\u540e<\/td>\n<td>[\u7528\u6237\u95ee\u9898, \u5de5\u5177\u8c03\u7528\u6d88\u606f, \u5de5\u5177\u7ed3\u679c]<\/td>\n<td>\u518d\u6b21\u8bf7\u6c42\u6a21\u578b<\/td>\n<\/tr>\n<tr>\n<td>\u6700\u7ec8\u56de\u590d\u5b8c\u6210<\/td>\n<td>[\u7528\u6237\u95ee\u9898, \u5de5\u5177\u8c03\u7528\u6d88\u606f, \u5de5\u5177\u7ed3\u679c, \u6587\u672c\u56de\u7b54]<\/td>\n<td>\u7ed3\u675f prompt()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u91cc\u518d\u6572\u4e00\u4e2a\u9ed1\u677f&#xff1a;\u4e00\u6761 assistant \u6d88\u606f\u7684 message_end&#xff0c;\u4e0d\u4ee3\u8868\u6574\u4e2a\u4efb\u52a1\u7ed3\u675f\u3002\u8981\u770b\u6700\u7ec8\u7b54\u6848&#xff0c;\u5f97\u7b49 await agent.prompt() \u5168\u90e8\u8dd1\u5b8c\u3002\u522b\u5728\u6a21\u578b\u8bf4\u7b2c\u4e00\u53e5\u8bdd\u7684\u65f6\u5019\u5c31\u51b2\u4e0a\u53bb\u8bfb\u7ed3\u679c\u2014\u2014\u90a3\u76f8\u5f53\u4e8e\u706b\u9505\u521a\u4e0b\u9505\u5c31\u95ee\u670d\u52a1\u5458&#034;\u719f\u4e86\u5417&#034;&#xff0c;\u670d\u52a1\u5458\u53ea\u80fd\u56de\u4f60\u4e00\u4e2a\u793c\u8c8c\u800c\u4e0d\u5931\u5c34\u5c2c\u7684\u5fae\u7b11\u3002<\/p>\n<h3>4. \u8dd1\u4e00\u628a Lab&#xff0c;\u9a8c\u8bc1\u5de5\u5177\u771f\u7684\u5728\u5e72\u6d3b<\/h3>\n<p>\u5b8c\u6574\u7a0b\u5e8f\u5728 labs\/08-tool-calling.ts\u3002\u88c5\u4f9d\u8d56\u3001\u8dd1\u8d77\u6765&#xff0c;\u5c31\u4e24\u884c&#xff1a;<\/p>\n<p><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span><br \/>\n<span class=\"token function\">node<\/span> labs\/08-tool-calling.ts<\/p>\n<p>\u5c31\u8fd9\u4e24\u884c&#xff0c;\u7a0b\u5e8f\u5458\u770b\u4e86 DNA \u90fd\u52a8\u4e86\u4e00\u4e0b\u3002Lab \u4f1a\u5728\u4e34\u65f6\u76ee\u5f55\u91cc\u5efa\u4e00\u4e2a note.txt&#xff0c;\u91cc\u9762\u5199\u4e00\u4e2a\u968f\u673a\u9a8c\u8bc1\u4ee3\u53f7&#xff0c;\u7136\u540e\u8ba9\u6a21\u578b\u53bb\u8bfb\u3002\u6a21\u578b\u4e0d\u8bfb\u6587\u4ef6\u5c31\u62ff\u4e0d\u5230\u4ee3\u53f7&#xff0c;\u4f5c\u5f0a\u90fd\u4f5c\u5f0a\u4e0d\u4e86\u2014\u2014\u8ddf\u5f00\u5377\u8003\u8bd5\u628a\u7b54\u6848\u9501\u4fdd\u9669\u67dc\u91cc\u4e00\u4e2a\u9053\u7406\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u6b21\u771f\u5b9e\u8c03\u7528\u7684\u8f93\u51fa&#xff0c;\u540e\u7eed\u8fd0\u884c\u7684\u4ee3\u53f7\u4f1a\u53d8\u5316&#xff1a;<\/p>\n<p>model: qwen3.8-flash<br \/>\ninput: \u8bf7\u7528 read \u8bfb\u53d6 note.txt&#xff0c;\u53ea\u56de\u590d\u5176\u4e2d\u7684\u9a8c\u8bc1\u4ee3\u53f7\u3002<br \/>\nrequest 1 roles: user<br \/>\nassistant stopReason: toolUse<br \/>\ntool_execution_start: read<br \/>\nread args: {&#034;path&#034;:&#034;note.txt&#034;}<br \/>\ntool_execution_end: read<br \/>\nread result: \u672c\u6b21\u9a8c\u8bc1\u4ee3\u53f7&#xff1a;read-643219<br \/>\nrequest 2 roles: user -&gt; assistant -&gt; toolResult<br \/>\nassistant stopReason: stop<br \/>\nfinal answer: read-643219<br \/>\nhistory roles: user -&gt; assistant -&gt; toolResult -&gt; assistant<br \/>\nchapter 8 native read tool passed<\/p>\n<p>\u8f93\u51fa\u91cc\u80fd\u770b\u5230\u5b8c\u6574\u7684\u4e00\u6761\u9f99&#xff1a;\u6a21\u578b\u7b2c\u4e00\u6b21\u8bf4 toolUse&#xff08;\u6211\u8981\u7528\u5de5\u5177&#xff09;&#xff0c;read \u6267\u884c\u5f00\u59cb\u3001\u7ed3\u675f&#xff0c;\u7136\u540e\u7b2c\u4e8c\u6b21\u8bf7\u6c42&#xff0c;\u6a21\u578b\u62ff\u5230\u7ed3\u679c\u7ed9\u51fa\u6700\u7ec8\u7b54\u6848 read-643219\u3002\u6574\u4e2a\u8fc7\u7a0b\u884c\u4e91\u6d41\u6c34&#xff0c;\u6bd4\u67d0\u4e9b\u540c\u4e8b\u7684\u5468\u62a5\u90fd\u5b8c\u6574\u3002<\/p>\n<p>Lab \u68c0\u67e5\u56db\u7ec4\u4e8b\u5b9e&#xff1a;<\/p>\n<li>\n<p>\u4e00\u6b21 prompt() \u6070\u597d\u53d1\u51fa\u4e24\u6b21\u6a21\u578b\u8bf7\u6c42&#xff0c;\u4e24\u6b21\u90fd\u643a\u5e26\u5de5\u5177\u8bf4\u660e&#xff1b;\u7b2c\u4e8c\u6b21\u8bf7\u6c42\u5305\u542b\u5b8c\u6574\u7684\u8c03\u7528\u6d88\u606f\u548c\u7ed3\u679c\u6d88\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ea\u51fa\u73b0\u4e00\u6b21 read \u6267\u884c\u7684\u5f00\u59cb\u4e0e\u7ed3\u675f\u4e8b\u4ef6&#xff0c;\u6a21\u578b\u8bf7\u6c42\u7684\u6587\u4ef6\u662f note.txt&#xff1b;\u7ed3\u679c\u6d88\u606f\u7684 toolCallId \u4e0e\u8c03\u7528 ID \u76f8\u540c&#xff0c;isError \u4e3a false&#xff0c;\u8fd4\u56de\u6587\u672c\u4e0e\u5199\u5165\u6587\u4ef6\u7684\u5185\u5bb9\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u5148\u4fdd\u5b58\u5de5\u5177\u8c03\u7528\u6d88\u606f&#xff0c;\u518d\u6267\u884c\u5de5\u5177\u3001\u4fdd\u5b58\u5de5\u5177\u7ed3\u679c&#xff0c;\u6700\u540e\u4fdd\u5b58\u56de\u7b54&#xff1b;\u5386\u53f2\u6070\u597d\u5305\u542b\u56db\u6761\u6d88\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>\u6700\u7ec8\u56de\u590d\u6b63\u5e38\u7ed3\u675f\u3001\u6ca1\u6709\u7ee7\u7eed\u8bf7\u6c42\u5de5\u5177&#xff0c;\u6587\u5b57\u7b49\u4e8e\u5de5\u5177\u8bfb\u51fa\u7684\u9a8c\u8bc1\u4ee3\u53f7\u3002<\/p>\n<\/li>\n<p>\u56db\u6761\u65ad\u8a00&#xff0c;\u6761\u6761\u90fd\u50cf\u73ed\u4e3b\u4efb\u62bd\u67e5\u4f5c\u4e1a\u2014\u2014\u800c\u4e14\u771f\u62bd\u67e5&#xff0c;\u4e0d\u662f\u8d70\u5f62\u5f0f\u3002\u62bd\u67e5\u5b8c\u8fd8\u544a\u8bc9\u4f60&#xff1a;\u4e24\u6b21\u8bf7\u6c42&#xff0c;\u4e00\u6b21\u4e0d\u591a\u4e00\u6b21\u4e0d\u5c11&#xff0c;\u6bd4\u4f60\u5bf9\u8c61\u7684\u593a\u547d\u8fde\u73af\u95ee\u8fd8\u7cbe\u786e\u3002<\/p>\n<p>\u770b\u5b8c\u6574\u4e2a\u8f93\u51fa\u4f60\u4f1a\u53d1\u73b0&#xff0c;\u6a21\u578b\u5168\u7a0b\u8868\u73b0\u5f97\u50cf\u4e2a\u4e56\u5b66\u751f&#xff1a;\u8001\u5e08\u8bf4\u8bfb\u6587\u4ef6&#xff0c;\u5b83\u5c31\u8c03\u7528 read&#xff1b;\u62ff\u5230\u7ed3\u679c&#xff0c;\u5c31\u8001\u8001\u5b9e\u5b9e\u590d\u8ff0\u3002\u8981\u662f\u73b0\u5b9e\u4e2d\u7684\u5b66\u751f\u90fd\u8fd9\u4e48\u597d\u5e26&#xff0c;\u8001\u5e08\u80fd\u591a\u6d3b\u5341\u5e74\u3002<\/p>\n<h3>5. \u5c0f\u7ed3<\/h3>\n<p>\u73b0\u5728&#xff0c;Agent \u4ece\u4e00\u6b21\u8f93\u5165\u5c31\u80fd\u4e00\u8def\u63a8\u7740\u5de5\u5177\u6267\u884c\u5f80\u4e0b\u8d70&#xff1a;\u7ed9\u6a21\u578b\u770b\u5de5\u5177\u7b80\u5386&#xff0c;\u6309\u540d\u5b57\u627e\u5230\u5de5\u5177&#xff0c;\u6821\u9a8c\u53c2\u6570&#xff0c;\u8c03 execute()&#xff0c;\u628a\u7ed3\u679c\u8d34\u56de\u539f\u8c03\u7528&#xff0c;\u518d\u8bf7\u6a21\u578b\u7ee7\u7eed\u5904\u7406\u3002<\/p>\n<p>\u6362\u6210\u4efb\u4f55\u7b26\u5408 AgentTool \u5951\u7ea6\u7684\u5de5\u5177&#xff0c;\u8d70\u7684\u90fd\u662f\u540c\u4e00\u5957\u6d41\u7a0b&#xff0c;\u53d8\u7684\u53ea\u662f\u5177\u4f53\u5e72\u6d3b\u7684\u51fd\u6570\u3002read \u53ea\u662f\u4e2a\u4f8b\u5b50\u2014\u2014\u4f60\u53ef\u4ee5\u6362\u6210\u67e5\u5929\u6c14\u3001\u7b97\u8d26\u3001\u53d1\u90ae\u4ef6&#xff0c;Agent \u90fd\u662f\u540c\u4e00\u526f\u59ff\u52bf&#xff1a;\u627e\u5230\u3001\u6821\u9a8c\u3001\u6267\u884c\u3001\u6c47\u62a5\u3002\u5de5\u5177\u6362\u4e86\u4e00\u4e2a\u53c8\u4e00\u4e2a&#xff0c;Agent \u7684\u59ff\u52bf\u4e00\u76f4\u6ca1\u53d8&#xff0c;\u50cf\u6781\u4e86\u4e00\u4e2a\u6210\u719f\u7684\u6253\u5de5\u4eba\u3002<\/p>\n<p>\u6700\u540e\u8bf4\u53e5\u638f\u5fc3\u7a9d\u7684&#xff1a;\u5de5\u5177\u8c03\u7528\u8fd9\u4e8b\u513f&#xff0c;\u8bf4\u767d\u4e86\u5c31\u662f\u7ed9\u4e00\u4e2a\u53ea\u4f1a\u8bf4\u8bdd\u7684\u6a21\u578b\u88c5\u4e86\u4e00\u53cc\u624b\u3002\u6a21\u578b\u8d1f\u8d23\u52a8\u5634&#xff0c;\u5de5\u5177\u8d1f\u8d23\u52a8\u624b&#xff0c;Agent \u8d1f\u8d23\u4e24\u5934\u4f20\u8bdd\u2014\u2014\u8fd8\u4e0d\u6536\u8dd1\u817f\u8d39\u3002\u8981\u662f\u6240\u6709\u4e2d\u95f4\u5c42\u90fd\u8fd9\u4e48\u4efb\u52b3\u4efb\u6028&#xff0c;\u8fd9\u4e2a\u4e16\u754c\u80fd\u5c11\u4e00\u534a\u7684\u626f\u76ae\u3002<\/p>\n<p>P.S. \u63a8\u8350\u4e00\u4e2a\u5927\u795e\u7684\u6559\u7a0b\u7ed9\u60f3\u8981\u4e86\u89e3\u6216\u8005\u5b66\u4e60\u4eba\u5de5\u667a\u80fd\u77e5\u8bc6\u7684\u8bfb\u8005&#xff0c;\u8fd9\u4e2a\u6559\u7a0b\u91cc\u5185\u5bb9\u8bb2\u89e3\u901a\u4fd7\u6613\u61c2\u4e14\u98ce\u8da3\u5e7d\u9ed8&#xff0c;\u5bf9\u6211\u5e2e\u52a9\u5f88\u5927\u3002\u6211\u60f3\u4e0e\u5927\u5bb6\u5206\u4eab\u8fd9\u4e2a\u5b9d\u85cf\u6559\u7a0b&#xff0c;\u8bf7\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u67e5\u770b&#xff0c;\u4f20\u9001\u95e8https:\/\/blog.csdn.net\/qq_74013365<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u76ee\u5f551. \u5148\u5206\u6e05\u56db\u4e2a\u89d2\u8272&#xff0c;\u522b\u628a\\&#8221;\u70b9\u83dc\\&#8221;\u5f53\u6210\\&#8221;\u4e0a\u83dc\\&#8221;1.1 \u5de5\u5177\u5b9a\u4e49 AgentTool&#xff1a;\u8d34\u5728\u95e8\u53e3\u7684\u83dc\u53551.2 \u8c03\u7528\u8bf7\u6c42 ToolCall&#xff1a;\u6a21\u578b\u7684\\&#8221;\u53e3\u5934\u627f\u8bfa\\&#8221;1.3 \u8fd4\u56de\u503c AgentToolResult&#xff1a;\u4ea4\u4e0a\u6765\u7684\u4f5c\u4e1a1.4 \u7ed3\u679c\u6d88\u606f ToolResultMessage&#xff1a;\u8d34\u4e0a\u59d3\u540d\u8d34\u7684\u4f5c\u4e1a2. \u628a\u5de5\u5177\u6ce8\u518c\u8fdb Agent&#xff1a;\u4ee5 read \u4e3a\u4f8b3. \u4ece\u5de5\u5177\u8bf4\u660e\u5230\u6267\u884c\u7ed3\u679c&#xff0c;\u518d\u56de\u5230\u6a21\u578b3.<\/p>\n","protected":false},"author":2,"featured_media":110096,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[50],"topic":[],"class_list":["post-110097","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-50"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Agent\u5de5\u5177\u8c03\u7528\u5b9e\u6218\uff1a\u7ed9\u5927\u6a21\u578b\u88c5\u4e0a\u80fd\u8bfb\u5199\u6587\u4ef6\u7684\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/110097.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Agent\u5de5\u5177\u8c03\u7528\u5b9e\u6218\uff1a\u7ed9\u5927\u6a21\u578b\u88c5\u4e0a\u80fd\u8bfb\u5199\u6587\u4ef6\u7684\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u76ee\u5f551. \u5148\u5206\u6e05\u56db\u4e2a\u89d2\u8272&#xff0c;\u522b\u628a&quot;\u70b9\u83dc&quot;\u5f53\u6210&quot;\u4e0a\u83dc&quot;1.1 \u5de5\u5177\u5b9a\u4e49 AgentTool&#xff1a;\u8d34\u5728\u95e8\u53e3\u7684\u83dc\u53551.2 \u8c03\u7528\u8bf7\u6c42 ToolCall&#xff1a;\u6a21\u578b\u7684&quot;\u53e3\u5934\u627f\u8bfa&quot;1.3 \u8fd4\u56de\u503c AgentToolResult&#xff1a;\u4ea4\u4e0a\u6765\u7684\u4f5c\u4e1a1.4 \u7ed3\u679c\u6d88\u606f ToolResultMessage&#xff1a;\u8d34\u4e0a\u59d3\u540d\u8d34\u7684\u4f5c\u4e1a2. \u628a\u5de5\u5177\u6ce8\u518c\u8fdb Agent&#xff1a;\u4ee5 read \u4e3a\u4f8b3. \u4ece\u5de5\u5177\u8bf4\u660e\u5230\u6267\u884c\u7ed3\u679c&#xff0c;\u518d\u56de\u5230\u6a21\u578b3.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/110097.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-25T14:41:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925144103-6ab687ff0d2bf.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110097.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/110097.html\",\"name\":\"Agent\u5de5\u5177\u8c03\u7528\u5b9e\u6218\uff1a\u7ed9\u5927\u6a21\u578b\u88c5\u4e0a\u80fd\u8bfb\u5199\u6587\u4ef6\u7684\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-25T14:41:05+00:00\",\"dateModified\":\"2026-09-25T14:41:05+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/110097.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/110097.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110097.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Agent\u5de5\u5177\u8c03\u7528\u5b9e\u6218\uff1a\u7ed9\u5927\u6a21\u578b\u88c5\u4e0a\u80fd\u8bfb\u5199\u6587\u4ef6\u7684\u624b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Agent\u5de5\u5177\u8c03\u7528\u5b9e\u6218\uff1a\u7ed9\u5927\u6a21\u578b\u88c5\u4e0a\u80fd\u8bfb\u5199\u6587\u4ef6\u7684\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/110097.html","og_locale":"zh_CN","og_type":"article","og_title":"Agent\u5de5\u5177\u8c03\u7528\u5b9e\u6218\uff1a\u7ed9\u5927\u6a21\u578b\u88c5\u4e0a\u80fd\u8bfb\u5199\u6587\u4ef6\u7684\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u76ee\u5f551. \u5148\u5206\u6e05\u56db\u4e2a\u89d2\u8272&#xff0c;\u522b\u628a\"\u70b9\u83dc\"\u5f53\u6210\"\u4e0a\u83dc\"1.1 \u5de5\u5177\u5b9a\u4e49 AgentTool&#xff1a;\u8d34\u5728\u95e8\u53e3\u7684\u83dc\u53551.2 \u8c03\u7528\u8bf7\u6c42 ToolCall&#xff1a;\u6a21\u578b\u7684\"\u53e3\u5934\u627f\u8bfa\"1.3 \u8fd4\u56de\u503c AgentToolResult&#xff1a;\u4ea4\u4e0a\u6765\u7684\u4f5c\u4e1a1.4 \u7ed3\u679c\u6d88\u606f ToolResultMessage&#xff1a;\u8d34\u4e0a\u59d3\u540d\u8d34\u7684\u4f5c\u4e1a2. \u628a\u5de5\u5177\u6ce8\u518c\u8fdb Agent&#xff1a;\u4ee5 read \u4e3a\u4f8b3. \u4ece\u5de5\u5177\u8bf4\u660e\u5230\u6267\u884c\u7ed3\u679c&#xff0c;\u518d\u56de\u5230\u6a21\u578b3.","og_url":"https:\/\/www.wsisp.com\/helps\/110097.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-25T14:41:05+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925144103-6ab687ff0d2bf.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/110097.html","url":"https:\/\/www.wsisp.com\/helps\/110097.html","name":"Agent\u5de5\u5177\u8c03\u7528\u5b9e\u6218\uff1a\u7ed9\u5927\u6a21\u578b\u88c5\u4e0a\u80fd\u8bfb\u5199\u6587\u4ef6\u7684\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-25T14:41:05+00:00","dateModified":"2026-09-25T14:41:05+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/110097.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/110097.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/110097.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Agent\u5de5\u5177\u8c03\u7528\u5b9e\u6218\uff1a\u7ed9\u5927\u6a21\u578b\u88c5\u4e0a\u80fd\u8bfb\u5199\u6587\u4ef6\u7684\u624b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=110097"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110097\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/110096"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=110097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=110097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=110097"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=110097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}