モデルの応答を生成したり、エージェントを構築したりする際には、組み込みツール、Function Calling、プログラムによるツール呼び出し、ツール検索、リモート MCP サーバーを使って機能を拡張できます。これらを使うと、モデルはウェブの検索、ファイルからの情報取得、遅延読み込みに設定したツール定義の実行時の読み込み、独自の関数の呼び出し、JavaScript によるツール呼び出しの組み合わせ、外部サービスへのアクセスが可能になります。tool_search に対応しているのは、gpt-5.4 以降のモデルのみです。
ランタイムに合った統合方法を選び、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": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/mcp",
"require_approval": "never"
}
],
"input": "Roll 2d4+1"
}'利用可能なツール
OpenAI プラットフォームで利用できるツールの概要を紹介します。各ツールを選択すると、詳しい使い方を確認できます。
カスタムコードを呼び出して、モデルが追加のデータや機能にアクセスできるようにします。
モデルの応答生成にインターネット上のデータを取り入れます。
Model Context Protocol(MCP)サーバーを通じて、モデルが新たな機能にアクセスできるようにします。
バージョン管理されたスキルバンドルをアップロードし、ホスト型シェル環境で再利用します。
ホスト型コンテナや独自のローカルランタイムでシェルコマンドを実行します。
モデルがコンピューターのインターフェースを操作できるエージェント型ワークフローを作成します。
GPT Image を使って画像を生成、編集します。
応答生成時に、アップロードしたファイルの内容を検索してコンテキストを取得します。
関連するツールをモデルのコンテキストに動的に読み込み、トークン使用量を最適化します。
ツール呼び出しを連携させる JavaScript をモデルに作成、実行させます。
API での使用方法
モデルの応答を生成するリクエストでは、通常、tools パラメータで設定を指定してツールへのアクセスを有効にします。必要な設定はツールごとに異なります。詳しい手順は、利用可能なツールのセクションを参照してください。
モデルは、入力されたプロンプトに基づいて、設定されたツールを使用するかどうかを自動的に判断します。たとえば、モデルの学習データのカットオフ日より後の情報をプロンプトで求め、ウェブ検索が有効になっている場合、モデルは通常、ウェブ検索ツールを呼び出して関連する最新情報を取得します。
高度なワークフローでは、やり取りの途中でツール定義を追加で読み込むこともできます。たとえば、ツール検索では、モデルが必要と判断するまで関数定義の読み込みを遅らせることができます。
API リクエストで tool_choice パラメータを設定すると、この動作を明示的に制御したり、方向付けたりできます。
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 を通じて機能を利用する場合は連携と可観測性を参照してください。