Skip to content

fix(adapters): ignore empty function_call from streaming deltas - #1031

Merged
dingyi222666 merged 1 commit into
v1-devfrom
fix/openai-function-calling
Aug 28, 2026
Merged

dingyi222666 merged 1 commit into
v1-devfrom
fix/openai-function-calling

Conversation

@dingyi222666

Copy link
Copy Markdown
Member

问题

群友反馈(issue #1027):使用中转站(如 openlux)的 deepseek-v4-flash-0731 时,Agent 陷入循环,持续调用模型直到 iteration limit(105 轮)。模型每轮输出空工具调用 tool_calls: [{"name":"","args":{}}]

根因

某些 DeepSeek V4 中转站在流式工具调用的收尾 chunkfinish_reason: "tool_calls")里返回空 function_call 对象{"arguments":"","name":""}),而非规范要求的 null(已在 openlux API 实测复现)。

ChatLuna 的 convertDeltaToMessageChunk 把该空对象透传进 additional_kwargs.function_call,而 agent 的动态解析器切换逻辑(createOpenAIAgent):

const hasFunction = input.additional_kwargs?.function_call != null
if (hasTools && parser是functions)  切到 tools
else if (hasFunction && parser是tools)  切到 functions parser

检测到残留的 function_call 后把解析器从 OpenAIToolsAgentOutputParser 切到 OpenAIFunctionsAgentOutputParser,后者读取空 function_call 返回 tool: "" 的 AgentAction,executor 找不到空名工具,错误 observation 喂回模型后再次输出同样结果,循环直到 iteration limit。

修复

packages/shared-adapter/src/utils.tsconvertDeltaToMessageChunk 只在 function_call 含实际内容(name 或 arguments 非空)时才透传,忽略空对象。

验证

  • openlux 实测复现空 function_call chunk
  • 修复后空 function_call 不再进入 additional_kwargs(chunks 14→13),tool_calls 正确聚合,两轮工具调用正常

Closes #1027

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.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@dingyi222666
dingyi222666 merged commit 44bb348 into v1-dev Aug 28, 2026
2 of 3 checks passed
@dingyi222666
dingyi222666 deleted the fix/openai-function-calling branch August 28, 2026 22:57
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b3ca7f45-44ca-45e1-a892-31d67e3932c0

📥 Commits

Reviewing files that changed from the base of the PR and between d1a480a and 7b807ed.

📒 Files selected for processing (1)
  • packages/shared-adapter/src/utils.ts

Walkthrough

本次修改更新 convertDeltaToMessageChunk。当 delta.function_callnamearguments 均为空时,函数调用不会写入消息块。

Changes

函数调用过滤

Layer / File(s) Summary
消息块函数调用转换
packages/shared-adapter/src/utils.ts
convertDeltaToMessageChunk 忽略内容为空的 delta.function_call,并保留非空函数调用的转换行为。

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

小兔检查消息流,
空函数调用不再留。
有名有参继续走,
消息块中写得周。
循环踪迹轻轻收。

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/openai-function-calling

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

[Bug] 群聊一次回复后 Agent 进入循环,持续调用模型直到 iteration limit

1 participant