Skip to content

Commit b07a588

Browse files
authored
fix: #562 invalid model settings when prompt is set in Agent (#563)
1 parent e0b46c4 commit b07a588

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

.changeset/young-bars-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openai/agents-openai': patch
3+
---
4+
5+
fix: #562 invalid model settings when prompt is set in Agent

examples/basic/prompt-id.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ async function main() {
55
name: 'Assistant',
66
prompt: {
77
promptId: 'pmpt_68d50b26524c81958c1425070180b5e10ab840669e470fc7',
8-
version: '1',
98
variables: { name: 'Kaz' },
109
},
1110
});

packages/agents-openai/src/openaiResponsesModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ export class OpenAIResponsesModel implements Model {
878878
}
879879

880880
const requestData = {
881-
model: this.#model,
881+
...(!request.prompt ? { model: this.#model } : {}),
882882
instructions: normalizeInstructions(request.systemInstructions),
883883
input,
884884
include,

packages/agents-openai/test/openaiResponsesModel.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,36 @@ describe('OpenAIResponsesModel', () => {
7474
});
7575
});
7676

77+
it('omits model when a prompt is provided', async () => {
78+
await withTrace('test', async () => {
79+
const fakeResponse = { id: 'res-prompt', usage: {}, output: [] };
80+
const createMock = vi.fn().mockResolvedValue(fakeResponse);
81+
const fakeClient = {
82+
responses: { create: createMock },
83+
} as unknown as OpenAI;
84+
const model = new OpenAIResponsesModel(fakeClient, 'gpt-default');
85+
86+
const request = {
87+
systemInstructions: undefined,
88+
prompt: { promptId: 'pmpt_123' },
89+
input: 'hello',
90+
modelSettings: {},
91+
tools: [],
92+
outputType: 'text',
93+
handoffs: [],
94+
tracing: false,
95+
signal: undefined,
96+
};
97+
98+
await model.getResponse(request as any);
99+
100+
expect(createMock).toHaveBeenCalledTimes(1);
101+
const [args] = createMock.mock.calls[0];
102+
expect('model' in args).toBe(false);
103+
expect(args.prompt).toMatchObject({ id: 'pmpt_123' });
104+
});
105+
});
106+
77107
it('normalizes systemInstructions so empty strings are omitted', async () => {
78108
await withTrace('test', async () => {
79109
const fakeResponse = {

0 commit comments

Comments
 (0)