← Develop AI Apps and Agents o… Latent Shelf · Ch.4

Module Study Guide · Path 1 · Generative AI apps

Develop Generative AI Apps That Use Tools

Tools turn a text generator into an orchestrator — the model decides when and which tool to call; your code decides how it runs.

— the module's core idea

Extending a model beyond text. This module explains what tools are and the tool-calling loop, tours the four built-in tools in the Responses API, and details the function tool — the controlled loop that lets a model call your own code.

tool-calling loop4 built-in toolsfunction calling13 quiz questions
01What tools are

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.

02The built-in tools

Four tools out of the box

The Responses API ships four built-in tools, each addressing a different limitation of a plain LLM.

The four built-in tools.
ToolWhat it does
code_interpreterA Python environment to write, test, and run code — computation and data analysis.
web_searchRetrieves current information from the internet, overcoming the training cutoff.
file_searchSearches user-uploaded files in a vector index — a built-in RAG pattern for proprietary knowledge.
functionCalls 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.

03The function tool

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", a name, and a description (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_output item with the result and the same call_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.

★Test yourself

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

Q1

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.

Q2

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.

Q3

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.

Q4

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.

Q5

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.

Q6

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

Q7

The web_search tool helps a model overcome its training-data cutoff.

Show answer

True. It retrieves current, real-time information from the internet.

Q8

Function arguments emitted by the model should be trusted without validation.

Show answer

False. Always validate arguments; incorrect or unexpected values can occur.

Q9

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.

Q10

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

Q11

Name the four built-in tools in the Responses API.

Show answer

code_interpreter, web_search, file_search, and function.

Q12

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.

Q13

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.