[ ABORT TO HUD ]
SEQ. 1
SEQ. 2

Function Calling Deep Dive

⚙️ Function Calling & Structured Outputs 15 min 250 BASE XP⌨ HANDS-ON LAB

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: "o3-mini",
  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.
⌨ HANDS-ON LABEnforce Strict Function Calling Schema
⭐ +200 XP

Guarantee 100% schema adherence with OpenAI's strict mode. Define get_stock_price with strict: true and required fields.

1POST to /v1/chat/completions with a function tool having strict: true and required parameters.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 1 — type "hint" if stuck
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