Understanding How GPT-5 Uses Tools

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:

TypeScript
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.

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