Function Calling
Definition
A model capability that allows an AI to generate structured requests to invoke predefined functions — outputting a JSON object specifying the function name and arguments rather than freeform text. Function calling is the implementation mechanism underlying tool use: the developer provides a schema of available functions (name, description, parameter types, required fields), and the model decides when to call a function and with what arguments based on the conversation context. The model does not execute the function — it generates the call specification, which the host application uses to dispatch the actual function and return the result. Modern implementations support parallel function calls (multiple functions in a single turn), forced function use (require the model to use a specific function), and streaming responses.
Builder Context
Function calling is more deterministic than prompt-based tool invocation and should be your default approach for any structured action. Write function descriptions as if explaining to a smart junior engineer on their first day — specific, unambiguous, with clear parameter descriptions and example values. The quality of your function schema directly determines calling accuracy. Common mistakes: (1) vague function names ('process' vs 'send_email_to_customer'); (2) parameter descriptions that just restate the name; (3) not specifying valid enum values for constrained parameters; (4) combining multiple actions into one function. Function calling schemas should mirror REST API design principles: one resource, one action, predictable side effects.