How to Configure Function Calling with the o3 and o4-mini Models
To enable function calling with OpenAI's o3-mini and o4-mini models, set the model identifier to "o3-mini" or "o4-mini", register your function schemas, and specify tool_choice="required" to force function usage or tool_choice="auto" to let the model decide.
The OpenAI o3-mini and o4-mini models support the same structured tool-use interface as the GPT-4o family, enabling complex agentic workflows through function calling. According to the openai/openai-cookbook repository, you configure these models using either the raw OpenAI SDK or the higher-level Agents SDK, both of which require explicit model selection and tool choice configuration.
Setting Model Name and Tool Choice
You activate function calling by combining the correct model identifier with a tool_choice directive. This applies whether you use the raw REST API, the Python SDK, or the Agents SDK wrapper.
Using ModelSettings in the Agents SDK
The cookbook demonstrates this pattern in examples/mcp/building-a-supply-chain-copilot-with-agent-sdk-and-databricks-mcp/main.py. The ModelSettings helper bundles the model name and tool behavior:
from agents import ModelSettings
model_settings = ModelSettings(
model="o3-mini", # ← Swap to "o4-mini" for the newer model
tool_choice="required", # ← Forces the model to call a function when one matches
)
Key parameters:
- model: Use
"o3-mini"or"o4-mini"(as seen inexamples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/pm.pyat line 64, where#model="o4-mini"shows the placeholder). - tool_choice: Set to
"required"to mandate function calls, or"auto"to let the model decide based on context.
Raw SDK Implementation
When using the raw OpenAI Python SDK, pass these values directly to the chat completion method:
import openai
response = openai.chat.completions.create(
model="o3-mini", # or "o4-mini"
messages=[{"role": "user", "content": "Analyze this data"}],
tools=function_schemas,
tool_choice="required", # or "auto"
)
Registering Function Definitions
Before the model can call a function, you must register the JSON schema definitions. In examples/object_oriented_agentic_approach/resources/registry/tools/python_code_interpreter_tool.py, the repository defines the schema that the model sees:
{
"name": "execute_python_code",
"description": "Execute Python code in a sandboxed environment",
"parameters": {
"type": "object",
"properties": {
"code": {"type": "string", "description": "Python code to execute"}
},
"required": ["code"]
}
}
When using the Agents SDK, the function_tool helper converts Python functions into this schema automatically.
Complete Implementation Examples
Minimal ChatCompletion with o3-mini
This example shows the raw SDK configuration targeting o3-mini with forced function calling:
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
functions = [
{
"name": "get_current_weather",
"description": "Retrieve the current weather for a location.",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City and country, e.g. 'Paris, FR'"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
}
]
response = openai.ChatCompletion.create(
model="o3-mini",
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
tools=functions,
tool_choice="required",
)
print(response.choices[0].message)
Agents SDK Agent with o4-mini
This pattern uses the Agent class with explicit ModelSettings to configure o4-mini:
from agents import Agent, ModelSettings, function_tool
# Define the tool schema
weather_tool = function_tool(
name="get_current_weather",
description="Get the weather for a city.",
parameters={
"type": "object",
"properties": {
"location": {"type": "string"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
)
# Configure the agent
weather_agent = Agent(
model_settings=ModelSettings(
model="o4-mini",
tool_choice="auto", # Model decides when to call the function
),
tools=[weather_tool],
)
# Execute
result = weather_agent.run("Show me the weather in London right now.")
print(result)
Object-Oriented Agent Pattern
The file examples/object_oriented_agentic_approach/resources/registry/agents/python_code_exec_agent.py (line 38) demonstrates a reusable agent class that defaults to o3-mini:
from examples.object_oriented_agentic_approach.resources.registry.agents.python_code_exec_agent import PythonExecAgent
# The agent is pre-configured with model_name="o3-mini" and automatic tool management
agent = PythonExecAgent()
# The model will call execute_python_code when reasoning requires code execution
output = agent.run(
"Load the CSV at /home/sandboxuser/sales.csv and compute total revenue per month."
)
print(output)
This agent inherits from BaseAgent, which internally creates a ToolManager that registers PythonExecTool (function name execute_python_code). Because the underlying language model is o3-mini, the OpenAI request includes the necessary tool configuration automatically.
Key Source Files in the Cookbook
examples/object_oriented_agentic_approach/resources/registry/agents/python_code_exec_agent.py: Demonstrates an agent class defaulting to o3-mini with integrated tool registration.examples/agents_sdk/multi-agent-portfolio-collaboration/investment_agents/pm.py: Contains the commented placeholder#model="o4-mini"at line 64, showing exactly where to swap model names.examples/mcp/building-a-supply-chain-copilot-with-agent-sdk-and-databricks-mcp/main.py: ShowsModelSettingsconfiguration withtool_choice="required".examples/object_oriented_agentic_approach/resources/registry/tools/python_code_interpreter_tool.py: Provides the JSON function definition that models see when function calling is enabled.
Summary
- Select the model by setting
model="o3-mini"ormodel="o4-mini"in your API call orModelSettingsobject. - Control tool behavior using
tool_choice="required"to force function calls ortool_choice="auto"to let the model decide. - Register function schemas using JSON schema definitions (raw SDK) or the
function_toolhelper (Agents SDK). - The same configuration pattern works across the raw OpenAI SDK and the Agents SDK provided in the openai-cookbook repository.
Frequently Asked Questions
What is the difference between tool_choice "auto" and "required" for o3-mini?
tool_choice="auto" lets the model decide whether to call a function based on the user query and available tools, while tool_choice="required" forces the model to use one of the provided functions if the reasoning process finds a match. Use "required" when you need deterministic tool usage and "auto" for flexible, conversational agents.
Can I use the same function schemas for o4-mini that I use for GPT-4o?
Yes. The o3-mini and o4-mini models use the identical JSON Schema format for function definitions as the GPT-4o family. You can migrate existing tool configurations by simply changing the model name parameter without modifying your schema definitions.
Where do I set the model name when using the Agents SDK?
Set the model name within the ModelSettings object passed to your Agent initialization, as demonstrated in examples/mcp/building-a-supply-chain-copilot-with-agent-sdk-and-databricks-mcp/main.py. The parameter is model="o3-mini" or model="o4-mini" inside the ModelSettings constructor.
Does o3-mini support parallel function calling like GPT-4o?
Yes. When you configure tool_choice="auto" or "required" with multiple tools registered, o3-mini can call multiple functions in a single response if the reasoning task requires it. The response will contain an array of tool calls that you must execute and return to the model.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →