[ ABORT TO HUD ]
SEQ. 1
SEQ. 2

Function Calling Deep Dive

⚙️ Function Calling & Structured Outputs 15 min 250 BASE XP

Making AI Take Action

Function calling is the mechanism that transforms an LLM from a text generator into an agent. You define functions with JSON Schema parameters, and the model decides when and how to call them.

How It Works

  1. You define one or more functions in the tools array.
  2. The model reads the function names, descriptions, and parameter schemas.
  3. Based on the user's input, the model returns a tool_call with the function name and JSON arguments.
  4. Your code executes the function locally and returns the result.
  5. The model uses the result to generate its final response.
const response = await openai.responses.create({
  model: "gpt-5.4",
  tools: [{
    type: "function",
    name: "get_stock_price",
    description: "Get the current stock price for a ticker symbol",
    parameters: {
      type: "object",
      properties: {
        symbol: { type: "string", description: "Stock ticker (e.g., AAPL)" },
        currency: { type: "string", enum: ["USD", "EUR", "GBP"] }
      },
      required: ["symbol"]
    }
  }],
  input: "What's Apple's stock price in euros?"
});

// Model returns: tool_call { name: "get_stock_price", arguments: { symbol: "AAPL", currency: "EUR" } }

Parallel Function Calls

The model can call multiple functions simultaneously when the queries are independent:

// User: "Compare AAPL and MSFT stock prices"
// Model returns TWO tool_calls in parallel:
// 1. get_stock_price({ symbol: "AAPL" })
// 2. get_stock_price({ symbol: "MSFT" })
💡 Pro Tip: Write detailed descriptions for every parameter. The model reads these to decide what values to pass. Poor descriptions = wrong arguments.
SYNAPSE VERIFICATION
QUERY 1 // 3
Does the model execute your functions directly?
Yes, it runs them on OpenAI's servers
No — it returns the function name and arguments; YOUR code executes them locally
Only for Python functions
Only with the Agents SDK
Watch: 139x Rust Speedup
Function Calling Deep Dive | Function Calling & Structured Outputs — OpenAI Academy