feat(parsing): add support for Qwen tool call tokens and AST parsing#5546
Open
CodeRulerNo1 wants to merge 1 commit into
Open
feat(parsing): add support for Qwen tool call tokens and AST parsing#5546CodeRulerNo1 wants to merge 1 commit into
CodeRulerNo1 wants to merge 1 commit into
Conversation
15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When Qwen models emit tool calls in their native token format:
<|tool_call_start|>[tool_name(args)]<|tool_call_end|>They were not parsed or executed by
src/tool_parsing.py, causing them to fail and leak into user-facing assistant messages as raw text.This PR fixes the issue by:
_QWEN_TOOL_CALL_REregex pattern matching the start/end tags and parsing the function name + arguments._parse_qwen_tool_callwhich extracts argument keys/values using safe Python AST parsing (wrapping arguments in a dummy function call to evaluate keyword arguments) and falling back to a regex parser on syntax errors.parse_tool_blocksandstrip_tool_blocksso the call executes correctly and the raw tags/tokens are cleaned from user-facing text.tests/test_qwen_tool_call.py) covering empty arguments, multiple arguments, type coercion, and syntax recovery.Target branch
dev, notmain. All PRs land indev;mainis curated by the maintainer at each release. If your PR is onmainby accident, click "Edit" on this PR and change the base.Linked Issue
Fixes #5545
Type of Change
Checklist
devdocker compose uporuvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.How to Test
venv/bin/pytest tests/test_qwen_tool_call.pylist_email_accounts()andlist_emails(account="Gmail", ...)as well as clean stripping of the tokens.Visual / UI changes — REQUIRED if you touched anything that renders
Anything that changes what the UI looks like — buttons, icons, padding, colors, fonts, spacing, layout, CSS, HTML, SVG, or any
static/js/module that draws to the DOM — needs all of the following. PRs that change rendering without these WILL be closed.--red,--fg,--bg,--card,--border, etc.) — do not introduce new color values, font sizes, or spacing units.static/index.html) or plain text.Fira Code) for primary UI text. Don't override.Screenshots / clips
None (pure token parsing backend utility, UI layout remains unchanged).