Zubnet AI學習Wiki › Function Calling
Using AI

Function Calling

Tool Calling, Tool Use API
AI 模型在對話中請求執行外部函數的結構化方式。你定義有名字、描述、參數 schema 的函數。當模型判定某個函數能幫回答一個請求時,它不輸出文字,而是輸出一個帶參數的結構化函數呼叫。你的程式執行這個函數,把結果返回給模型整合。

為什麼重要

Function calling 就是把聊天機器人變成 agent 的東西。沒有它,模型只能生成文字。有了它,模型能搜資料庫、呼叫 API、跑運算、訂預約、發信 — 任何你能暴露成函數的東西。這是每個真正做事而不只是說話的 AI 助手背後的機制。

Deep Dive

The API flow: (1) you send your prompt plus function definitions (JSON schemas describing each function's name, description, and parameters), (2) the model decides whether to call a function and which one, (3) it outputs a structured function call with specific arguments, (4) your code executes the function and returns the result, (5) the model incorporates the result into its response. Some models can call multiple functions in sequence or in parallel.

Function Calling vs. MCP

Function calling is the model-level primitive: the model outputs structured tool calls. MCP (Model Context Protocol) is a higher-level protocol that standardizes how tools are discovered, described, and connected. Think of function calling as the instruction set and MCP as the operating system — MCP uses function calling underneath but adds tool discovery, authentication, and standardization across providers.

Reliability

Function calling is more reliable than asking a model to output function calls as text (which requires parsing and is error-prone). Providers implement function calling by constraining the model's output to valid function calls matching your schema — similar to structured output. But the model can still choose wrong functions, hallucinate parameter values, or call functions when it shouldn't. Robust applications include validation, error handling, and human-in-the-loop confirmation for high-stakes operations.

相關概念

← 所有術語
← Foundation Model GAN →