{"id":24,"date":"2026-11-08T13:15:59","date_gmt":"2026-11-08T13:15:59","guid":{"rendered":"http:\/\/blog.antpython.net\/?p=24"},"modified":"2026-11-08T13:15:59","modified_gmt":"2026-11-08T13:15:59","slug":"agent-%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9a%e5%b7%a5%e5%85%b7%e8%b0%83%e7%94%a8%ef%bc%88function-calling%ef%bc%89%e5%b7%a5%e4%bd%9c%e6%b5%81%e6%8b%86%e8%a7%a3","status":"publish","type":"post","link":"http:\/\/blog.antpython.net\/?p=24","title":{"rendered":"Agent \u662f\u4ec0\u4e48\uff1a\u5de5\u5177\u8c03\u7528\uff08Function Calling\uff09\u5de5\u4f5c\u6d41\u62c6\u89e3"},"content":{"rendered":"<p>Chatbot \u53ea\u4f1a\u804a\u5929\uff1bAgent \u8fd8\u80fd<strong>\u51b3\u5b9a\u8c03\u7528\u5de5\u5177<\/strong>\uff1a\u67e5\u5e93\u3001\u641c\u6587\u6863\u3001\u7b97\u6570\u3001\u8c03 API\u3002\u7406\u89e3 Function Calling\uff0c\u662f\u8fdb\u5165 Agent \u5f00\u53d1\u7684\u7b2c\u4e00\u6247\u95e8\u3002<\/p>\n<h2>\u4e00\u6b21\u5178\u578b\u5faa\u73af<\/h2>\n<ol>\n<li>\u7528\u6237\u63d0\u51fa\u76ee\u6807<\/li>\n<li>\u6a21\u578b\u9009\u62e9\uff1a\u76f4\u63a5\u56de\u7b54 or \u8c03\u7528\u67d0\u4e2a\u5de5\u5177<\/li>\n<li>\u7a0b\u5e8f\u6267\u884c\u5de5\u5177\uff0c\u628a\u7ed3\u679c\u56de\u586b<\/li>\n<li>\u6a21\u578b\u57fa\u4e8e\u5de5\u5177\u7ed3\u679c\u7ee7\u7eed\u63a8\u7406\uff0c\u76f4\u5230\u7ed9\u51fa\u6700\u7ec8\u7b54\u6848<\/li>\n<\/ol>\n<h2>\u5de5\u5177\u63cf\u8ff0\u793a\u4f8b<\/h2>\n<pre><code>tools = [{\n  \"type\": \"function\",\n  \"function\": {\n    \"name\": \"get_order\",\n    \"description\": \"\u6839\u636e\u8ba2\u5355\u53f7\u67e5\u8be2\u8ba2\u5355\u72b6\u6001\u4e0e\u91d1\u989d\",\n    \"parameters\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"order_id\": {\"type\": \"string\", \"description\": \"\u8ba2\u5355\u53f7\"}\n      },\n      \"required\": [\"order_id\"]\n    }\n  }\n}]\n<\/code><\/pre>\n<h2>\u4f2a\u4ee3\u7801\u4e3b\u5faa\u73af<\/h2>\n<pre><code>messages = [{\"role\": \"user\", \"content\": \"\u5e2e\u6211\u67e5\u8ba2\u5355 A10086 \u5230\u54ea\u4e86\"}]\nwhile True:\n    resp = llm.chat(messages, tools=tools)\n    if resp.tool_calls:\n        for call in resp.tool_calls:\n            result = run_tool(call.name, call.arguments)\n            messages.append({\"role\": \"tool\", \"tool_call_id\": call.id, \"content\": result})\n        continue\n    return resp.content\n<\/code><\/pre>\n<h2>\u8bbe\u8ba1\u539f\u5219<\/h2>\n<ul>\n<li>\u5de5\u5177\u8981\u5c11\u800c\u7cbe\uff0c\u63cf\u8ff0\u5199\u6e05\u695a\u300c\u4f55\u65f6\u7528\u300d<\/li>\n<li>\u53c2\u6570 schema \u4e25\u683c\uff0c\u51cf\u5c11\u80e1\u7f16\u53c2\u6570<\/li>\n<li>\u5de5\u5177\u6267\u884c\u5fc5\u987b\u9274\u6743\u4e0e\u5ba1\u8ba1<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Chatbot \u53ea\u4f1a\u804a\u5929\uff1bAgent \u8fd8\u80fd\u51b3\u5b9a\u8c03\u7528\u5de5\u5177\uff1a\u67e5\u5e93\u3001\u641c\u6587\u6863\u3001\u7b97\u6570\u3001\u8c03 API\u3002\u7406\u89e3 Function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-agent-dev"],"_links":{"self":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24"}],"version-history":[{"count":0,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/24\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}