Controlling Function Calling with Specified and Dynamic Tool Use
This lesson explains function calling and the difference between specified and dynamic tool use, which decide how much freedom the model has in choosing the tools through which agents query systems, perform actions and run code.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how function calling works.
- Control tool selection with the tool_choice parameter.
- Decide when dynamic tool use suits a task and how to limit the number of tools.
How function calling works
With function calling, the application sends tool definitions with the request: each has a name, a description and a JSON Schema for its parameters. The model may respond with one or more function calls containing arguments that match the schema. The application executes the function, sends the result back in a function_call_output item, and the model continues. Strict mode constrains the arguments to the schema exactly. The model never executes anything itself; the application stays in control of what actually runs.
tools = [{
"type": "function", "name": "get_order", "strict": True,
"description": "Look up one order by its ID. Use before answering any question about an order.",
"parameters": {"type": "object", "additionalProperties": False, "required": ["order_id"],
"properties": {"order_id": {"type": "string", "pattern": "^ORD-[0-9]{6}$"}}},
}]
r = openai.responses.create(model=CHAT, input=question, tools=tools,
tool_choice={"type": "function", "name": "get_order"}) # specified tool use
call = next(item for item in r.output if item.type == "function_call")
result = get_order(**json.loads(call.arguments))
r = openai.responses.create(model=CHAT, previous_response_id=r.id, tools=tools,
input=[{"type": "function_call_output", "call_id": call.call_id, "output": json.dumps(result)}])The following diagram shows the messages exchanged for one function call.

One function call round trip
Specified tool use
Specified tool use controls whether and which tool the model calls through the tool_choice parameter: auto lets the model decide, required forces at least one tool call, none disables tools, and naming a function forces that function. Forcing a tool suits workflow steps where a call is mandatory, such as always retrieving the customer record before answering, or extracting structured data through a function schema. Restricting the available tools per step (allowed tools) achieves a similar effect while leaving some choice.
tool_choice values
Dynamic tool use
Dynamic tool use gives the model freedom to choose tools, decide their order and call several in parallel, which suits open-ended tasks. It also covers tools discovered at run time: an agent connected to an MCP server lists the server's current tools, and an agent with a very large catalogue can select a relevant subset per request by embedding similarity between the request and tool descriptions. Tool selection accuracy depends on clear names, distinct descriptions that say when to use and when not to use each tool, and a manageable number of tools per call.
The following table summarizes the options.
| Mode | Setting or mechanism | Use when |
|---|---|---|
| Model chooses | tool_choice auto | Open-ended tasks with several useful tools |
| At least one call | tool_choice required | The answer must come from a tool |
| Specific tool | tool_choice naming the function | A workflow step needs exactly that call |
| Discovered at run time | MCP list_tools, tool retrieval | Tool catalogues change or are large |
Letting the model choose
Too many tools
An internal IT agent has 120 function tools. It often chooses a wrong but similarly named tool, and each request uses 18,000 input tokens before the user's question is processed.
Selecting the most relevant 10-15 tools per request by similarity between the request and tool descriptions reduces both errors and tokens, and rewriting descriptions to distinguish similar tools helps further. Alternatively, split the tools across specialist agents behind a router. A larger model might choose slightly better but would increase cost on every request.
How can a call to a particular tool be made mandatory?
Show answer
With tool_choice, which can force a specific tool, or any tool, on that request.
Exam Tips
Remember for the exam
- The application executes tools; the model only proposes calls.
- tool_choice forces a specific tool or any tool when a call is mandatory.
- Large catalogues: select a subset per request or split across agents.