Repository navigation
fix(relayconvert): keep Responses custom tools on Claude and Gemini upstreams - #7636
Merged
Merged
Conversation
A Chat Completions tool call without a function name cannot become a valid Responses function_call item, so the non-stream conversion now skips it instead of emitting an item with an empty name.
A streamed tool call is no longer announced while it has no function name, whether or not custom tools are in play. A call whose name never arrives is left out of the stream and the completed response. A call ID that arrives after the first fragment becomes the item ID as long as the item has not been announced yet.
The two standalone stream tests repeated what the nameless-tool hold test already covers. Their distinct checks now live in its subtests: a held function call without custom tools, its late call ID becoming the item ID, and calls whose name never arrives leaving no event, output index or sequence number behind, with and without custom tools.
…pstreams
Responses requests sent to Claude Messages dropped Codex custom tools
such as exec and apply_patch as unsupported hosted tools, and Gemini
omitted their definitions and stripped custom_tool_call history before
conversion. A forced custom tool_choice was rejected on both targets,
and Claude parsed JSON-looking custom tool input from history.
Claude and Gemini now get the same treatment as Chat Completions: each
custom tool is sent as a function that takes one string input, with
the grammar kept in the description, and a forced custom tool_choice
becomes the matching named tool choice when that tool was sent. Gemini
declarations go through the usual parameter cleanup.
custom_tool_call history replays the raw input as {"input": ...} on
both targets, and its outputs pair with the call as tool results. The
custom tool selection is shared by all three targets and recorded for
each of them, so the existing Chat to Responses step restores
custom_tool_call items from Claude and Gemini responses as well.
…responses Claude and Gemini responses reach the Responses format through the Chat to Responses step, but only the Chat source had a restore test. The test is now table-driven over all three sources and checks the non-stream output item and the exact streamed custom tool events.
Contributor
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (13)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Javabcd
pushed a commit
to Javabcd/new-api
that referenced
this pull request
Oct 9, 2026
…pstreams (QuantumNous#7636) * fix(relayconvert): drop unnamed function calls from Responses output A Chat Completions tool call without a function name cannot become a valid Responses function_call item, so the non-stream conversion now skips it instead of emitting an item with an empty name. * fix(relayconvert): hold streamed tool calls until a name arrives A streamed tool call is no longer announced while it has no function name, whether or not custom tools are in play. A call whose name never arrives is left out of the stream and the completed response. A call ID that arrives after the first fragment becomes the item ID as long as the item has not been announced yet. * test(relayconvert): fold unnamed stream tool cases into the hold test The two standalone stream tests repeated what the nameless-tool hold test already covers. Their distinct checks now live in its subtests: a held function call without custom tools, its late call ID becoming the item ID, and calls whose name never arrives leaving no event, output index or sequence number behind, with and without custom tools. * fix(relayconvert): keep Responses custom tools on Claude and Gemini upstreams Responses requests sent to Claude Messages dropped Codex custom tools such as exec and apply_patch as unsupported hosted tools, and Gemini omitted their definitions and stripped custom_tool_call history before conversion. A forced custom tool_choice was rejected on both targets, and Claude parsed JSON-looking custom tool input from history. Claude and Gemini now get the same treatment as Chat Completions: each custom tool is sent as a function that takes one string input, with the grammar kept in the description, and a forced custom tool_choice becomes the matching named tool choice when that tool was sent. Gemini declarations go through the usual parameter cleanup. custom_tool_call history replays the raw input as {"input": ...} on both targets, and its outputs pair with the call as tool results. The custom tool selection is shared by all three targets and recorded for each of them, so the existing Chat to Responses step restores custom_tool_call items from Claude and Gemini responses as well. * test(relayconvert): cover custom tool restore from Claude and Gemini responses Claude and Gemini responses reach the Responses format through the Chat to Responses step, but only the Chat source had a restore test. The test is now table-driven over all three sources and checks the non-stream output item and the exact streamed custom tool events. * test(gemini): assert custom tools survive the Responses to Gemini adaptor path --------- Co-authored-by: Kabuda <495696116@qq.com>
1 of 5 tasks
12 tasks
timwenx
pushed a commit
to timwenx/new-api
that referenced
this pull request
Nov 18, 2026
…pstreams (QuantumNous#7636) * fix(relayconvert): drop unnamed function calls from Responses output A Chat Completions tool call without a function name cannot become a valid Responses function_call item, so the non-stream conversion now skips it instead of emitting an item with an empty name. * fix(relayconvert): hold streamed tool calls until a name arrives A streamed tool call is no longer announced while it has no function name, whether or not custom tools are in play. A call whose name never arrives is left out of the stream and the completed response. A call ID that arrives after the first fragment becomes the item ID as long as the item has not been announced yet. * test(relayconvert): fold unnamed stream tool cases into the hold test The two standalone stream tests repeated what the nameless-tool hold test already covers. Their distinct checks now live in its subtests: a held function call without custom tools, its late call ID becoming the item ID, and calls whose name never arrives leaving no event, output index or sequence number behind, with and without custom tools. * fix(relayconvert): keep Responses custom tools on Claude and Gemini upstreams Responses requests sent to Claude Messages dropped Codex custom tools such as exec and apply_patch as unsupported hosted tools, and Gemini omitted their definitions and stripped custom_tool_call history before conversion. A forced custom tool_choice was rejected on both targets, and Claude parsed JSON-looking custom tool input from history. Claude and Gemini now get the same treatment as Chat Completions: each custom tool is sent as a function that takes one string input, with the grammar kept in the description, and a forced custom tool_choice becomes the matching named tool choice when that tool was sent. Gemini declarations go through the usual parameter cleanup. custom_tool_call history replays the raw input as {"input": ...} on both targets, and its outputs pair with the call as tool results. The custom tool selection is shared by all three targets and recorded for each of them, so the existing Chat to Responses step restores custom_tool_call items from Claude and Gemini responses as well. * test(relayconvert): cover custom tool restore from Claude and Gemini responses Claude and Gemini responses reach the Responses format through the Chat to Responses step, but only the Chat source had a restore test. The test is now table-driven over all three sources and checks the non-stream output item and the exact streamed custom tool events. * test(gemini): assert custom tools survive the Responses to Gemini adaptor path --------- Co-authored-by: Kabuda <495696116@qq.com>
xiaolanawaqaq
pushed a commit
to xiaolanawaqaq/new-apiaaa
that referenced
this pull request
Nov 26, 2026
…pstreams (QuantumNous#7636) * fix(relayconvert): drop unnamed function calls from Responses output A Chat Completions tool call without a function name cannot become a valid Responses function_call item, so the non-stream conversion now skips it instead of emitting an item with an empty name. * fix(relayconvert): hold streamed tool calls until a name arrives A streamed tool call is no longer announced while it has no function name, whether or not custom tools are in play. A call whose name never arrives is left out of the stream and the completed response. A call ID that arrives after the first fragment becomes the item ID as long as the item has not been announced yet. * test(relayconvert): fold unnamed stream tool cases into the hold test The two standalone stream tests repeated what the nameless-tool hold test already covers. Their distinct checks now live in its subtests: a held function call without custom tools, its late call ID becoming the item ID, and calls whose name never arrives leaving no event, output index or sequence number behind, with and without custom tools. * fix(relayconvert): keep Responses custom tools on Claude and Gemini upstreams Responses requests sent to Claude Messages dropped Codex custom tools such as exec and apply_patch as unsupported hosted tools, and Gemini omitted their definitions and stripped custom_tool_call history before conversion. A forced custom tool_choice was rejected on both targets, and Claude parsed JSON-looking custom tool input from history. Claude and Gemini now get the same treatment as Chat Completions: each custom tool is sent as a function that takes one string input, with the grammar kept in the description, and a forced custom tool_choice becomes the matching named tool choice when that tool was sent. Gemini declarations go through the usual parameter cleanup. custom_tool_call history replays the raw input as {"input": ...} on both targets, and its outputs pair with the call as tool results. The custom tool selection is shared by all three targets and recorded for each of them, so the existing Chat to Responses step restores custom_tool_call items from Claude and Gemini responses as well. * test(relayconvert): cover custom tool restore from Claude and Gemini responses Claude and Gemini responses reach the Responses format through the Chat to Responses step, but only the Chat source had a restore test. The test is now table-driven over all three sources and checks the non-stream output item and the exact streamed custom tool events. * test(gemini): assert custom tools survive the Responses to Gemini adaptor path --------- Co-authored-by: Kabuda <495696116@qq.com>
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.
🔗 关联任务 / Related Issue
🚀 变更类型 / Type of change
📝 变更描述 / Description
Codex 以 Responses 协议发送的
exec/apply_patch(type:"custom")工具,在上游为 Claude Messages 或 Gemini generateContent 时会被整体丢弃:Claude 把定义当作unsupported_hosted_tool,Gemini 的预处理把定义和custom_tool_call历史一起删掉,强制tool_choice也被拒绝。结果是模型不知道自己打过哪些 patch,或退回去调用不存在的工具。改动全部在
relaykit/relayconvert/:{input: string}的 function 发送,grammar 写进 description;Gemini 的声明走现有的参数清洗。tool_choice {"type":"custom"}在 Claude 转成{"type":"tool"},在 Gemini 转成ANY+allowedFunctionNames,仅当该工具确实被发出时才转换。custom_tool_call在 Claude / Gemini 一律回放为{"input": 原始字符串},不再被ObjectValue解析成 JSON;custom_tool_call_output与调用配对。to_gemini_chat_req_preprocess.go:ExtractRequest在转换器运行前已清空顶层 tools,它的工具过滤是死代码,历史过滤由转换取代。ResponsesToolState。响应侧不改:Claude / Gemini → Responses 本来就经过 Chat → Responses 那一步,复用现有还原逻辑。host 侧只改写了
relay/channel/gemini/adaptor_responses_test.go中断言旧丢弃行为的测试。📸 运行证明 / Proof of Work
新增 / 调整的测试:
internal/toolconv/policy_test.go:Claude、Gemini 的定义、tool_choice、重名诊断;Strict 策略下报ConversionLossError。request_registry_test.go:三个目标都记录ResponsesToolState,无 custom 工具的重试清空;Claude / Gemini 历史里"{\"a\":1}"、"[1,2]"、普通文本都保持原串;Gemini 的functionResponse.name由callNames补齐,call_id 属于 custom 调用的function_call_output不再被删。response_registry_test.go:Chat、Claude、Gemini 非流式还原为custom_tool_call;Claude 和 Gemini 流式事件序列output_item.added→custom_tool_call_input.delta→custom_tool_call_input.done→output_item.done。未验证:没有对真实 Claude / Gemini 上游和真实 Codex 做端到端探测。
✅ 提交前检查项 / Checklist
New feature,我已关联对应 Issue;若尚无 Issue,我已先自行创建。go build通过或测试通过,不视为有效证明。🤖 Generated with Claude Code