Skip to content

Commit 54e3b00

Browse files
committed
Fix #300 migrate ai-sdk/provider to v2
1 parent 8287b5f commit 54e3b00

File tree

7 files changed

+310
-213
lines changed

7 files changed

+310
-213
lines changed

examples/ai-sdk/ai-sdk-model.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

examples/ai-sdk/index.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { aisdk } from '@openai/agents-extensions';
2+
import { z } from 'zod';
3+
import { Agent, run, tool } from '@openai/agents';
4+
import { AiSdkModel } from '@openai/agents-extensions';
5+
6+
export async function runAgents(model: AiSdkModel) {
7+
const sleep = (ms: number) =>
8+
new Promise((resolve) => setTimeout(resolve, ms));
9+
10+
const getWeatherTool = tool({
11+
name: 'get_weather',
12+
description: 'Get the weather for a given city',
13+
parameters: z.object({ city: z.string() }),
14+
execute: async (input) => {
15+
await sleep(300);
16+
return `The weather in ${input.city} is sunny`;
17+
},
18+
});
19+
20+
const dataAgent = new Agent({
21+
name: 'Weather Data Agent',
22+
instructions: 'You are a weather data agent.',
23+
handoffDescription:
24+
'When you are asked about the weather, you will use tools to get the weather.',
25+
tools: [getWeatherTool],
26+
model, // Using the AI SDK model for this agent
27+
});
28+
29+
const agent = new Agent({
30+
name: 'Helpful Assistant',
31+
instructions:
32+
'You are a helpful assistant. When you need to get the weather, you can hand off the task to the Weather Data Agent.',
33+
handoffs: [dataAgent],
34+
});
35+
36+
const result = await run(
37+
agent,
38+
'Hello what is the weather in San Francisco and oakland?',
39+
);
40+
console.log(result.finalOutput);
41+
}
42+
43+
import { openai } from '@ai-sdk/openai';
44+
// import { anthropic } from '@ai-sdk/anthropic';
45+
// import { google } from '@ai-sdk/google';
46+
47+
(async function () {
48+
const model = aisdk(openai('gpt-4.1-nano'));
49+
// const model = aisdk(anthropic('claude-sonnet-4-20250514'));
50+
// const model = aisdk(google('gemini-2.5-flash'));
51+
await runAgents(model);
52+
})();

examples/ai-sdk/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"private": true,
33
"name": "ai-sdk",
44
"dependencies": {
5+
"@ai-sdk/openai": "^2.0.15",
56
"@openai/agents": "workspace:*",
67
"@openai/agents-extensions": "workspace:*",
7-
"@ai-sdk/openai": "^1.1.3",
8-
"zod": "^3.25.40"
8+
"zod": "^3.25.76"
99
},
1010
"scripts": {
1111
"build-check": "tsc --noEmit",
12-
"start:sdk-model": "tsx ai-sdk-model.ts",
12+
"start": "tsx index.ts",
1313
"start:stream": "tsx stream.ts"
1414
}
1515
}

examples/ai-sdk/stream.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
import { z } from 'zod';
22
import { Agent, run, tool } from '@openai/agents';
3-
import { openai } from '@ai-sdk/openai';
4-
import { aisdk } from '@openai/agents-extensions';
5-
6-
const model = aisdk(openai('gpt-4.1-nano'));
3+
import { aisdk, AiSdkModel } from '@openai/agents-extensions';
74

8-
const getWeatherTool = tool({
9-
name: 'get_weather',
10-
description: 'Get the weather for a given city',
11-
parameters: z.object({ city: z.string() }),
12-
async execute({ city }) {
13-
return `The weather in ${city} is sunny`;
14-
},
15-
});
5+
export async function runAgents(model: AiSdkModel) {
6+
const getWeatherTool = tool({
7+
name: 'get_weather',
8+
description: 'Get the weather for a given city',
9+
parameters: z.object({ city: z.string() }),
10+
async execute({ city }) {
11+
return `The weather in ${city} is sunny`;
12+
},
13+
});
1614

17-
const agent = new Agent({
18-
name: 'Weather agent',
19-
instructions: 'You provide weather information.',
20-
tools: [getWeatherTool],
21-
model,
22-
});
15+
const agent = new Agent({
16+
name: 'Weather agent',
17+
instructions: 'You provide weather information.',
18+
tools: [getWeatherTool],
19+
model,
20+
});
2321

24-
async function main() {
2522
const stream = await run(agent, 'What is the weather in San Francisco?', {
2623
stream: true,
2724
});
@@ -32,6 +29,13 @@ async function main() {
3229
console.log();
3330
}
3431

35-
if (require.main === module) {
36-
main().catch(console.error);
37-
}
32+
import { openai } from '@ai-sdk/openai';
33+
// import { anthropic } from '@ai-sdk/anthropic';
34+
// import { google } from '@ai-sdk/google';
35+
36+
(async function () {
37+
const model = aisdk(openai('gpt-4.1-nano'));
38+
// const model = aisdk(anthropic('claude-sonnet-4-20250514'));
39+
// const model = aisdk(google('gemini-2.5-flash'));
40+
await runAgents(model);
41+
})();

packages/agents-extensions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"build-check": "tsc --noEmit -p ./tsconfig.test.json"
1414
},
1515
"dependencies": {
16-
"@ai-sdk/provider": "^1.1.3",
16+
"@ai-sdk/provider": "^2.0.0",
1717
"@types/ws": "^8.18.1",
1818
"debug": "^4.4.0"
1919
},

0 commit comments

Comments
 (0)