Skip to content

Commit 04a1b30

Browse files
committed
GPT-5 full support
1 parent ac97264 commit 04a1b30

File tree

12 files changed

+98
-68
lines changed

12 files changed

+98
-68
lines changed

examples/handoffs/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
HandoffInputData,
66
handoff,
77
withTrace,
8+
isGpt5Default,
89
} from '@openai/agents';
910
import { removeAllTools } from '@openai/agents-core/extensions';
1011
import { z } from 'zod';
@@ -23,6 +24,12 @@ const randomNumberTool = tool({
2324

2425
// Message filter for handoff (removes tool messages and first two history items)
2526
function spanishHandoffMessageFilter(handoffMessageData: HandoffInputData) {
27+
if (isGpt5Default()) {
28+
console.log(
29+
'GPT-5 models do not work if you remove the toll call results, so this filter does nothing.',
30+
);
31+
return handoffMessageData;
32+
}
2633
// Remove all tool-related messages
2734
return removeAllTools(handoffMessageData);
2835
}

examples/mcp/hosted-mcp-human-in-the-loop.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ async function main(verbose: boolean, stream: boolean): Promise<void> {
2121
};
2222
const agent = new Agent({
2323
name: 'MCP Assistant',
24-
instructions: 'You must always use the MCP tools to answer questions.',
24+
instructions:
25+
'You must always use the MCP tools to answer questions. The mcp server knows which repo to investigate, so you do not need to ask the user about it.',
2526
tools: [
2627
hostedMcpTool({
2728
serverLabel: 'gitmcp',

examples/mcp/hosted-mcp-on-approval.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ async function main(verbose: boolean, stream: boolean): Promise<void> {
2525
};
2626
const agent = new Agent({
2727
name: 'MCP Assistant',
28-
instructions: 'You must always use the MCP tools to answer questions.',
28+
instructions:
29+
'You must always use the MCP tools to answer questions. The mcp server knows which repo to investigate, so you do not need to ask the user about it.',
2930
tools: [
3031
hostedMcpTool({
3132
serverLabel: 'gitmcp',

examples/mcp/hosted-mcp-simple.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ async function main(verbose: boolean, stream: boolean): Promise<void> {
44
withTrace('Hosted MCP Example', async () => {
55
const agent = new Agent({
66
name: 'MCP Assistant',
7-
instructions: 'You must always use the MCP tools to answer questions.',
7+
instructions:
8+
'You must always use the MCP tools to answer questions. The mcp server knows which repo to investigate, so you do not need to ask the user about it.',
89
tools: [
910
hostedMcpTool({
1011
serverLabel: 'gitmcp',

examples/mcp/streamable-http-custom-fetch-example.ts

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

examples/mcp/streamable-http-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function main() {
1616
await mcpServer.connect();
1717
const result = await run(
1818
agent,
19-
'Which language is this repo written in?',
19+
'Which language is this repo written in? The MCP server knows which repo to investigate.',
2020
);
2121
console.log(result.finalOutput);
2222
});

examples/model-providers/custom-example-agent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const getWeatherTool = tool({
1313
description: 'Get the weather for a given city',
1414
parameters: z.object({ city: z.string() }),
1515
execute: async (input) => {
16+
console.log(`[debug] Getting weather for ${input.city}\n`);
1617
return `The weather in ${input.city} is sunny`;
1718
},
1819
});
@@ -28,7 +29,7 @@ const agent = new Agent({
2829
async function main() {
2930
await withTrace('ChatCompletions Assistant Example', async () => {
3031
const result = await run(agent, "What's the weather in Tokyo?");
31-
console.log(`\n\nFinal response:\n${result.finalOutput}`);
32+
console.log(`[Final response]\n${result.finalOutput}`);
3233
});
3334
}
3435

examples/tools/file-search.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
import { Agent, run, fileSearchTool, withTrace } from '@openai/agents';
2+
import OpenAI, { toFile } from 'openai';
23

34
async function main() {
5+
const client = new OpenAI({
6+
apiKey: process.env.OPENAI_API_KEY,
7+
});
8+
9+
const text = `Arrakis, the desert planet in Frank Herbert's "Dune," was inspired by the scarcity of water
10+
as a metaphor for oil and other finite resources.`;
11+
const upload = await client.files.create({
12+
file: await toFile(Buffer.from(text, 'utf-8'), 'cafe.txt'),
13+
purpose: 'assistants',
14+
});
15+
const vectorStore = await client.vectorStores.create({
16+
name: 'Arrakis',
17+
});
18+
console.log(vectorStore);
19+
const indexed = await client.vectorStores.files.createAndPoll(
20+
vectorStore.id,
21+
{ file_id: upload.id },
22+
);
23+
console.log(indexed);
24+
425
const agent = new Agent({
526
name: 'File searcher',
627
instructions: 'You are a helpful agent.',
728
tools: [
8-
fileSearchTool(['vs_67bf88953f748191be42b462090e53e7'], {
29+
fileSearchTool([vectorStore.id], {
930
maxNumResults: 3,
1031
includeSearchResults: true,
1132
}),

examples/tools/image-generation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function main() {
2525
console.log('Generating image, this may take a while...');
2626
const result = await run(
2727
agent,
28-
'Create an image of a frog eating a pizza, comic book style.',
28+
'Create an image of a frog eating a pizza, comic book style. Return a text description of the image as a message too.',
2929
);
3030
console.log(result.finalOutput);
3131

packages/agents-core/src/run.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
254254

255255
try {
256256
while (true) {
257+
const explictlyModelSet =
258+
(state._currentAgent.model !== undefined &&
259+
state._currentAgent.model !== '') ||
260+
(this.config.model !== undefined && this.config.model !== '');
257261
let model = selectModel(state._currentAgent.model, this.config.model);
258262

259263
if (typeof model === 'string') {
@@ -370,10 +374,9 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
370374
...this.config.modelSettings,
371375
...state._currentAgent.modelSettings,
372376
};
373-
const agentModel = state._currentAgent.model;
374377
const agentModelSettings = state._currentAgent.modelSettings;
375-
modelSettings = sanitizeModelSettingsForNonGpt5Runner(
376-
agentModel,
378+
modelSettings = adjustModelSettingsForNonGPT5RunnerModel(
379+
explictlyModelSet,
377380
agentModelSettings,
378381
model,
379382
modelSettings,
@@ -704,6 +707,9 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
704707
`Running agent ${currentAgent.name} (turn ${result.state._currentTurn})`,
705708
);
706709

710+
const explictlyModelSet =
711+
(currentAgent.model !== undefined && currentAgent.model !== '') ||
712+
(this.config.model !== undefined && this.config.model !== '');
707713
let model = selectModel(currentAgent.model, this.config.model);
708714

709715
if (typeof model === 'string') {
@@ -718,10 +724,9 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
718724
...this.config.modelSettings,
719725
...currentAgent.modelSettings,
720726
};
721-
const agentModel = currentAgent.model;
722727
const agentModelSettings = currentAgent.modelSettings;
723-
modelSettings = sanitizeModelSettingsForNonGpt5Runner(
724-
agentModel,
728+
modelSettings = adjustModelSettingsForNonGPT5RunnerModel(
729+
explictlyModelSet,
725730
agentModelSettings,
726731
model,
727732
modelSettings,
@@ -1053,18 +1058,17 @@ export async function run<TAgent extends Agent<any, any>, TContext = undefined>(
10531058
* agent relied on the default model (i.e., no explicit model set), these GPT-5-only settings
10541059
* are incompatible and should be stripped to avoid runtime errors.
10551060
*/
1056-
function sanitizeModelSettingsForNonGpt5Runner(
1057-
agentModel: string | Model,
1061+
function adjustModelSettingsForNonGPT5RunnerModel(
1062+
explictlyModelSet: boolean,
10581063
agentModelSettings: ModelSettings,
10591064
runnerModel: string | Model,
10601065
modelSettings: ModelSettings,
10611066
): ModelSettings {
10621067
if (
10631068
// gpt-5 is enabled for the default model for agents
10641069
isGpt5Default() &&
1065-
// no explicitly set model for the agent
1066-
typeof agentModel === 'string' &&
1067-
agentModel === Agent.DEFAULT_MODEL_PLACEHOLDER &&
1070+
// explicitly set model for the agent
1071+
explictlyModelSet &&
10681072
// this runner uses a non-gpt-5 model
10691073
(typeof runnerModel !== 'string' ||
10701074
!gpt5ReasoningSettingsRequired(runnerModel)) &&

0 commit comments

Comments
 (0)