fix: use null instead of empty string for assistant tool-call messages#1094
Open
octo-patch wants to merge 1 commit into
Open
fix: use null instead of empty string for assistant tool-call messages#1094octo-patch wants to merge 1 commit into
octo-patch wants to merge 1 commit into
Conversation
When the researcher agent pushes an assistant message with tool_calls back into the conversation history, the content field was set to an empty string which violates the OpenAI API specification. The spec requires content to be null when tool_calls are present. Several OpenAI-compatible providers such as OpenRouter strictly validate this and throw errors like 'Error: is empty', causing all API requests to fail with a 500 error. Fixes ItzCrazyKns#1080
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1080
Problem
When the researcher agent completes an iteration and pushes an assistant message with
tool_callsback into the conversation history, thecontentfield was set to an empty string (''). This violates the OpenAI API specification, which requirescontentto benull(not'') whentool_callsare present.Several OpenAI-compatible providers such as OpenRouter strictly enforce this rule and reject assistant messages with empty string content, throwing errors like
Error: is empty. This caused all API calls via/api/searchto fail with a 500 error for users of such providers.Solution
AssistantMessage.contenttype fromstringtostring | nullinsrc/lib/types.tscontent: ''tocontent: nullinresearcher/index.tsfor the assistant message pushed when tool calls are presentformatHistory.tsto guard against null content with a?? ''fallbackTesting
convertToOpenAIMessagesfunction inopenaiLLM.tsalready acceptsnullcontent (it maps directly toChatCompletionAssistantMessageParamwhich typescontentasstring | null | ...)tool_callsis present,contentshould benullSummary by cubic
Set assistant message content to null when
tool_callsare present to match the OpenAI spec and stop 500s from strict providers like OpenRouter. Fixes #1080.AssistantMessage.contenttype tostring | null.content: nullinstead of''whentool_callsexist.?? ''fallback in history formatter to handle null content.Written for commit d28986d. Summary will update on new commits.