qwen3-coder tool call parser - #16755
Conversation
…r_edit Fix grammar, hide tool_call from output
Add missing closing brace to terminate test_template_output_parsers() function. This resolves compilation errors that prevented successful build of the test-chat target.
Co-authored-by: Kashyap Jois <kjois@iprdgroup.com>
Co-authored-by: Kashyap Jois <kjois@iprdgroup.com>
Co-authored-by: Marcel de Vries <marceldev89@gmail.com>
Co-authored-by: Marcel de Vries <marceldev89@gmail.com>
…d84/llama.cpp into qwen3-coder_tool_call_parser
…ranches; add tests
- chat-parser: support schema.type as array (e.g. ["number","null"]) in convert_qwen3_param_value()
- chat: resolve $refs; allow unions including "string" as freeform; sanitize empty {"not":{}} in anyOf/oneOf before add_schema
- tests: add Qwen3-Coder regression ensuring grammar builds with unions and ignores {"not":{}}
|
Anecdotally, I observed that the previous PR (and presumably this PR too) essentially fixed tool calling for qwen3-coder. Although when trying to use it with It would be nice to get this PR merged in. |
I guess you could test it through openrouter or something and check if you see the same behavior there as well. My guess would be that it's a model thing and not so much this PR. Or maybe even a codex thing since it's probably heavily optimized for GPT models in terms of system prompt and tool descriptions. |
|
Hey, just to confirm that running this branch fixes the integration with Qwen3-Coder-30B-A3B. Reproduction steps: PS: I opened too many tabs to figure it out, and I can’t find the sources any more to properly source them. I invented nothing here, credits goes to whoever wrote the pieces first. |
|
@MartyLake can you try also opencode if it works well? anomalyco/opencode#1890 |
|
This feature is really needed, please merge this PR as soon as possible. |
can confirm it does work well with opencode too. |
|
Hi, I'm using
and I'm getting incomplete tags from LLM responses like below - would this PR help? trying to figure if I should try to find out how to build it myself as I've seen reports how it helped elsewhere :) |
|
sorry for the silly question there above. this PR does help - thanks! |
|
Seems like another PR (#16932) was merged a few days ago that makes this obsolete. Giving it a quick test with Qwen3 Coder to see if it actually works. |
|
Alright, closing this in favor of the merged #16932. Seems to be working well. I'll keep this branch around just in case. :) |


Note
Original work and PR by bold84 @ #15019
This pull request resolves #15012 and introduces comprehensive support for the Qwen3-Coder model family's XML-based tool-calling format. It includes a new, robust XML parser and updated chat template detection logic to ensure reliable function calling.
Key Changes:
New XML Parser (
common/chat-parser.cpp):Chat Template Detection (
common/chat.h,common/chat.cpp):QWEN3_CODER_XMLformat is applied consistently, even when no tools are explicitly provided in the request.Comprehensive tests (
tests/test-chat.cpp):Known issues:
<tool_call>. This seems to be an issue with the model itself(?).