コンテンツにスキップ

AI SDK で任意モデルを指定

Agents SDK は、標準で Responses API または Chat Completions API を通じて OpenAI モデルと動作します。別のモデルを使用したい場合は、Vercel’s AI SDK がサポートするさまざまなモデルを、このアダプター経由で Agents SDK に組み込むことができます。

  1. extensions パッケージをインストールして AI SDK アダプターを追加します:

    Terminal window
    npm install @openai/agents-extensions
  2. Vercel’s AI SDK から使用したいモデルパッケージを選択してインストールします:

    Terminal window
    npm install @ai-sdk/openai
  3. エージェントに接続するためにアダプターとモデルをインポートします:

    import { openai } from '@ai-sdk/openai';
    import { aisdk } from '@openai/agents-extensions';
  4. エージェントが使用するモデルのインスタンスを初期化します:

    const model = aisdk(openai('o4-mini'));
AI SDK セットアップ
import { Agent, run } from '@openai/agents';
// Import the model package you installed
import { openai } from '@ai-sdk/openai';
// Import the adapter
import { aisdk } from '@openai/agents-extensions';
// Create a model instance to be used by the agent
const model = aisdk(openai('o4-mini'));
// Create an agent with the model
const agent = new Agent({
name: 'My Agent',
instructions: 'You are a helpful assistant.',
model,
});
// Run the agent with the new model
run(agent, 'What is the capital of Germany?');