[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"i-ri:search-line":3,"i-ri:moon-line":8,"i-ri:sun-line":10,"i-ri:menu-3-line":12,"i-ri:close-line":14,"notes-module-items-ai":16,"notes-page-ai-01-llm-basics\u002F03-function-calling":74,"i-ri:arrow-left-s-line":1166,"i-ri:menu-2-line":1168,"i-ri:arrow-right-s-line":1170,"i-ep:copy-document":1172},{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":7},0,24,false,"\u003Cpath fill=\"currentColor\" d=\"m18.031 16.617l4.283 4.282l-1.415 1.415l-4.282-4.283A8.96 8.96 0 0 1 11 20c-4.968 0-9-4.032-9-9s4.032-9 9-9s9 4.032 9 9a8.96 8.96 0 0 1-1.969 5.617m-2.006-.742A6.98 6.98 0 0 0 18 11c0-3.867-3.133-7-7-7s-7 3.133-7 7s3.133 7 7 7a6.98 6.98 0 0 0 4.875-1.975z\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":9},"\u003Cpath fill=\"currentColor\" d=\"M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12S6.477 2 12 2h.1A6.98 6.98 0 0 0 10 7m-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938A8 8 0 0 0 4 12\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":11},"\u003Cpath fill=\"currentColor\" d=\"M12 18a6 6 0 1 1 0-12a6 6 0 0 1 0 12m0-2a4 4 0 1 0 0-8a4 4 0 0 0 0 8M11 1h2v3h-2zm0 19h2v3h-2zM3.515 4.929l1.414-1.414L7.05 5.636L5.636 7.05zM16.95 18.364l1.414-1.414l2.121 2.121l-1.414 1.414zm2.121-14.85l1.414 1.415l-2.121 2.121l-1.414-1.414zM5.636 16.95l1.414 1.414l-2.121 2.121l-1.414-1.414zM23 11v2h-3v-2zM4 11v2H1v-2z\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":13},"\u003Cpath fill=\"currentColor\" d=\"M3 4h18v2H3zm6 7h12v2H9zm-6 7h18v2H3z\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":15},"\u003Cpath fill=\"currentColor\" d=\"m12 10.587l4.95-4.95l1.414 1.414l-4.95 4.95l4.95 4.95l-1.415 1.414l-4.95-4.95l-4.949 4.95l-1.414-1.415l4.95-4.95l-4.95-4.95L7.05 5.638z\"\u002F>",[17,22,26,30,34,38,42,46,50,54,58,62,66,70],{"path":18,"title":19,"meta":20},"\u002Fnotes\u002Fai\u002F01-llm-basics\u002F01-hello-llm","LLM 交互基础：透过现象看本质",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},"2026-11-05T09:47:15.000Z",{"path":23,"title":24,"meta":25},"\u002Fnotes\u002Fai\u002F01-llm-basics\u002F02-streaming-and-prompts","进阶交互：流式传输与提示词工程",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":27,"title":28,"meta":29},"\u002Fnotes\u002Fai\u002F01-llm-basics\u002F03-function-calling","结构化输出与 Function Calling",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":31,"title":32,"meta":33},"\u002Fnotes\u002Fai\u002F02-agent-architecture\u002F01-tool-use","Agent 核心能力 ①：Tool Use（工具调用）",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":35,"title":36,"meta":37},"\u002Fnotes\u002Fai\u002F02-agent-architecture\u002F02-mini-cursor-cli","实战项目：Mini Cursor（CLI 版）",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":39,"title":40,"meta":41},"\u002Fnotes\u002Fai\u002F02-agent-architecture\u002F03-memory","Agent 核心能力 ②：Memory（记忆管理）",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":43,"title":44,"meta":45},"\u002Fnotes\u002Fai\u002F02-agent-architecture\u002F04-planning","Agent 核心能力 ③：Planning（规划能力）",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":47,"title":48,"meta":49},"\u002Fnotes\u002Fai\u002F02-agent-architecture\u002F05-review-diff-chunking","代码改了很多，AI 为什么只审了前面？",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":51,"title":52,"meta":53},"\u002Fnotes\u002Fai\u002F02-agent-architecture","Agent 架构笔记",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":55,"title":56,"meta":57},"\u002Fnotes\u002Fai\u002F03-rag\u002F01-vector-db-and-embeddings-node","RAG ①：Embeddings 与向量数据库入门（Node.js 优先）",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":59,"title":60,"meta":61},"\u002Fnotes\u002Fai\u002F04-document-extraction\u002F01-ocr-field-evidence","OCR 读对了字，为什么地址仍然错？",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":63,"title":64,"meta":65},"\u002Fnotes\u002Fai\u002F05-development-workflow\u002F01-task-recovery","AI 任务做一半，中断后怎么继续？",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":67,"title":68,"meta":69},"\u002Fnotes\u002Fai","AI 应用开发",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"path":71,"title":72,"meta":73},"\u002Fnotes\u002Fai\u002Froadmap","AI Agent 全栈开发学习路线图 (Roadmap)",{"date":-1,"tags":-1,"summary":-1,"lastUpdated":21},{"id":75,"type":76,"sourcePath":77,"routePath":27,"path":27,"title":28,"updatedAt":21,"meta":78,"body":80,"toc":1154},"bm90ZTpub3Rlcy9haS8wMS1sbG0tYmFzaWNzLzAzLWZ1bmN0aW9uLWNhbGxpbmcubWQ","note","notes\u002Fai\u002F01-llm-basics\u002F03-function-calling.md",{"id":75,"type":76,"sourcePath":77,"slug":79,"title":28,"updatedAt":21,"lastUpdated":21},"ai\u002F01-llm-basics\u002F03-function-calling",{"type":81,"children":82},"root",[83,91,107,114,119,126,140,150,156,182,192,261,267,273,286,585,591,596,915,921,939,1090,1096,1101,1134,1138,1148],{"type":84,"tag":85,"props":86,"children":88},"element","h1",{"id":87},"结构化输出与-function-calling",[89],{"type":90,"value":28},"text",{"type":84,"tag":92,"props":93,"children":94},"blockquote",{},[95],{"type":84,"tag":96,"props":97,"children":98},"p",{},[99,105],{"type":84,"tag":100,"props":101,"children":102},"strong",{},[103],{"type":90,"value":104},"摘要",{"type":90,"value":106},"：这是 AI Agent 从“聊天机器人”进化为“智能助理”的关键一步。本章将讲解如何让 LLM 不再只会闲聊，而是能够精准地输出 JSON 数据，甚至主动请求执行代码函数。",{"type":84,"tag":108,"props":109,"children":111},"h2",{"id":110},"_1-结构化输出-structured-output",[112],{"type":90,"value":113},"1. 结构化输出 (Structured Output)",{"type":84,"tag":96,"props":115,"children":116},{},[117],{"type":90,"value":118},"默认情况下，LLM 输出的是非结构化的文本。但这对于程序来说是难以处理的。我们需要 JSON。",{"type":84,"tag":120,"props":121,"children":123},"h3",{"id":122},"_11-json-mode",[124],{"type":90,"value":125},"1.1 JSON Mode",{"type":84,"tag":96,"props":127,"children":128},{},[129,131,138],{"type":90,"value":130},"这是最简单的让模型输出 JSON 的方式。\n在请求中设置 ",{"type":84,"tag":132,"props":133,"children":135},"code",{"className":134},[],[136],{"type":90,"value":137},"response_format: { \"type\": \"json_object\" }",{"type":90,"value":139},"，并在 System Prompt 中明确要求“输出 JSON”。",{"type":84,"tag":96,"props":141,"children":142},{},[143,148],{"type":84,"tag":100,"props":144,"children":145},{},[146],{"type":90,"value":147},"适用场景",{"type":90,"value":149},"：数据提取、文本分类、生成配置文件。",{"type":84,"tag":120,"props":151,"children":153},{"id":152},"_12-function-calling-函数调用",[154],{"type":90,"value":155},"1.2 Function Calling (函数调用)",{"type":84,"tag":96,"props":157,"children":158},{},[159,161,166,168,173,175,180],{"type":90,"value":160},"JSON Mode 只是让输出格式变了，而 ",{"type":84,"tag":100,"props":162,"children":163},{},[164],{"type":90,"value":165},"Function Calling",{"type":90,"value":167}," 则是让模型具备了",{"type":84,"tag":100,"props":169,"children":170},{},[171],{"type":90,"value":172},"意图识别",{"type":90,"value":174},"和",{"type":84,"tag":100,"props":176,"children":177},{},[178],{"type":90,"value":179},"参数构造",{"type":90,"value":181},"的能力。",{"type":84,"tag":96,"props":183,"children":184},{},[185,190],{"type":84,"tag":100,"props":186,"children":187},{},[188],{"type":90,"value":189},"核心流程",{"type":90,"value":191},"：",{"type":84,"tag":193,"props":194,"children":195},"ol",{},[196,207,225,241,251],{"type":84,"tag":197,"props":198,"children":199},"li",{},[200,205],{"type":84,"tag":100,"props":201,"children":202},{},[203],{"type":90,"value":204},"定义工具",{"type":90,"value":206},"：你告诉模型：“我有这几个函数（工具），如果你需要用，就告诉我。”",{"type":84,"tag":197,"props":208,"children":209},{},[210,215,217,223],{"type":84,"tag":100,"props":211,"children":212},{},[213],{"type":90,"value":214},"模型决策",{"type":90,"value":216},"：模型根据用户的问题，判断是否需要调用工具。如果需要，它不返回文本，而是返回一个 ",{"type":84,"tag":132,"props":218,"children":220},{"className":219},[],[221],{"type":90,"value":222},"tool_calls",{"type":90,"value":224}," 对象，包含函数名和参数（JSON 格式）。",{"type":84,"tag":197,"props":226,"children":227},{},[228,233,234,239],{"type":84,"tag":100,"props":229,"children":230},{},[231],{"type":90,"value":232},"执行工具",{"type":90,"value":191},{"type":84,"tag":100,"props":235,"children":236},{},[237],{"type":90,"value":238},"你的代码",{"type":90,"value":240},"捕获到这个请求，执行真正的本地函数（如查询数据库、调用天气 API）。",{"type":84,"tag":197,"props":242,"children":243},{},[244,249],{"type":84,"tag":100,"props":245,"children":246},{},[247],{"type":90,"value":248},"回传结果",{"type":90,"value":250},"：你把函数执行的结果（Result）再次发给模型。",{"type":84,"tag":197,"props":252,"children":253},{},[254,259],{"type":84,"tag":100,"props":255,"children":256},{},[257],{"type":90,"value":258},"最终回答",{"type":90,"value":260},"：模型结合函数结果，生成给用户的最终自然语言回复。",{"type":84,"tag":108,"props":262,"children":264},{"id":263},"_2-协议详解",[265],{"type":90,"value":266},"2. 协议详解",{"type":84,"tag":120,"props":268,"children":270},{"id":269},"_21-定义-tools-schema",[271],{"type":90,"value":272},"2.1 定义 Tools Schema",{"type":84,"tag":96,"props":274,"children":275},{},[276,278,284],{"type":90,"value":277},"你需要在 API 请求中增加 ",{"type":84,"tag":132,"props":279,"children":281},{"className":280},[],[282],{"type":90,"value":283},"tools",{"type":90,"value":285}," 字段。每个 tool 都是一个函数描述。",{"type":84,"tag":287,"props":288,"children":293},"pre",{"className":289,"code":290,"language":291,"meta":292,"style":292},"language-json shiki shiki-themes github-light github-dark","\"tools\": [\n  {\n    \"type\": \"function\",\n    \"function\": {\n      \"name\": \"get_weather\",\n      \"description\": \"获取某个城市的当前天气\",\n      \"parameters\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"city\": {\n            \"type\": \"string\",\n            \"description\": \"城市名称，如 Beijing, Shanghai\"\n          }\n        },\n        \"required\": [\"city\"]\n      }\n    }\n  }\n]\n","json","",[294],{"type":84,"tag":132,"props":295,"children":296},{"__ignoreMap":292},[297,315,324,349,363,385,407,420,442,455,468,490,508,517,526,550,559,568,577],{"type":84,"tag":298,"props":299,"children":302},"span",{"class":300,"line":301},"line",1,[303,309],{"type":84,"tag":298,"props":304,"children":306},{"style":305},"--shiki-default:#032F62;--shiki-dark:#9ECBFF",[307],{"type":90,"value":308},"\"tools\"",{"type":84,"tag":298,"props":310,"children":312},{"style":311},"--shiki-default:#24292E;--shiki-dark:#E1E4E8",[313],{"type":90,"value":314},": [\n",{"type":84,"tag":298,"props":316,"children":318},{"class":300,"line":317},2,[319],{"type":84,"tag":298,"props":320,"children":321},{"style":311},[322],{"type":90,"value":323},"  {\n",{"type":84,"tag":298,"props":325,"children":327},{"class":300,"line":326},3,[328,334,339,344],{"type":84,"tag":298,"props":329,"children":331},{"style":330},"--shiki-default:#005CC5;--shiki-dark:#79B8FF",[332],{"type":90,"value":333},"    \"type\"",{"type":84,"tag":298,"props":335,"children":336},{"style":311},[337],{"type":90,"value":338},": ",{"type":84,"tag":298,"props":340,"children":341},{"style":305},[342],{"type":90,"value":343},"\"function\"",{"type":84,"tag":298,"props":345,"children":346},{"style":311},[347],{"type":90,"value":348},",\n",{"type":84,"tag":298,"props":350,"children":352},{"class":300,"line":351},4,[353,358],{"type":84,"tag":298,"props":354,"children":355},{"style":330},[356],{"type":90,"value":357},"    \"function\"",{"type":84,"tag":298,"props":359,"children":360},{"style":311},[361],{"type":90,"value":362},": {\n",{"type":84,"tag":298,"props":364,"children":366},{"class":300,"line":365},5,[367,372,376,381],{"type":84,"tag":298,"props":368,"children":369},{"style":330},[370],{"type":90,"value":371},"      \"name\"",{"type":84,"tag":298,"props":373,"children":374},{"style":311},[375],{"type":90,"value":338},{"type":84,"tag":298,"props":377,"children":378},{"style":305},[379],{"type":90,"value":380},"\"get_weather\"",{"type":84,"tag":298,"props":382,"children":383},{"style":311},[384],{"type":90,"value":348},{"type":84,"tag":298,"props":386,"children":388},{"class":300,"line":387},6,[389,394,398,403],{"type":84,"tag":298,"props":390,"children":391},{"style":330},[392],{"type":90,"value":393},"      \"description\"",{"type":84,"tag":298,"props":395,"children":396},{"style":311},[397],{"type":90,"value":338},{"type":84,"tag":298,"props":399,"children":400},{"style":305},[401],{"type":90,"value":402},"\"获取某个城市的当前天气\"",{"type":84,"tag":298,"props":404,"children":405},{"style":311},[406],{"type":90,"value":348},{"type":84,"tag":298,"props":408,"children":410},{"class":300,"line":409},7,[411,416],{"type":84,"tag":298,"props":412,"children":413},{"style":330},[414],{"type":90,"value":415},"      \"parameters\"",{"type":84,"tag":298,"props":417,"children":418},{"style":311},[419],{"type":90,"value":362},{"type":84,"tag":298,"props":421,"children":423},{"class":300,"line":422},8,[424,429,433,438],{"type":84,"tag":298,"props":425,"children":426},{"style":330},[427],{"type":90,"value":428},"        \"type\"",{"type":84,"tag":298,"props":430,"children":431},{"style":311},[432],{"type":90,"value":338},{"type":84,"tag":298,"props":434,"children":435},{"style":305},[436],{"type":90,"value":437},"\"object\"",{"type":84,"tag":298,"props":439,"children":440},{"style":311},[441],{"type":90,"value":348},{"type":84,"tag":298,"props":443,"children":445},{"class":300,"line":444},9,[446,451],{"type":84,"tag":298,"props":447,"children":448},{"style":330},[449],{"type":90,"value":450},"        \"properties\"",{"type":84,"tag":298,"props":452,"children":453},{"style":311},[454],{"type":90,"value":362},{"type":84,"tag":298,"props":456,"children":458},{"class":300,"line":457},10,[459,464],{"type":84,"tag":298,"props":460,"children":461},{"style":330},[462],{"type":90,"value":463},"          \"city\"",{"type":84,"tag":298,"props":465,"children":466},{"style":311},[467],{"type":90,"value":362},{"type":84,"tag":298,"props":469,"children":471},{"class":300,"line":470},11,[472,477,481,486],{"type":84,"tag":298,"props":473,"children":474},{"style":330},[475],{"type":90,"value":476},"            \"type\"",{"type":84,"tag":298,"props":478,"children":479},{"style":311},[480],{"type":90,"value":338},{"type":84,"tag":298,"props":482,"children":483},{"style":305},[484],{"type":90,"value":485},"\"string\"",{"type":84,"tag":298,"props":487,"children":488},{"style":311},[489],{"type":90,"value":348},{"type":84,"tag":298,"props":491,"children":493},{"class":300,"line":492},12,[494,499,503],{"type":84,"tag":298,"props":495,"children":496},{"style":330},[497],{"type":90,"value":498},"            \"description\"",{"type":84,"tag":298,"props":500,"children":501},{"style":311},[502],{"type":90,"value":338},{"type":84,"tag":298,"props":504,"children":505},{"style":305},[506],{"type":90,"value":507},"\"城市名称，如 Beijing, Shanghai\"\n",{"type":84,"tag":298,"props":509,"children":511},{"class":300,"line":510},13,[512],{"type":84,"tag":298,"props":513,"children":514},{"style":311},[515],{"type":90,"value":516},"          }\n",{"type":84,"tag":298,"props":518,"children":520},{"class":300,"line":519},14,[521],{"type":84,"tag":298,"props":522,"children":523},{"style":311},[524],{"type":90,"value":525},"        },\n",{"type":84,"tag":298,"props":527,"children":529},{"class":300,"line":528},15,[530,535,540,545],{"type":84,"tag":298,"props":531,"children":532},{"style":330},[533],{"type":90,"value":534},"        \"required\"",{"type":84,"tag":298,"props":536,"children":537},{"style":311},[538],{"type":90,"value":539},": [",{"type":84,"tag":298,"props":541,"children":542},{"style":305},[543],{"type":90,"value":544},"\"city\"",{"type":84,"tag":298,"props":546,"children":547},{"style":311},[548],{"type":90,"value":549},"]\n",{"type":84,"tag":298,"props":551,"children":553},{"class":300,"line":552},16,[554],{"type":84,"tag":298,"props":555,"children":556},{"style":311},[557],{"type":90,"value":558},"      }\n",{"type":84,"tag":298,"props":560,"children":562},{"class":300,"line":561},17,[563],{"type":84,"tag":298,"props":564,"children":565},{"style":311},[566],{"type":90,"value":567},"    }\n",{"type":84,"tag":298,"props":569,"children":571},{"class":300,"line":570},18,[572],{"type":84,"tag":298,"props":573,"children":574},{"style":311},[575],{"type":90,"value":576},"  }\n",{"type":84,"tag":298,"props":578,"children":580},{"class":300,"line":579},19,[581],{"type":84,"tag":298,"props":582,"children":583},{"style":311},[584],{"type":90,"value":549},{"type":84,"tag":120,"props":586,"children":588},{"id":587},"_22-处理-tool-calls",[589],{"type":90,"value":590},"2.2 处理 Tool Calls",{"type":84,"tag":96,"props":592,"children":593},{},[594],{"type":90,"value":595},"当模型决定调用工具时，返回的 JSON 结构如下：",{"type":84,"tag":287,"props":597,"children":599},{"className":289,"code":598,"language":291,"meta":292,"style":292},"{\n  \"choices\": [\n    {\n      \"message\": {\n        \"role\": \"assistant\",\n        \"content\": null, \u002F\u002F 注意这里内容为空\n        \"tool_calls\": [\n          {\n            \"id\": \"call_abc123\",\n            \"type\": \"function\",\n            \"function\": {\n              \"name\": \"get_weather\",\n              \"arguments\": \"{\\\"city\\\": \\\"Beijing\\\"}\" \u002F\u002F 模型生成的参数\n            }\n          }\n        ]\n      },\n      \"finish_reason\": \"tool_calls\"\n    }\n  ]\n}\n",[600],{"type":84,"tag":132,"props":601,"children":602},{"__ignoreMap":292},[603,611,623,631,643,664,692,704,712,733,752,764,784,842,850,857,865,873,890,897,906],{"type":84,"tag":298,"props":604,"children":605},{"class":300,"line":301},[606],{"type":84,"tag":298,"props":607,"children":608},{"style":311},[609],{"type":90,"value":610},"{\n",{"type":84,"tag":298,"props":612,"children":613},{"class":300,"line":317},[614,619],{"type":84,"tag":298,"props":615,"children":616},{"style":330},[617],{"type":90,"value":618},"  \"choices\"",{"type":84,"tag":298,"props":620,"children":621},{"style":311},[622],{"type":90,"value":314},{"type":84,"tag":298,"props":624,"children":625},{"class":300,"line":326},[626],{"type":84,"tag":298,"props":627,"children":628},{"style":311},[629],{"type":90,"value":630},"    {\n",{"type":84,"tag":298,"props":632,"children":633},{"class":300,"line":351},[634,639],{"type":84,"tag":298,"props":635,"children":636},{"style":330},[637],{"type":90,"value":638},"      \"message\"",{"type":84,"tag":298,"props":640,"children":641},{"style":311},[642],{"type":90,"value":362},{"type":84,"tag":298,"props":644,"children":645},{"class":300,"line":365},[646,651,655,660],{"type":84,"tag":298,"props":647,"children":648},{"style":330},[649],{"type":90,"value":650},"        \"role\"",{"type":84,"tag":298,"props":652,"children":653},{"style":311},[654],{"type":90,"value":338},{"type":84,"tag":298,"props":656,"children":657},{"style":305},[658],{"type":90,"value":659},"\"assistant\"",{"type":84,"tag":298,"props":661,"children":662},{"style":311},[663],{"type":90,"value":348},{"type":84,"tag":298,"props":665,"children":666},{"class":300,"line":387},[667,672,676,681,686],{"type":84,"tag":298,"props":668,"children":669},{"style":330},[670],{"type":90,"value":671},"        \"content\"",{"type":84,"tag":298,"props":673,"children":674},{"style":311},[675],{"type":90,"value":338},{"type":84,"tag":298,"props":677,"children":678},{"style":330},[679],{"type":90,"value":680},"null",{"type":84,"tag":298,"props":682,"children":683},{"style":311},[684],{"type":90,"value":685},", ",{"type":84,"tag":298,"props":687,"children":689},{"style":688},"--shiki-default:#6A737D;--shiki-dark:#6A737D",[690],{"type":90,"value":691},"\u002F\u002F 注意这里内容为空\n",{"type":84,"tag":298,"props":693,"children":694},{"class":300,"line":409},[695,700],{"type":84,"tag":298,"props":696,"children":697},{"style":330},[698],{"type":90,"value":699},"        \"tool_calls\"",{"type":84,"tag":298,"props":701,"children":702},{"style":311},[703],{"type":90,"value":314},{"type":84,"tag":298,"props":705,"children":706},{"class":300,"line":422},[707],{"type":84,"tag":298,"props":708,"children":709},{"style":311},[710],{"type":90,"value":711},"          {\n",{"type":84,"tag":298,"props":713,"children":714},{"class":300,"line":444},[715,720,724,729],{"type":84,"tag":298,"props":716,"children":717},{"style":330},[718],{"type":90,"value":719},"            \"id\"",{"type":84,"tag":298,"props":721,"children":722},{"style":311},[723],{"type":90,"value":338},{"type":84,"tag":298,"props":725,"children":726},{"style":305},[727],{"type":90,"value":728},"\"call_abc123\"",{"type":84,"tag":298,"props":730,"children":731},{"style":311},[732],{"type":90,"value":348},{"type":84,"tag":298,"props":734,"children":735},{"class":300,"line":457},[736,740,744,748],{"type":84,"tag":298,"props":737,"children":738},{"style":330},[739],{"type":90,"value":476},{"type":84,"tag":298,"props":741,"children":742},{"style":311},[743],{"type":90,"value":338},{"type":84,"tag":298,"props":745,"children":746},{"style":305},[747],{"type":90,"value":343},{"type":84,"tag":298,"props":749,"children":750},{"style":311},[751],{"type":90,"value":348},{"type":84,"tag":298,"props":753,"children":754},{"class":300,"line":470},[755,760],{"type":84,"tag":298,"props":756,"children":757},{"style":330},[758],{"type":90,"value":759},"            \"function\"",{"type":84,"tag":298,"props":761,"children":762},{"style":311},[763],{"type":90,"value":362},{"type":84,"tag":298,"props":765,"children":766},{"class":300,"line":492},[767,772,776,780],{"type":84,"tag":298,"props":768,"children":769},{"style":330},[770],{"type":90,"value":771},"              \"name\"",{"type":84,"tag":298,"props":773,"children":774},{"style":311},[775],{"type":90,"value":338},{"type":84,"tag":298,"props":777,"children":778},{"style":305},[779],{"type":90,"value":380},{"type":84,"tag":298,"props":781,"children":782},{"style":311},[783],{"type":90,"value":348},{"type":84,"tag":298,"props":785,"children":786},{"class":300,"line":510},[787,792,796,801,806,811,815,819,823,828,832,837],{"type":84,"tag":298,"props":788,"children":789},{"style":330},[790],{"type":90,"value":791},"              \"arguments\"",{"type":84,"tag":298,"props":793,"children":794},{"style":311},[795],{"type":90,"value":338},{"type":84,"tag":298,"props":797,"children":798},{"style":305},[799],{"type":90,"value":800},"\"{",{"type":84,"tag":298,"props":802,"children":803},{"style":330},[804],{"type":90,"value":805},"\\\"",{"type":84,"tag":298,"props":807,"children":808},{"style":305},[809],{"type":90,"value":810},"city",{"type":84,"tag":298,"props":812,"children":813},{"style":330},[814],{"type":90,"value":805},{"type":84,"tag":298,"props":816,"children":817},{"style":305},[818],{"type":90,"value":338},{"type":84,"tag":298,"props":820,"children":821},{"style":330},[822],{"type":90,"value":805},{"type":84,"tag":298,"props":824,"children":825},{"style":305},[826],{"type":90,"value":827},"Beijing",{"type":84,"tag":298,"props":829,"children":830},{"style":330},[831],{"type":90,"value":805},{"type":84,"tag":298,"props":833,"children":834},{"style":305},[835],{"type":90,"value":836},"}\"",{"type":84,"tag":298,"props":838,"children":839},{"style":688},[840],{"type":90,"value":841}," \u002F\u002F 模型生成的参数\n",{"type":84,"tag":298,"props":843,"children":844},{"class":300,"line":519},[845],{"type":84,"tag":298,"props":846,"children":847},{"style":311},[848],{"type":90,"value":849},"            }\n",{"type":84,"tag":298,"props":851,"children":852},{"class":300,"line":528},[853],{"type":84,"tag":298,"props":854,"children":855},{"style":311},[856],{"type":90,"value":516},{"type":84,"tag":298,"props":858,"children":859},{"class":300,"line":552},[860],{"type":84,"tag":298,"props":861,"children":862},{"style":311},[863],{"type":90,"value":864},"        ]\n",{"type":84,"tag":298,"props":866,"children":867},{"class":300,"line":561},[868],{"type":84,"tag":298,"props":869,"children":870},{"style":311},[871],{"type":90,"value":872},"      },\n",{"type":84,"tag":298,"props":874,"children":875},{"class":300,"line":570},[876,881,885],{"type":84,"tag":298,"props":877,"children":878},{"style":330},[879],{"type":90,"value":880},"      \"finish_reason\"",{"type":84,"tag":298,"props":882,"children":883},{"style":311},[884],{"type":90,"value":338},{"type":84,"tag":298,"props":886,"children":887},{"style":305},[888],{"type":90,"value":889},"\"tool_calls\"\n",{"type":84,"tag":298,"props":891,"children":892},{"class":300,"line":579},[893],{"type":84,"tag":298,"props":894,"children":895},{"style":311},[896],{"type":90,"value":567},{"type":84,"tag":298,"props":898,"children":900},{"class":300,"line":899},20,[901],{"type":84,"tag":298,"props":902,"children":903},{"style":311},[904],{"type":90,"value":905},"  ]\n",{"type":84,"tag":298,"props":907,"children":909},{"class":300,"line":908},21,[910],{"type":84,"tag":298,"props":911,"children":912},{"style":311},[913],{"type":90,"value":914},"}\n",{"type":84,"tag":120,"props":916,"children":918},{"id":917},"_23-提交-tool-outputs",[919],{"type":90,"value":920},"2.3 提交 Tool Outputs",{"type":84,"tag":96,"props":922,"children":923},{},[924,926,937],{"type":90,"value":925},"执行完函数后，你需要构造一个新的 message 发回给模型。",{"type":84,"tag":100,"props":927,"children":928},{},[929,931],{"type":90,"value":930},"注意：必须带上 ",{"type":84,"tag":132,"props":932,"children":934},{"className":933},[],[935],{"type":90,"value":936},"tool_call_id",{"type":90,"value":938},"，这样模型才知道这个结果对应哪次调用。",{"type":84,"tag":287,"props":940,"children":942},{"className":289,"code":941,"language":291,"meta":292,"style":292},"{\n  \"role\": \"tool\",\n  \"tool_call_id\": \"call_abc123\",\n  \"name\": \"get_weather\",\n  \"content\": \"{\\\"temperature\\\": 22, \\\"condition\\\": \\\"Sunny\\\"}\"\n}\n",[943],{"type":84,"tag":132,"props":944,"children":945},{"__ignoreMap":292},[946,953,974,994,1014,1083],{"type":84,"tag":298,"props":947,"children":948},{"class":300,"line":301},[949],{"type":84,"tag":298,"props":950,"children":951},{"style":311},[952],{"type":90,"value":610},{"type":84,"tag":298,"props":954,"children":955},{"class":300,"line":317},[956,961,965,970],{"type":84,"tag":298,"props":957,"children":958},{"style":330},[959],{"type":90,"value":960},"  \"role\"",{"type":84,"tag":298,"props":962,"children":963},{"style":311},[964],{"type":90,"value":338},{"type":84,"tag":298,"props":966,"children":967},{"style":305},[968],{"type":90,"value":969},"\"tool\"",{"type":84,"tag":298,"props":971,"children":972},{"style":311},[973],{"type":90,"value":348},{"type":84,"tag":298,"props":975,"children":976},{"class":300,"line":326},[977,982,986,990],{"type":84,"tag":298,"props":978,"children":979},{"style":330},[980],{"type":90,"value":981},"  \"tool_call_id\"",{"type":84,"tag":298,"props":983,"children":984},{"style":311},[985],{"type":90,"value":338},{"type":84,"tag":298,"props":987,"children":988},{"style":305},[989],{"type":90,"value":728},{"type":84,"tag":298,"props":991,"children":992},{"style":311},[993],{"type":90,"value":348},{"type":84,"tag":298,"props":995,"children":996},{"class":300,"line":351},[997,1002,1006,1010],{"type":84,"tag":298,"props":998,"children":999},{"style":330},[1000],{"type":90,"value":1001},"  \"name\"",{"type":84,"tag":298,"props":1003,"children":1004},{"style":311},[1005],{"type":90,"value":338},{"type":84,"tag":298,"props":1007,"children":1008},{"style":305},[1009],{"type":90,"value":380},{"type":84,"tag":298,"props":1011,"children":1012},{"style":311},[1013],{"type":90,"value":348},{"type":84,"tag":298,"props":1015,"children":1016},{"class":300,"line":365},[1017,1022,1026,1030,1034,1039,1043,1048,1052,1057,1061,1065,1069,1074,1078],{"type":84,"tag":298,"props":1018,"children":1019},{"style":330},[1020],{"type":90,"value":1021},"  \"content\"",{"type":84,"tag":298,"props":1023,"children":1024},{"style":311},[1025],{"type":90,"value":338},{"type":84,"tag":298,"props":1027,"children":1028},{"style":305},[1029],{"type":90,"value":800},{"type":84,"tag":298,"props":1031,"children":1032},{"style":330},[1033],{"type":90,"value":805},{"type":84,"tag":298,"props":1035,"children":1036},{"style":305},[1037],{"type":90,"value":1038},"temperature",{"type":84,"tag":298,"props":1040,"children":1041},{"style":330},[1042],{"type":90,"value":805},{"type":84,"tag":298,"props":1044,"children":1045},{"style":305},[1046],{"type":90,"value":1047},": 22, ",{"type":84,"tag":298,"props":1049,"children":1050},{"style":330},[1051],{"type":90,"value":805},{"type":84,"tag":298,"props":1053,"children":1054},{"style":305},[1055],{"type":90,"value":1056},"condition",{"type":84,"tag":298,"props":1058,"children":1059},{"style":330},[1060],{"type":90,"value":805},{"type":84,"tag":298,"props":1062,"children":1063},{"style":305},[1064],{"type":90,"value":338},{"type":84,"tag":298,"props":1066,"children":1067},{"style":330},[1068],{"type":90,"value":805},{"type":84,"tag":298,"props":1070,"children":1071},{"style":305},[1072],{"type":90,"value":1073},"Sunny",{"type":84,"tag":298,"props":1075,"children":1076},{"style":330},[1077],{"type":90,"value":805},{"type":84,"tag":298,"props":1079,"children":1080},{"style":305},[1081],{"type":90,"value":1082},"}\"\n",{"type":84,"tag":298,"props":1084,"children":1085},{"class":300,"line":387},[1086],{"type":84,"tag":298,"props":1087,"children":1088},{"style":311},[1089],{"type":90,"value":914},{"type":84,"tag":108,"props":1091,"children":1093},{"id":1092},"_3-为什么不直接用正则提取参数",[1094],{"type":90,"value":1095},"3. 为什么不直接用正则提取参数？",{"type":84,"tag":96,"props":1097,"children":1098},{},[1099],{"type":90,"value":1100},"早期的开发者确实是用正则去匹配用户输入（例如匹配 \"查询天气\"），但这非常脆弱。Function Calling 的优势在于：",{"type":84,"tag":193,"props":1102,"children":1103},{},[1104,1114,1124],{"type":84,"tag":197,"props":1105,"children":1106},{},[1107,1112],{"type":84,"tag":100,"props":1108,"children":1109},{},[1110],{"type":90,"value":1111},"语义理解",{"type":90,"value":1113},"：模型能理解复杂的自然语言意图（例如“帮我看看那个有鸟巢的城市今天下雨吗” -> 提取出 Beijing）。",{"type":84,"tag":197,"props":1115,"children":1116},{},[1117,1122],{"type":84,"tag":100,"props":1118,"children":1119},{},[1120],{"type":90,"value":1121},"鲁棒性",{"type":90,"value":1123},"：模型经过专门训练，生成的 JSON 参数非常稳定，甚至能自动纠正拼写错误。",{"type":84,"tag":197,"props":1125,"children":1126},{},[1127,1132],{"type":84,"tag":100,"props":1128,"children":1129},{},[1130],{"type":90,"value":1131},"多步推理",{"type":90,"value":1133},"：模型可以一次性决定调用多个工具，或者根据前一个工具的结果决定下一步操作（Agent 雏形）。",{"type":84,"tag":1135,"props":1136,"children":1137},"hr",{},[],{"type":84,"tag":96,"props":1139,"children":1140},{},[1141,1146],{"type":84,"tag":100,"props":1142,"children":1143},{},[1144],{"type":90,"value":1145},"下一步",{"type":90,"value":1147},"：我们将编写一段代码，亲手实现这个“模型 -> 代码 -> 模型”的闭环。",{"type":84,"tag":1149,"props":1150,"children":1151},"style",{},[1152],{"type":90,"value":1153},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":292,"searchDepth":317,"depth":317,"links":1155},[1156,1160,1165],{"id":110,"depth":317,"text":113,"children":1157},[1158,1159],{"id":122,"depth":326,"text":125},{"id":152,"depth":326,"text":155},{"id":263,"depth":317,"text":266,"children":1161},[1162,1163,1164],{"id":269,"depth":326,"text":272},{"id":587,"depth":326,"text":590},{"id":917,"depth":326,"text":920},{"id":1092,"depth":317,"text":1095},{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":1167},"\u003Cpath fill=\"currentColor\" d=\"m10.828 12l4.95 4.95l-1.414 1.415L8 12l6.364-6.364l1.414 1.414z\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":1169},"\u003Cpath fill=\"currentColor\" d=\"M3 4h18v2H3zm0 7h12v2H3zm0 7h18v2H3z\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":1171},"\u003Cpath fill=\"currentColor\" d=\"m13.172 12l-4.95-4.95l1.414-1.413L16 12l-6.364 6.364l-1.414-1.415z\"\u002F>",{"left":4,"top":4,"width":1173,"height":1173,"rotate":4,"vFlip":6,"hFlip":6,"body":1174},1024,"\u003Cpath fill=\"currentColor\" d=\"M768 832a128 128 0 0 1-128 128H192A128 128 0 0 1 64 832V384a128 128 0 0 1 128-128v64a64 64 0 0 0-64 64v448a64 64 0 0 0 64 64h448a64 64 0 0 0 64-64z\"\u002F>\u003Cpath fill=\"currentColor\" d=\"M384 128a64 64 0 0 0-64 64v448a64 64 0 0 0 64 64h448a64 64 0 0 0 64-64V192a64 64 0 0 0-64-64zm0-64h448a128 128 0 0 1 128 128v448a128 128 0 0 1-128 128H384a128 128 0 0 1-128-128V192A128 128 0 0 1 384 64\"\u002F>"]