AI SDK で任意モデルを指定
Agents SDK は、標準で Responses API または Chat Completions API を通じて OpenAI モデルと動作します。別のモデルを使用したい場合は、Vercel’s AI SDK がサポートするさまざまなモデルを、このアダプター経由で Agents SDK に組み込むことができます。
セットアップ
Section titled “セットアップ”-
extensions パッケージをインストールして AI SDK アダプターを追加します:
Terminal window npm install @openai/agents-extensions -
Vercel’s 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('o4-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('o4-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?');