Introduction & Overview

Welcome to understanding how GPT-5 responds when it decides to use your tools! In the previous lesson, you learned how to create tool schemas that describe your functions to GPT-5. Now, you'll discover how to include these tools in your API requests and, more importantly, how to interpret GPT-5's responses when it wants to use them.

In this lesson, you'll learn how to configure your requests to enable tool use, understand the different types of responses GPT-5 can provide, and extract the specific information you need to execute the tools GPT-5 requests. By the end, you'll be able to recognize when GPT-5 wants to use a tool and gather all the details needed to make that happen.

Adding Tool Guidance to Your Instructions

While GPT-5 will automatically see and can use any tools you provide in your request, mentioning tools in your instructions can help ensure more consistent behavior and guide GPT-5 toward using them appropriately.

Here's an example of how you can improve your instructions:

import OpenAI from "openai";

// Initialize the OpenAI client
const client = new OpenAI();

// System instructions with optional tool usage guidance
const systemPrompt =
  "You are a helpful math assistant. " +
  "Always use the available tools to perform calculations accurately.";

This guidance helps GPT-5 understand your preferences for when and how to use tools, but it's not required for tool functionality. GPT-5 can still recognize and use tools based solely on their availability in the request.

Providing Tools to GPT-5

The tools parameter is the essential component that makes your functions available to GPT-5. This parameter accepts the JSON array of schemas you created in the previous lesson:

import fs from "fs";

// Load your tool schemas
const schemasJson = fs.readFileSync("schemas.json", "utf-8");
const toolSchemas = JSON.parse(schemasJson);

// Create a message requesting a calculation
const messages: Array<{ role: "user"; content: string }> = [
  { role: "user", content: "Calculate 15 + 27" }
];

// Send the request with tools enabled
const response = await client.responses.create({
  model: "gpt-5",
  instructions: systemPrompt,
  input: messages,
  tools: toolSchemas,  // This makes your tools available to GPT-5
  store: false
});

GPT-5 will recognize the available tools from the tools parameter alone. The instructions guidance can be helpful for encouraging consistent tool usage patterns, but GPT-5 will still be able to see and use your tools even without explicit instructions.

Understanding GPT-5's Tool Use Responses

When GPT-5 decides to use a tool, the response structure contains specific items that indicate function calls. Let's examine what a complete tool use response looks like by printing the entire response structure:

// Print the complete response structure
console.log(JSON.stringify(response, null, 2));

This will output a detailed JSON structure showing all the components of GPT-5's response. Looking at the output, you'll see a structure like this:

{
  "id": "resp_0b9865c3fa45420a016925ebcfbd28819e963e5699a034ac4e",
  "created_at": 1764092879,
  "error": null,
  "incomplete_details": null,
  "instructions": "You are a helpful math assistant. Always use the available tools to perform calculations accurately.",
  "metadata": {},
  ̶"model": "gpt-5-2025-08-07",
  "object": "response",
  "output": [
    {
      "id": "rs_0b9865c3fa45420a016925ebd03bac819e938ac928f40b5b4c",
      "summary": [],
      "type": "reasoning"
    },
    {
      "arguments": "{\"a\":15,\"b\":27}",
      "call_id": "call_0m91Qu2mDkJ1xIrrbfm7ba52",
      "name": "sum_numbers",
      "type": "function_call",
      "id": "fc_0b9865c3fa45420a016925ebd16950819e8a82030bf71aeee3",
      "status": "completed"
    }
  ],
  ...
}

Notice that this response does not include any message content for the user. Instead, the output array contains a function_call item (and possibly a reasoning item). This is how GPT-5 requests to use a tool — it cannot execute the function itself. When you see a function_call item, it means GPT-5 is asking your code to run the specified tool on its behalf. It's your responsibility to extract the name, arguments, and call_id, execute the function, and then send the result back to GPT-5 so it can continue the conversation or provide a final answer to the user.

Understanding the Output Array and Function Call Items

The output array is where GPT-5 communicates its tool use intentions. Each item in this array has a type field that tells you how to handle it. When GPT-5 wants to execute a function, you'll encounter items with type: "function_call".

Let's iterate through the output array to examine each item:

// Process each content item
response.output.forEach((contentItem, index) => {
  console.log(`\nContent Item ${index + 1}:`);
  console.log(`Type: ${contentItem.type}`);
  
  if (contentItem.type === "message") {
    const messageContent = contentItem.content[0];
    if (messageContent.type === "output_text") {
      console.log(`Content: ${messageContent.text}`);
    }
  } else if (contentItem.type === "function_call") {
    console.log(`Tool Name: ${contentItem.name}`);
    console.log(`Tool Input: ${contentItem.arguments}`);
    console.log(`Tool Call ID: ${contentItem.call_id}`);
  }
});

Running this code will show you the structure of each output item:

Content Item 1:
Type: reasoning

Content Item 2:
Type: function_call
Tool Name: sum_numbers
Tool Input: {"a":15,"b":27}
Tool Call ID: call_0m91Qu2mDkJ1xIrrbfm7ba52

Each function call item contains three essential pieces of information that your system needs to execute the requested function:

  • name: The function name that matches your tool schema (e.g., "sum_numbers")
  • arguments: A JSON string containing the parameters to pass to your function, with keys matching your schema's parameter names
  • call_id: A unique identifier for this specific function call request, which you'll need when sending results back to GPT-5

These fields work together to provide everything you need to execute the tool and maintain proper conversation flow. Note that arguments is provided as a JSON string, so you'll need to parse it (using JSON.parse()) before passing the values to your actual function.

Summary and Next Steps

You now understand how GPT-5 communicates its tool use intentions through structured API responses. When GPT-5 decides to use tools, it provides function call items within the output array, each containing the function name, arguments, and a unique call ID.

The key to working with GPT-5's tool use responses is:

  1. Iterate through the response.output array.
  2. Check each item's type field to identify function calls.
  3. Extract the name, arguments, and call_id from function call items.
  4. Use this information to execute the appropriate functions.

In the upcoming practice exercises, you'll work with these response structures hands-on, learning to parse function call requests and prepare for the next step: actually executing the requested tools and sending results back to GPT-5 to complete the conversation flow.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal