fix: reasoning_content DeepSeek — retry avec maxSteps=1 si erreur thinking mode
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 23s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Antigravity
2026-05-05 21:33:16 +00:00
parent b55f558a62
commit ab914f0587
2 changed files with 62 additions and 32 deletions

View File

@@ -119,25 +119,40 @@ export class CustomOpenAIProvider implements AIProvider {
async generateWithTools(options: ToolUseOptions): Promise<ToolCallResult> {
const { tools, maxSteps = 10, systemPrompt, messages, prompt } = options
const opts: Record<string, any> = {
model: this.model,
tools,
stopWhen: stepCountIs(maxSteps),
}
if (systemPrompt) opts.system = systemPrompt
if (messages) opts.messages = messages
else if (prompt) opts.prompt = prompt
const result = await aiGenerateText(opts as any)
return {
toolCalls: result.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
toolResults: result.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
text: result.text,
steps: result.steps?.map((step: any) => ({
const buildOpts = (steps: number): Record<string, any> => {
const opts: Record<string, any> = { model: this.model, tools, stopWhen: stepCountIs(steps) }
if (systemPrompt) opts.system = systemPrompt
if (messages) opts.messages = messages
else if (prompt) opts.prompt = prompt
return opts
}
const toResult = (r: any): ToolCallResult => ({
toolCalls: r.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
toolResults: r.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
text: r.text,
steps: r.steps?.map((step: any) => ({
text: step.text,
toolCalls: step.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
toolResults: step.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || []
})) || []
toolResults: step.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
})) || [],
})
try {
const result = await aiGenerateText(buildOpts(maxSteps) as any)
return toResult(result)
} catch (err: any) {
// DeepSeek reasoning/thinking models require reasoning_content to be passed back
// between multi-step calls, which the AI SDK doesn't handle via the OpenAI-compat layer.
// Retry with a single step so the model calls the tool directly.
const msg: string = err?.message || String(err)
if (msg.includes('reasoning_content') || msg.includes('thinking mode')) {
console.warn('[CustomOpenAI] Reasoning model detected — retrying with maxSteps=1')
const result = await aiGenerateText(buildOpts(1) as any)
return toResult(result)
}
throw err
}
}

View File

@@ -103,25 +103,40 @@ export class DeepSeekProvider implements AIProvider {
async generateWithTools(options: ToolUseOptions): Promise<ToolCallResult> {
const { tools, maxSteps = 10, systemPrompt, messages, prompt } = options
const opts: Record<string, any> = {
model: this.model,
tools,
stopWhen: stepCountIs(maxSteps),
}
if (systemPrompt) opts.system = systemPrompt
if (messages) opts.messages = messages
else if (prompt) opts.prompt = prompt
const result = await aiGenerateText(opts as any)
return {
toolCalls: result.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
toolResults: result.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
text: result.text,
steps: result.steps?.map((step: any) => ({
const buildOpts = (steps: number): Record<string, any> => {
const opts: Record<string, any> = { model: this.model, tools, stopWhen: stepCountIs(steps) }
if (systemPrompt) opts.system = systemPrompt
if (messages) opts.messages = messages
else if (prompt) opts.prompt = prompt
return opts
}
const toResult = (r: any): ToolCallResult => ({
toolCalls: r.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
toolResults: r.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
text: r.text,
steps: r.steps?.map((step: any) => ({
text: step.text,
toolCalls: step.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
toolResults: step.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || []
})) || []
toolResults: step.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
})) || [],
})
try {
const result = await aiGenerateText(buildOpts(maxSteps) as any)
return toResult(result)
} catch (err: any) {
// DeepSeek reasoning/thinking models require reasoning_content to be passed back
// between multi-step calls, which the AI SDK doesn't handle automatically.
// Retry with a single step so the model calls the tool directly without multi-turn.
const msg: string = err?.message || String(err)
if (msg.includes('reasoning_content') || msg.includes('thinking mode')) {
console.warn('[DeepSeek] Reasoning model detected — retrying with maxSteps=1')
const result = await aiGenerateText(buildOpts(1) as any)
return toResult(result)
}
throw err
}
}