Skip to content

Commit be6b141

Browse files
committed
Fix a bug where responses api does not accept both outputType and verbosity parameter for gpt-5
1 parent 8cf5356 commit be6b141

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

examples/basic/hello-world-gpt-5.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Agent, run } from '@openai/agents';
1+
import { Agent, OpenAIChatCompletionsModel, run } from '@openai/agents';
2+
import OpenAI from 'openai';
3+
import { z } from 'zod';
4+
5+
const output = z.object({
6+
title: z.string(),
7+
description: z.string(),
8+
});
29

310
async function main() {
411
const agent = new Agent({
@@ -11,10 +18,27 @@ async function main() {
1118
text: { verbosity: 'low' },
1219
},
1320
},
21+
outputType: output,
1422
});
1523

16-
const result = await run(agent, 'Tell me about recursion in programming.');
24+
const prompt = 'Tell me about recursion in programming.';
25+
const result = await run(agent, prompt);
1726
console.log(result.finalOutput);
27+
28+
const completionsAgent = new Agent({
29+
name: 'GPT-5 Assistant',
30+
model: new OpenAIChatCompletionsModel(new OpenAI(), 'gpt-5'),
31+
instructions: "You're a helpful assistant.",
32+
modelSettings: {
33+
providerData: {
34+
reasoning_effort: 'minimal',
35+
verbosity: 'low',
36+
},
37+
},
38+
outputType: output,
39+
});
40+
const completionsResult = await run(completionsAgent, prompt);
41+
console.log(completionsResult.finalOutput);
1842
}
1943

2044
if (require.main === module) {

packages/agents-openai/src/openaiResponsesModel.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ function getToolChoice(
7171

7272
function getResponseFormat(
7373
outputType: SerializedOutputType,
74+
otherProperties: Record<string, any> | undefined,
7475
): OpenAI.Responses.ResponseTextConfig | undefined {
7576
if (outputType === 'text') {
76-
return undefined;
77+
return otherProperties;
7778
}
7879

7980
return {
81+
...otherProperties,
8082
format: outputType,
8183
};
8284
}
@@ -830,7 +832,9 @@ export class OpenAIResponsesModel implements Model {
830832
const input = getInputItems(request.input);
831833
const { tools, include } = getTools(request.tools, request.handoffs);
832834
const toolChoice = getToolChoice(request.modelSettings.toolChoice);
833-
const responseFormat = getResponseFormat(request.outputType);
835+
const { text, ...restOfProviderData } =
836+
request.modelSettings.providerData ?? {};
837+
const responseFormat = getResponseFormat(request.outputType, text);
834838
const prompt = getPrompt(request.prompt);
835839

836840
let parallelToolCalls: boolean | undefined = undefined;
@@ -859,7 +863,7 @@ export class OpenAIResponsesModel implements Model {
859863
stream,
860864
text: responseFormat,
861865
store: request.modelSettings.store,
862-
...request.modelSettings.providerData,
866+
...restOfProviderData,
863867
};
864868

865869
if (logger.dontLogModelData) {

0 commit comments

Comments
 (0)