AgentEngineering
GlossaryCore Concepts

Function Calling

A native model capability — first popularized by OpenAI — that allows an LLM to emit structured, schema-validated requests to invoke developer-defined functions, replacing ad-hoc text parsing with reliable tool invocation.

Definition

Function calling is a first-class feature of modern LLM APIs that allows developers to declare a set of callable functions as JSON schemas. During generation, the model can emit a structured tool_call object specifying which function to invoke and with what arguments — instead of (or alongside) free-form text.

This approach replaced earlier, brittle patterns where developers prompted the model to output JSON and then parsed that text manually. With native function calling, the schema is enforced at the API level.

How It Works

  1. Declare — The developer provides one or more tool schemas in the API request:
    {
      "name": "get_weather",
      "description": "Get current weather for a city.",
      "parameters": {
        "type": "object",
        "properties": {
          "city": { "type": "string" }
        },
        "required": ["city"]
      }
    }
    
  2. Invoke — The model decides to call the function and emits a tool_call in its response.
  3. Execute — The calling application runs the actual function and captures the return value.
  4. Return — The result is sent back to the model as a tool message, and the model continues generating.

Parallel Function Calling

Modern APIs (GPT-4o, Claude 3.5+) support parallel function calling: the model emits multiple tool calls in a single response turn, and the application executes them concurrently before returning all results in one batch. This is a significant performance optimization for tasks with independent sub-queries.

Function Calling vs. Tool Use

The terms are often used interchangeably. Strictly speaking, "function calling" refers to the specific API mechanism; "tool use" is the broader capability concept that includes function calling as well as code execution, web browsing, and other modalities. This site uses both terms.

Reliability Considerations

  • Always validate model-emitted arguments against the declared schema before execution.
  • Treat function call arguments as untrusted input — they are model-generated and can be incorrect or manipulated via prompt injection.
  • Use descriptive description fields; the quality of tool selection and argument generation is strongly correlated with schema clarity.
ShareY