AI SDK で任意モデルを指定
Agents SDK は標準で Responses API または Chat Completions API を通じて OpenAI モデルと連携します。別のモデルを使用したい場合は、Vercel の AI SDK が提供する幅広い対応モデルを、このアダプターを介して Agents SDK に取り込むことができます。
セットアップ
Section titled “セットアップ”-
拡張パッケージをインストールして AI SDK アダプターを導入します:
Terminal window npm install @openai/agents-extensions -
Vercel の AI SDK から使用したいモデルのパッケージを選び、インストールします:
Terminal window npm install @ai-sdk/openai -
アダプターとモデルをインポートしてエージェントに接続します:
import { openai } from '@ai-sdk/openai';import { aisdk } from '@openai/agents-extensions'; -
エージェントが使用するモデルのインスタンスを初期化します:
const model = aisdk(openai('gpt-5-mini'));
import { Agent, run } from '@openai/agents';
// Import the model package you installedimport { openai } from '@ai-sdk/openai';
// Import the adapterimport { aisdk } from '@openai/agents-extensions';
// Create a model instance to be used by the agentconst model = aisdk(openai('gpt-5-mini'));
// Create an agent with the modelconst agent = new Agent({ name: 'My Agent', instructions: 'You are a helpful assistant.', model,});
// Run the agent with the new modelrun(agent, 'What is the capital of Germany?');
プロバイダーのメタデータの受け渡し
Section titled “プロバイダーのメタデータの受け渡し”メッセージごとにプロバイダー固有のオプションを送信する必要がある場合は、providerMetadata
を通して渡してください。値は基盤となる AI SDK モデルにそのまま転送されます。例えば、Agents SDK で次の providerData
providerData: { anthropic: { cacheControl: { type: 'ephemeral'; } }}
は、AI SDK 連携を使用すると次のようになります
providerMetadata: { anthropic: { cacheControl: { type: 'ephemeral'; } }}