fix(adapters): ignore empty function_call from streaming deltas - #1031
Merged
Merged
Conversation
Some DeepSeek V4 relays (e.g. openlux) emit an empty function_call object
({ arguments: '', name: '' }) on the final tool_calls chunk. This leaked
into additional_kwargs and made the agent see a phantom empty tool call,
causing a 105-iteration loop (chatluna issue #1027). Only keep
function_call when it carries an actual name or arguments.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Walkthrough本次修改更新 Changes函数调用过滤
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
✨ 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 |
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.
问题
群友反馈(issue #1027):使用中转站(如 openlux)的 deepseek-v4-flash-0731 时,Agent 陷入循环,持续调用模型直到 iteration limit(105 轮)。模型每轮输出空工具调用
tool_calls: [{"name":"","args":{}}]。根因
某些 DeepSeek V4 中转站在流式工具调用的收尾 chunk(
finish_reason: "tool_calls")里返回空 function_call 对象({"arguments":"","name":""}),而非规范要求的null(已在 openlux API 实测复现)。ChatLuna 的
convertDeltaToMessageChunk把该空对象透传进additional_kwargs.function_call,而 agent 的动态解析器切换逻辑(createOpenAIAgent):检测到残留的 function_call 后把解析器从
OpenAIToolsAgentOutputParser切到OpenAIFunctionsAgentOutputParser,后者读取空 function_call 返回tool: ""的 AgentAction,executor 找不到空名工具,错误 observation 喂回模型后再次输出同样结果,循环直到 iteration limit。修复
packages/shared-adapter/src/utils.ts:convertDeltaToMessageChunk只在 function_call 含实际内容(name 或 arguments 非空)时才透传,忽略空对象。验证
additional_kwargs(chunks 14→13),tool_calls 正确聚合,两轮工具调用正常Closes #1027