Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-dogs-reason.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ai-sdk/open-responses": patch
---

Preserve assistant reasoning parts when converting prompts to Open Responses input.
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,35 @@ describe('convertToOpenResponsesInput', () => {
]
`);
});

it('should convert reasoning parts to reasoning items', async () => {
const result = await convertToOpenResponsesInput({
prompt: [
{
role: 'assistant',
content: [
{
type: 'reasoning',
text: 'Analyzing the problem step by step',
},
],
},
],
});

expect(result.input).toEqual([
{
type: 'reasoning',
summary: [],
content: [
{
type: 'reasoning_text',
text: 'Analyzing the problem step by step',
},
],
},
]);
});
});

describe('assistant messages with tool calls', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
InputTextContentParam,
OpenResponsesRequestBody,
OutputTextContentParam,
ReasoningItemParam,
RefusalContentParam,
} from './open-responses-api';

Expand Down Expand Up @@ -105,10 +106,19 @@ export async function convertToOpenResponsesInput({
const assistantContent: Array<
OutputTextContentParam | RefusalContentParam
> = [];
const reasoningItems: Array<ReasoningItemParam> = [];
const toolCalls: Array<FunctionCallItemParam> = [];

for (const part of content) {
switch (part.type) {
case 'reasoning': {
reasoningItems.push({
type: 'reasoning',
summary: [],
content: [{ type: 'reasoning_text', text: part.text }],
});
break;
}
case 'text': {
assistantContent.push({ type: 'output_text', text: part.text });
break;
Expand All @@ -129,6 +139,11 @@ export async function convertToOpenResponsesInput({
}
}

// Push reasoning as separate items
for (const reasoningItem of reasoningItems) {
input.push(reasoningItem);
}

// Push assistant message with text content if any
if (assistantContent.length > 0) {
input.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export type ReasoningItemParam = {
id?: string;
type: 'reasoning';
summary: ReasoningSummaryContentParam[];
content?: unknown;
content?: ReasoningTextContent[];
encrypted_content?: string;
};

Expand Down