tool-call
: Qwen3 Coder chat format support
#15162
Draft
+369
−27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP! Will fix #15012 & #15046 when done.
Depends on Minja fixes: #15161
Qwen3 Coder has a weird syntax for tool calls: a Qwen2-esque
<tool_call>\n<function=${fn_name}>...</function></tool_call>
, except the parameters aren't a JSON object. Instead they're a succession of XML-ish parameters:<parameter=${name}>\n${typeof value === 'string' : value : JSON.stringify(value)}\n</parameter>\n
This special treatment of strings technically means it's impossible for the model to output a call argument string that contains the substring
</parameter>
(probably avoided having to train the model to do proper JSON string escapes?). This is quite unfortunate tbh. I don't think we should follow it to the letter. In this PR I'm just constraining the format to be:<parameter=${name}>\n${JSON.stringify(value)}\n</parameter>\n
(that is, string arguments will have quotes and their content will need to be escaped)