fix: Add tool_calls array to OpenAI chat completions response#34
Merged
CaddyGlow merged 2 commits intoJan 20, 2026
Merged
Conversation
The convert__anthropic_message_to_openai_chat__response function was not converting Anthropic tool_use blocks to OpenAI tool_calls format. This caused the finish_reason to be "tool_calls" but the actual tool_calls array was missing from the response message. This fix: - Adds handling for tool_use blocks in the response converter - Converts Anthropic tool_use format to OpenAI tool_calls format - Includes the tool_calls array in the message when present This is required for n8n AI Agent workflows and other OpenAI-compatible clients that rely on the tool_calls array to execute function calls. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Owner
|
Reused a shared helper to build OpenAI tool_calls for Anthropic adapters (streaming + non-streaming) to ensure consistent JSON serialization of function.arguments. Added unit coverage for tool_use -> tool_calls and strengthened the sample-based test on claude_messages_tools to assert tool names and JSON args. Tests: |
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.
Summary
This PR fixes a bug where the
convert__anthropic_message_to_openai_chat__responsefunction was not converting Anthropictool_useblocks to OpenAItool_callsformat in chat completion responses.The Problem:
When Claude returns a tool use response, the converter correctly set
finish_reason: "tool_calls"but the actualtool_callsarray was missing from the response message:{ "choices": [{ "finish_reason": "tool_calls", "message": { "role": "assistant", "content": "" // MISSING: "tool_calls": [...] } }] }The Fix:
This PR adds handling for
tool_useblocks in the response converter, converting them to the OpenAItool_callsformat:{ "choices": [{ "finish_reason": "tool_calls", "message": { "role": "assistant", "content": null, "tool_calls": [{ "id": "toolu_xxx", "type": "function", "function": { "name": "get_gmail", "arguments": "{}" } }] } }] }Use Case
This fix is required for n8n AI Agent workflows and other OpenAI-compatible clients that rely on the
tool_callsarray to execute function calls. Without this fix, the AI Agent sees the tools are available but Claude's tool call requests are lost in translation.Changes
tool_useblocks inconvert__anthropic_message_to_openai_chat__responseid,name,input) to OpenAI tool_calls format (id,type,function.name,function.arguments)contenttoNonewhen there's no text content (per OpenAI spec)jsonimport for serializing tool argumentsTest plan