-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Description
When web search results are returned, AI SDK enqueues either a tool-result
or tool-error
chunk based on whether web search was successful or not. However, the OpenAI implementation in AI SDK doesn't check if the web search was successful or not and always enqueues a tool-result
chunk. See:
ai/packages/openai/src/responses/openai-responses-language-model.ts
Lines 1011 to 1034 in 418e18f
} else if (value.item.type === 'web_search_call') { | |
ongoingToolCalls[value.output_index] = undefined; | |
controller.enqueue({ | |
type: 'tool-input-end', | |
id: value.item.id, | |
}); | |
controller.enqueue({ | |
type: 'tool-call', | |
toolCallId: value.item.id, | |
toolName: 'web_search', | |
input: JSON.stringify({ action: value.item.action }), | |
providerExecuted: true, | |
}); | |
controller.enqueue({ | |
type: 'tool-result', | |
toolCallId: value.item.id, | |
toolName: 'web_search', | |
result: { status: value.item.status }, | |
providerExecuted: true, | |
}); | |
} else if (value.item.type === 'computer_call') { |
A fix would be to check the status
field (described briefly in the example in OpenAI docs) and enqueue a tool-result
or error
based on the value of the status field.
Also another issue I noticed there isn't a guideline on what should be included in the input/output of a web search tool call result, so AI SDK seems to currently set the input to the action returned in the web search result (which could be of various types, like 'search', 'find', etc and may include query and sources), so it feels slightly incorrect to include the whole thing into input and set output to just the status. This is also inconsistent with Anthropic's implementation. I can create another issue discussing this in detail if you'd like.
AI SDK Version
- @ai-sdk/openai: 2.0.44
- ai: 5.0.60
Code of Conduct
- I agree to follow this project's Code of Conduct