Repository navigation
Conversation
WalkthroughThe Responses-to-chat conversion now recognizes reasoning inputs, preserves reasoning across tool-call sequences, attaches it to assistant messages without duplication, and treats ChangesReasoning preservation
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
service/relayconvert/internal/oai_responses/to_oai_chat_req.go (1)
169-219: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated boilerplate between
function_callandcustom_tool_callcases.Both branches follow the identical build→appendPendingReasoning→appendToolCallToLastAssistant→attach sequence, differing only in which constructor is called. Extracting a shared helper reduces duplication and centralizes the reasoning-attachment logic (which is exactly where the bugs above live) in one place.
♻️ Proposed refactor
+func responsesToolCallItemToChatMessages(item map[string]any, messages []dto.Message, pendingReasoning *string, build func(map[string]any) (dto.ToolCallRequest, error)) ([]dto.Message, error) { + toolCall, err := build(item) + if err != nil { + return nil, err + } + appendPendingReasoning(pendingReasoning, responsesItemReasoningText(item)) + messages = appendToolCallToLastAssistant(messages, toolCall) + attachPendingReasoningToLastAssistant(messages, pendingReasoning) + return messages, nil +} + case responsesInputTypeFunctionCall: - toolCall, err := responsesFunctionCallItemToChatToolCall(item) - if err != nil { - return nil, err - } - appendPendingReasoning(pendingReasoning, responsesItemReasoningText(item)) - messages = appendToolCallToLastAssistant(messages, toolCall) - attachPendingReasoningToLastAssistant(messages, pendingReasoning) - return messages, nil + return responsesToolCallItemToChatMessages(item, messages, pendingReasoning, responsesFunctionCallItemToChatToolCall) case responsesInputTypeCustomToolCall: - toolCall, err := responsesCustomToolCallItemToChatToolCall(item) - if err != nil { - return nil, err - } - appendPendingReasoning(pendingReasoning, responsesItemReasoningText(item)) - messages = appendToolCallToLastAssistant(messages, toolCall) - attachPendingReasoningToLastAssistant(messages, pendingReasoning) - return messages, nil + return responsesToolCallItemToChatMessages(item, messages, pendingReasoning, responsesCustomToolCallItemToChatToolCall)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@service/relayconvert/internal/oai_responses/to_oai_chat_req.go` around lines 169 - 219, Refactor responsesInputItemToChatMessages by extracting the shared tool-call handling sequence from the responsesInputTypeFunctionCall and responsesInputTypeCustomToolCall cases into a helper. The helper should accept the appropriate tool-call constructor result, pendingReasoning, and messages, then perform appendPendingReasoning, appendToolCallToLastAssistant, and attachPendingReasoningToLastAssistant; keep each case responsible only for constructing the correct tool call and propagating errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@service/relayconvert/internal/oai_responses/to_oai_chat_req.go`:
- Around line 239-244: Update appendPendingReasoning and appendReasoningContent
so separately flushed reasoning segments are joined with a consistent delimiter,
preserving readable boundaries across reasoning→tool-call rounds. Replace
whole-buffer equality checks with segment-aware deduplication that prevents
replayed or overlapping reasoning from being appended while retaining distinct
content.
- Around line 246-256: Update attachPendingReasoningToLastAssistant so it checks
that the last message is an assistant before clearing *pending or extracting it
for attachment. Preserve pending reasoning unchanged when messages are empty or
the last message has another role, and clear it only after
appendReasoningContent successfully attaches it.
---
Nitpick comments:
In `@service/relayconvert/internal/oai_responses/to_oai_chat_req.go`:
- Around line 169-219: Refactor responsesInputItemToChatMessages by extracting
the shared tool-call handling sequence from the responsesInputTypeFunctionCall
and responsesInputTypeCustomToolCall cases into a helper. The helper should
accept the appropriate tool-call constructor result, pendingReasoning, and
messages, then perform appendPendingReasoning, appendToolCallToLastAssistant,
and attachPendingReasoningToLastAssistant; keep each case responsible only for
constructing the correct tool call and propagating errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d258f47e-7b34-4ed7-9975-3f3dd8cb88f8
📒 Files selected for processing (2)
service/relayconvert/internal/oai_responses/to_oai_chat_req.goservice/relayconvert/internal/oai_responses/to_oai_chat_req_test.go
|
由于当前仓库限制同一作者同时维护的开放 PR 数量,先暂时关闭。本分支和提交会保留;该补丁基于 relaykit 迁移前的 service/relayconvert 路径,后续会适配当前 relaykit 目录并补齐评审意见后再重新提交。 |
Important
Note
实现、最小复现和描述初稿由 OpenAI Codex 协助完成;我已经确认了问题、修复和测试
📝 变更描述 / Description
Responses→Chat 请求转换此前未识别 standalone
reasoninginput item,也没有保留 function/custom tool call 上内联的reasoning_content。在 Agent 多轮工具调用历史中,这会让转换后的 assistanttool_calls缺少 reasoning;严格要求完整回传 reasoning 的 Chat Completions 上游会在下一轮返回 HTTP 400。这个bug会影响到小米mimo在Codex中的调用,会出现只输出一句话就完成的问题,小米文档:Agent 多轮会话开启深度思考且历史存在工具调用时,后续请求必须完整回传带工具调用 assistant 的 reasoning_content,没回传的话就会 400 文档:https://mimo.mi.com/docs/zh-CN/usage-guide/passing-back-reasoning_content。本改动仅修改 Responses 请求转换层:
reasoningitem,并绑定到拥有工具调用的 assistant message;summary、New API 生成的content,以及内联reasoning_content/reasoning;previous_response_id状态管理。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
reasoning_content的映射关系。📸 运行证明 / Proof of Work
同一个回归测试仅应用到未修复的
main @ 1721144时:应用本 PR 后,同一测试通过:
完整验证: