モデルの応答を生成するときやエージェントを構築するときは、組み込みツール、Function Calling、プログラムによるツール呼び出し、ツール検索、リモート MCP サーバーを使ってモデルの機能を拡張できます。これらを使うと、モデルはウェブを検索したり、ファイルから情報を取得したり、読み込みを保留したツール定義を実行時に読み込んだりできます。また、独自の関数を呼び出す、JavaScript で複数のツール呼び出しを組み合わせる、外部サービスにアクセスするといった操作も可能です。gpt-5.4 以降のモデルのみが tool_search に対応しています。
実行環境に合った方法を選び、Responses API のリクエスト、Agents API のエージェント、または Agents SDK のエージェント定義でツールを設定します。利用できるツール、設定方法、呼び出しの処理方法は、どの方法を選ぶかによって異なります。以下の例では Responses API を使用します。
import OpenAI from "openai";
const client = new OpenAI();
const response = await client.responses.create({
model: "gpt-6-astra",
tools: [{ type: "web_search" }],
input: "What was a positive news story from today?",
});
console.log(response.output_text);import OpenAI from "openai";
const openai = new OpenAI();
const response = await openai.responses.create({
model: "gpt-6-astra",
input: "What is deep research by OpenAI?",
tools: [
{
type: "file_search",
vector_store_ids: ["<vector_store_id>"],
},
],
});
console.log(response);import OpenAI from "openai";
const client = new OpenAI();
const crmNamespace = {
type: "namespace",
name: "crm",
description: "CRM tools for customer lookup and order management.",
tools: [
{
type: "function",
name: "get_customer_profile",
description: "Fetch a customer profile by customer ID.",
parameters: {
type: "object",
properties: {
customer_id: { type: "string" },
},
required: ["customer_id"],
additionalProperties: false,
},
},
{
type: "function",
name: "list_open_orders",
description: "List open orders for a customer ID.",
defer_loading: true,
parameters: {
type: "object",
properties: {
customer_id: { type: "string" },
},
required: ["customer_id"],
additionalProperties: false,
},
},
],
};
const response = await client.responses.create({
model: "gpt-6-astra",
input: "List open orders for customer CUST-12345.",
tools: [crmNamespace, { type: "tool_search" }],
parallel_tool_calls: false,
});
console.log(response.output);import OpenAI from "openai";
const client = new OpenAI();
const tools = [
{
type: "function",
name: "get_weather",
description: "Get current temperature for a given location.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "City and country e.g. Bogotá, Colombia",
},
},
required: ["location"],
additionalProperties: false,
},
strict: true,
},
];
const response = await client.responses.create({
model: "gpt-6-astra",
input: [
{ role: "user", content: "What is the weather like in Paris today?" },
],
tools,
});
console.log(response.output[0]);curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"tools": [
{
"type": "mcp",
"server_label": "openai_docs",
"server_description": "Search and read the public OpenAI documentation.",
"server_url": "https://developers.openai.com/mcp",
"require_approval": "never"
}
],
"input": "Search the OpenAI docs for Responses API streaming and return the relevant links."
}'利用可能なツール
OpenAI プラットフォームで利用できるツールの一覧です。各ツールを選択すると、詳しい使い方を確認できます。
独自のコードを呼び出して、モデルが追加のデータや機能を利用できるようにします。
モデルが応答を生成する際に、インターネット上の情報を利用できます。
Model Context Protocol(MCP)サーバーを介して、モデルが新しい機能を利用できるようにします。
バージョン管理されたスキルバンドルをホスト型シェル環境にアップロードして再利用できます。
ホスト型コンテナまたは独自のローカル実行環境でシェルコマンドを実行できます。
モデルがコンピューターのインターフェースを操作できるエージェントワークフローを構築できます。
GPT Image を使って画像を生成、編集できます。
アップロードしたファイルの内容を検索し、応答の生成に必要なコンテキストを取得できます。
関連するツールをモデルのコンテキストに動的に読み込み、トークンの使用量を最適化します。
モデルが JavaScript コードを作成、実行して、複数のツール呼び出しを制御できるようにします。
API での使い方
API でモデルの応答を生成する際は、通常、リクエストの tools パラメーターでツールを設定して、モデルがツールを使えるようにします。必要な設定はツールごとに異なります。詳しい手順は「利用可能なツール」を参照してください。
モデルは、与えられたプロンプトに基づいて、設定済みのツールを使うかどうかを自動的に判断します。たとえば、モデルの学習データの対象期間より後の情報をプロンプトで求めた場合、ウェブ検索が有効であれば、通常はモデルがウェブ検索ツールを呼び出して関連する最新情報を取得します。
高度なワークフローでは、やり取りの途中でツール定義を追加で読み込むこともできます。たとえば、ツール検索では、モデルが必要と判断するまで関数定義の読み込みを保留できます。
ツールの選択を明示的に制御したり、選択の方針を指定したりするには、tool_choice パラメーターを API リクエストで設定します。
Agents API
エージェントの実行ループは Agents API が処理します。ツールは agent.tools で設定し、関数呼び出しはアプリケーション側で処理します。ツールに実行環境が必要な場合は、サンドボックスを接続します。
アプリケーションのコードを呼び出す方法は「関数」、ツールサーバーに接続する方法は「MCP 接続」、ツールに必要な実行環境を用意する方法は「サンドボックスの設定」を参照してください。プログラムによるツール呼び出しはデフォルトで有効です。スキルは、サンドボックス内の機能ディレクトリから検出されます。
Agents SDK での使い方
Agents SDK でも、各ツールの役割は同じです。ただし、ツールの組み込み方は異なります。個々の Responses API リクエストで設定する代わりに、エージェントの定義とワークフローの設計にツールを組み込みます。
- 専門エージェントが自らツールを呼び出す場合は、そのエージェントにホスト型ツール、関数ツール、またはホスト型 MCP ツールを直接追加します。
- ユーザーへの応答を管理役のエージェントが引き続き担当する場合は、専門エージェントをツールとして公開します。
- ツールを使うかどうかの判断を SDK で表現する場合でも、シェル、パッチ適用、コンピューターの使用に必要なハーネスは、自分の実行環境に用意します。
import { tool } from "@openai/agents";
import { z } from "zod";
const getWeatherTool = tool({
name: "get_weather",
description: "Get the weather for a given city.",
parameters: z.object({ city: z.string() }),
async execute({ city }) {
return `The weather in ${city} is sunny.`;
},
});import { Agent } from "@openai/agents";
const summarizer = new Agent({
name: "Summarizer",
instructions: "Generate a concise summary of the supplied text.",
});
const mainAgent = new Agent({
name: "Research assistant",
tools: [
summarizer.asTool({
toolName: "summarize_text",
toolDescription: "Generate a concise summary of the supplied text.",
}),
],
});個々の専門エージェントを設計する際は「エージェントの定義」を参照してください。ツールの利用によって担当するエージェントが変わる場合は「オーケストレーションとハンドオフ」、ツールが承認に関わる場合は「ガードレールと人によるレビュー」、MCP を介して機能を利用する場合は「統合と可観測性」を参照してください。