Skip to content

Commit 1767bf4

Browse files
committed
fix: switch to text response format in Claude thinking patch
1 parent 2381d2c commit 1767bf4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

runner/codegen/ai-sdk-claude-thinking-patch.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const anthropicThinkingWithStructuredResponseMiddleware: LanguageModelV2M
2020
},
2121
];
2222
params.toolChoice = {type: 'auto'};
23-
23+
params.responseFormat = {type: 'text'};
2424
params.prompt.push({
2525
role: 'user',
2626
content: [
@@ -33,4 +33,16 @@ export const anthropicThinkingWithStructuredResponseMiddleware: LanguageModelV2M
3333
}
3434
return Promise.resolve(params);
3535
},
36+
wrapGenerate: async ({doGenerate}) => {
37+
const result = await doGenerate();
38+
39+
// Extract the JSON tool call (conforming to the schema) and return it as text response.
40+
for (const r of result.content) {
41+
if (r.type === 'tool-call' && r.toolName === 'json') {
42+
result.content.push({type: 'text', text: r.input});
43+
}
44+
}
45+
46+
return result;
47+
},
3648
};

0 commit comments

Comments
 (0)