fix: preserve additional_kwargs in tool-call messages for reasoning models#6150
Open
octo-patch wants to merge 1 commit intoFlowiseAI:mainfrom
Open
Conversation
…odels (fixes FlowiseAI#6108) When an OpenAI reasoning model (gpt-5, o-series) responds with tool calls, the API associates a reasoning item (rs_xxxx) with the assistant message (msg_xxxx). Subsequent API calls must include that reasoning item in the message history or the API returns a 400 error: "Item 'msg_xxxx' of type 'message' was provided without its required 'reasoning' item: 'rs_xxxx'". The fix passes additional_kwargs from the response when pushing the assistant message to the messages array in both handleToolCalls and handleResumedToolCalls, so the reasoning content is preserved for the next LLM invocation.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the Agent_Agentflow class to include additional_kwargs when pushing LLM responses to the message history. This change ensures that reasoning items from models such as OpenAI's o-series are preserved, preventing 400 errors in subsequent API calls that require this context. I have no feedback to provide as there were no review comments.
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 #6108
Problem
When using an OpenAI reasoning model (gpt-5, o-series) with a tool assigned to an Agent node, the API returns a 400 error:
This happens because when the agent receives an assistant response with tool calls, it pushes a reconstructed message object to the
messagesarray — but omitsadditional_kwargs. For reasoning models,additional_kwargscontains the reasoning content (and structured reasoning items with IDs likers_xxxx) that the OpenAI API requires to be present in subsequent API calls alongside their paired assistant messages.Solution
Include
additional_kwargs: response.additional_kwargswhen pushing the assistant message in bothhandleToolCallsandhandleResumedToolCalls. This preserves the reasoning items in the conversation history so the next LLM invocation satisfies the OpenAI API constraint.Testing