Repository navigation
工具参数解析时大整数精度丢失(业务 ID 被舍入)——修复补丁 #6002
yellowzhou
started this conversation in
General
Replies: 1 comment
|
The independent snapshot-boundary finding and exact-integer transport proposal are now tracked in a separate discussion. That report includes the standalone reproduction and validation scope, and links back here for the related argument-parsing issue. This comment has been shortened to keep the detailed report in one place. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
问题
模型输出的工具调用参数里,超出
Number.MAX_SAFE_INTEGER的大整数(如各类业务 ID)在JSON.parse后精度丢失。使用 Qwen3.6-35B-A3B-FP8 可稳定复现该问题。
复现:给模型的输入包含
模型输出:
{ "user_id": 900719925474099123, "order_id": 1234567890123456789, "category_id": "b3f1c9d24e7a4f0e9c1a2b3c4d5e6f70" }parseArguments里JSON.parse之后变成900719925474099100、1234567890123456800,最终下发到请求头/参数即为错误值。原因
packages/core/agent-loop/src/tool-calls.ts的parseArguments直接JSON.parse(raw),19 位整数被双精度浮点表示后四舍五入;另外模型把声明为string的 ID 字段写成数字时,也没有按 schema 还原类型。修复
1.
packages/core/agent-loop/src/tool-calls.tsparseArguments改为接收工具声明的parametersschema,先给超限整数字面量加引号再解析,随后按 schema 强转类型:调用点同步传入 schema:
2.
packages/client/ui-trajectory/src/client/TrajectoryTable.tsx轨迹表格展示 Payload 时同样走了
JSON.parse,大整数 ID 会显示成舍入后的值。这里复用同一套 token 扫描逻辑,只对展示解析生效:function parseJsonContainer(value: string): object | undefined { try { - const parsed: unknown = JSON.parse(value) + const parsed: unknown = JSON.parse(quoteUnsafeIntegers(value)) return typeof parsed === 'object' && parsed !== null ? parsed : undefined } catch { return undefined3.
packages/core/agent-loop/tests/tool-calls.spec.ts新增
schema-aware argument parsing测试组,共 9 个用例:运行:
pnpm --filter @deepseek-ai/dsh-agent-loop test -- tool-calls变更文件
packages/core/agent-loop/src/tool-calls.tsparseArguments保留大整数精度 + 按 schema 强转类型(+71)packages/core/agent-loop/tests/tool-calls.spec.tspackages/client/ui-trajectory/src/client/TrajectoryTable.tsxAll reactions