Beyond generating text
Tools let a model find information or perform tasks beyond generating text — searching the web, running code, reading files, or calling your functions. Tool-capable Foundry models expose this through the OpenAI Responses API: you pass a tools list, and by default the model autonomously decides when and which tool to use, guided by the prompt and system instructions.
Key concept · The tool-calling loop
User prompt → model decision → tool selection → execution → response. You deploy a tool-capable model, specify available tools in responses.create(), and the model chooses based on context. You steer its choices with tool-selection rules and the instructions (system prompt), but the decision to call is the model's.
Four tools out of the box
The Responses API ships four built-in tools, each addressing a different limitation of a plain LLM.
| Tool | What it does |
|---|---|
code_interpreter | A Python environment to write, test, and run code — computation and data analysis. |
web_search | Retrieves current information from the internet, overcoming the training cutoff. |
file_search | Searches user-uploaded files in a vector index — a built-in RAG pattern for proprietary knowledge. |
function | Calls custom functions in your application code to integrate business logic and systems. |
Built-in tools are provided by the API; custom tools are developer-defined functions. You list them all as JSON objects in the tools parameter and the model picks per request.
Calling your own code, safely
The function tool is the key extensibility point. Crucially, the model requests a call but never runs your business logic itself — your app executes it and returns the result, giving you control, auditability, and safety.
Key concept · The call-and-respond loop
- Define tools — each a JSON object with
type: "function", aname, and adescription(guiding when to call it). - The model evaluates the prompt and, if needed, emits a function call (name +
call_id). - Your app runs the matching function and returns a
function_call_outputitem with the result and the samecall_id. - The model completes its answer, incorporating the tool's output.
Best practices: keep tools single-purpose, validate arguments (never trust them blindly), handle errors so the model can reason about them, log usage, and require explicit authorization for high-impact actions. Tools add latency and can produce wrong arguments, so outputs still need review for critical decisions — but they turn a model into a controlled orchestrator of real systems.
Chapter 4 quiz
Thirteen questions on tools, the built-in tools, and the function-calling loop. Answer first, then expand Show answer.
Part A · Multiple choice
By default, who decides when and which tool to call?
- A The developer, hardcoded
- B The model, autonomously based on the prompt
- C The end user
- D Azure
Show answer
B. The model chooses; you guide it with tool-selection rules and system instructions.
Which built-in tool runs Python for computation and data analysis?
- A web_search
- B code_interpreter
- C file_search
- D function
Show answer
B — code_interpreter.
Which built-in tool grounds responses in user-uploaded files via a vector index?
- A file_search
- B web_search
- C code_interpreter
- D function
Show answer
A — file_search. A built-in RAG pattern over proprietary knowledge.
In the function-calling loop, who executes the function?
- A The model
- B Your application code
- C Azure OpenAI
- D The end user
Show answer
B. The model only requests the call; your app runs it and returns the output — control and safety.
What three elements define a function tool?
- A type "function", a name, and a description
- B endpoint, key, and model
- C role, content, and id
- D temperature, top_p, and max tokens
Show answer
A. Plus optional parameter specifications; the description guides when the model calls it.
What links a model's function-call request to the result your app returns?
- A The
call_id - B The temperature
- C The endpoint URL
- D The system message
Show answer
A — the call_id. You send a function_call_output with the matching call_id.
Part B · True or false
The web_search tool helps a model overcome its training-data cutoff.
Show answer
True. It retrieves current, real-time information from the internet.
Function arguments emitted by the model should be trusted without validation.
Show answer
False. Always validate arguments; incorrect or unexpected values can occur.
Tools are specified as a JSON list in the tools parameter of responses.create().
Show answer
True. The model then chooses among them per request.
Using tools eliminates the need to review outputs for critical decisions.
Show answer
False. Tools improve reliability but outputs still need review; they also add latency.
Part C · Short answer
Name the four built-in tools in the Responses API.
Show answer
code_interpreter, web_search, file_search, and function.
Give the four steps of the function call-and-respond loop.
Show answer
Define tools → model emits a function call → your app runs it and returns function_call_output → model completes the answer.
Give three best practices for the function tool.
Show answer
Any three: keep tools single-purpose, validate inputs, handle errors safely, log usage, and require authorization for high-impact actions.