Skip to content

fix: the CUDA server types Qwen tool parameters by the tool's schema - #75

Closed
MiaAI-Lab wants to merge 1 commit into
ashhart:mainfrom
MiaAI-Lab:fix/cuda-typed-tool-parameters
Closed

MiaAI-Lab wants to merge 1 commit into
ashhart:mainfrom
MiaAI-Lab:fix/cuda-typed-tool-parameters

Conversation

@MiaAI-Lab

Copy link
Copy Markdown
Contributor

TL;DR: on CUDA, a Qwen tool call's array, object, number and boolean parameters reach the client as JSON strings. With this change they arrive as typed JSON values, as the Mac server has returned them since 0.3.5 (#28). It changes 6 lines in cuda/reply_text.py and reuses the Mac server's decode_parameter.

The problem

Qwen3.8 writes tool calls as <function=name><parameter=k>value</parameter></function>. The Mac server decodes each value by the tool's JSON schema (tool_parameters.decode_parameter, from #28). cuda/reply_text.parse_tool_calls never got that step and keeps every value as text. For example, a research agent's finish(paths: array) call on a DGX Spark (0.3.6.2, Qwen3.8 Flash Next, MLX 4-bit):

before: {"paths":"[\"https://a.example/1\", \"https://b.example/2\"]"}
after:  {"paths":["https://a.example/1","https://b.example/2"]}

Clients that validate arguments against the schema reject the call, and clients that don't pass a string where the tool expects a list.

The change

parse_tool_calls builds parameter_schemas(tools) once per reply. Each <parameter> value then goes through decode_parameter(value, schema), the same function and rules the Mac server uses:

  • array, object, boolean, integer, number and null parameters decode when the text is valid JSON of that type;
  • anything else keeps its exact text, including strings, untyped parameters, parameters missing from the schema, and text that isn't valid JSON of the declared type.

JSON-bodied and GLM calls are unchanged: they were already typed.

Tests

  • tests/test_tool_parameter_types.py: the existing parametrized check (8 kinds × 3 stream steps) now also runs the CUDA parser, with and without max_calls.
  • tests/test_glm_tool_calls.py::test_qwen_function_blocks_are_unchanged: this test pinned the difference ("the CUDA server keeps them as text", added in 1fc5915). It now expects days: 3 from both parsers. If that difference was deliberate, say so and I'll rework this.
  • Without the fix, the updated tests fail 16 cases; with it they pass.
  • Tool-call and server tests in nvcr.io/nvidia/pytorch:26.07-py3 (test_tool_*, test_glm_tool_calls, test_cuda_tool_choice, test_cuda_server_stream, test_server_openai_compat): 132 passed, 5 skipped, 2 failed. The 2 failures are in test_tool_parameters_null.py::test_http_* and fail the same way on unmodified main, because they import mlx, which isn't available on Linux.
  • Live check on one DGX Spark (tensorfold serve Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP --parallel 4 --kv-dtype int8): a finish(paths: array) call returns paths as a JSON array, both streamed and non-streamed.

🤖 Generated with Claude Code

The Mac server has decoded Qwen `<parameter=k>` values by the tool's JSON
schema since 0.3.5 (ashhart#28); the CUDA server's parser still returned every
value as a string, so an array parameter reached the client as
"[\"a\", \"b\"]" instead of ["a", "b"] and strict clients rejected the call.

cuda/reply_text.parse_tool_calls now runs each value through the same
tool_parameters.decode_parameter the Mac server uses: array, object,
boolean, integer, number and null parameters decode when the text is valid
JSON of that type, anything else keeps its exact text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ashhart

ashhart commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Thank you, @MiaAI-Lab. Typed tool arguments on CUDA are in 0.3.6.3 under your name (fe2b5147). The difference in
that test wasn't deliberate: CUDA just never got the Mac's decode step, so we updated the CUDA stop-string and
single-call tests to expect 2, not "2". We also made the two null-parameter HTTP tests skip where MLX is absent,
so the Linux run you described is clean. Thanks for the overnight testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

landed Landed on main by the maintainers; the commits keep the contributor's authorship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants