[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
Function Calling Deep Dive
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
- You define one or more functions in the
toolsarray. - The model reads the function names, descriptions, and parameter schemas.
- Based on the user's input, the model returns a
tool_callwith the function name and JSON arguments. - Your code executes the function locally and returns the result.
- 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.
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