Skip to content

fix(chat): normalize tool call arguments in assistant history - #1777

Merged
sufubao merged 3 commits into
ModelTC:mainfrom
sufubao:fix/glm5-tool-call-history
Dec 2, 2026
Merged

sufubao merged 3 commits into
ModelTC:mainfrom
sufubao:fix/glm5-tool-call-history

Conversation

@sufubao

@sufubao sufubao commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

历史工具调用里的 function.arguments 可能是截断的 JSON。GLM 等模型的聊天模板会对它调用 .items(),一条坏记录就能让后续每轮对话都构建 prompt 失败。

参考 vLLM 的消息处理,在所有模型共用的模板入口逐个处理 assistant 的工具调用。对象直接传给模板,JSON 对象字符串先解析。缺失、空、截断或非对象参数按 {} 渲染。异常日志只记录长度或类型。请求历史可以接收对象,OpenAI 普通响应和流式增量仍使用字符串。

用官方 GLM-5.3-Flash 模板重放了 5 条原始失败请求,每条生成的完整 prompt 都与只把损坏参数替换为 {} 的对照一致。工具调用、Anthropic 请求、推理参数和 DeepSeek V4 tokenizer 相关的 113 项测试通过。

@sufubao sufubao changed the title fix(glm5): handle malformed tool call arguments in chat history fix(chat): normalize tool call arguments in assistant history Dec 2, 2026
@sufubao
sufubao merged commit 950b916 into ModelTC:main Dec 2, 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.

1 participant