Skip to content

fix(openai): generate fallback id for missing streaming tool calls#78

Merged
LIlGG merged 1 commit into
halo-dev:mainfrom
acanyo:main
Jul 3, 2026
Merged

fix(openai): generate fallback id for missing streaming tool calls#78
LIlGG merged 1 commit into
halo-dev:mainfrom
acanyo:main

Conversation

@acanyo

@acanyo acanyo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

部分 OpenAI-compatible 供应商在流式工具调用返回中,可能会省略 tool_calls[].id。例如 DashScope / 阿里云百炼在某些模型的工具调用流中只返回工具名称和参数增量,不返回 tool call id。

当前 AI Foundation 会将该空 id 继续转换为 Halo 的 tool-call stream part,最终触发校验失败:

tool-call stream part toolCallId must not be blank

导致 Agent 工具调用流程中断。

修改内容

  • 在 OpenAI-compatible ChatModel 解析流式 tool_calls 时,为缺失的 tool call id 生成兜底 id
  • 同一个流式工具调用 index 会复用同一个 fallback id,保证后续参数增量可以正确合并
  • 非流式 message.tool_calls 缺失 id 时也增加兜底处理
  • 工具调用 type 缺失时默认按 function 处理

修改前:
iShot Pro 2026-07-03 10 29 27

修改后:
Google Chrome 2026-07-03 10 30 50

@ruibaby ruibaby requested a review from LIlGG July 3, 2026 02:53
@LIlGG LIlGG merged commit be39657 into halo-dev:main Jul 3, 2026
1 check passed
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.

2 participants