Skip to content

fix: preserve additional_kwargs in tool-call messages for reasoning models#6150

Open
octo-patch wants to merge 1 commit intoFlowiseAI:mainfrom
octo-patch:fix/issue-6108-preserve-reasoning-kwargs-in-tool-calls
Open

fix: preserve additional_kwargs in tool-call messages for reasoning models#6150
octo-patch wants to merge 1 commit intoFlowiseAI:mainfrom
octo-patch:fix/issue-6108-preserve-reasoning-kwargs-in-tool-calls

Conversation

@octo-patch
Copy link
Copy Markdown

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:

Error in Agent node: 400 Item 'msg_xxxxx' of type 'message' was provided without its required 'reasoning' item: 'rs_xxxx'

This happens because when the agent receives an assistant response with tool calls, it pushes a reconstructed message object to the messages array — but omits additional_kwargs. For reasoning models, additional_kwargs contains the reasoning content (and structured reasoning items with IDs like rs_xxxx) that the OpenAI API requires to be present in subsequent API calls alongside their paired assistant messages.

Solution

Include additional_kwargs: response.additional_kwargs when pushing the assistant message in both handleToolCalls and handleResumedToolCalls. This preserves the reasoning items in the conversation history so the next LLM invocation satisfies the OpenAI API constraint.

Testing

  • Reproduce with an AgentFlow V2 using a gpt-5 (or o-series) model with reasoning enabled and at least one custom tool
  • Before fix: 400 error on the first tool-call round trip
  • After fix: agent completes the tool call and returns a response

…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.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in Agent node: 400 Item 'msg_xxxxx' of type 'message' was provided without its required 'reasoning' item: 'rs_xxxx'

1 participant