Skip to content

[Bugfix] Fix Kimi-K2 tool parser concatenated tool calls parsing#24847

Closed
yiyeguhu wants to merge 7 commits into
vllm-project:mainfrom
yiyeguhu:fix-kimi-k2-multiple-tool-calls-parsing-issue
Closed

[Bugfix] Fix Kimi-K2 tool parser concatenated tool calls parsing#24847
yiyeguhu wants to merge 7 commits into
vllm-project:mainfrom
yiyeguhu:fix-kimi-k2-multiple-tool-calls-parsing-issue

Conversation

@yiyeguhu

@yiyeguhu yiyeguhu commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

[Bugfix] Fix Kimi-K2 tool parser concatenated tool calls parsing

Purpose

  • Resolves GitHub issue [Bug]: Kimi-K2 tool parser may incorrectly parse multiple tool calls #24478
  • Fix regex pattern to handle concatenated tool calls without spacing
  • Use negative lookahead to prevent over-matching across tool call boundaries
  • Add comprehensive test cases for edge cases including angle brackets in JSON
  • Consolidate test cases into parametrized test for better maintainability

Test Plan

pytest tests/tool_use/test_kimi_k2_tool_parser.py

Test Result

All 11 tests pass, including 4 new test cases that validate the regex fix:

  • concatenated_tool_calls_bug_fix: Exact GitHub issue reproduction
  • three_concatenated_tool_calls: Scalability test
  • mixed_spacing_tool_calls: Robustness test
  • angle_brackets_in_json: Edge case with HTML in JSON

- Fix regex pattern to handle concatenated tool calls without spacing
- Use negative lookahead to prevent over-matching across tool call boundaries
- Add comprehensive test cases for edge cases including angle brackets in JSON
- Consolidate test cases into parametrized test for better maintainability
- Resolves GitHub issue vllm-project#24478

Signed-off-by: Thomas Mao <yiyeguhu@gmail.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a bug in the Kimi-K2 tool parser where concatenated tool calls were not parsed correctly. The fix involves updating the regular expression to be more specific and using a negative lookahead to prevent over-matching. The changes are well-supported by new, comprehensive test cases that cover various edge scenarios.

My review includes two main points:

  1. A suggestion to make the main regex robust to newlines in function arguments by adding the re.DOTALL flag.
  2. A suggestion to improve the new test cases by using json.dumps for creating expected argument strings, which enhances maintainability and ensures JSON validity, consistent with existing tests.

Comment thread vllm/entrypoints/openai/tool_parsers/kimi_k2_tool_parser.py Outdated
Comment thread tests/tool_use/test_kimi_k2_tool_parser.py

@chaunceyjiang chaunceyjiang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @MoyanZitto PTAL.

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors.

You ask your reviewers to trigger select CI tests on top of fastcheck CI.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

- Add re.DOTALL flag to tool_call_regex to ensure . matches newlines
- Add test case for pretty-printed JSON with newlines
- Addresses reviewer feedback about newline handling in function arguments

Signed-off-by: Thomas Mao <yiyeguhu@gmail.com>
- Replace hardcoded JSON strings with json.dumps() calls for better maintainability
- Use default json.dumps format to match actual parser output (with spaces)

Signed-off-by: Thomas Mao <yiyeguhu@gmail.com>
- Improve code formatting consistency
- Address pre-commit formatting requirements

Signed-off-by: Thomas Mao <yiyeguhu@gmail.com>
Signed-off-by: Thomas Mao <yiyeguhu@gmail.com>
@MoyanZitto

Copy link
Copy Markdown
Contributor

LGTM

@wizche

wizche commented Nov 11, 2025

Copy link
Copy Markdown

Why is this not being merged?

@chaunceyjiang chaunceyjiang added the ready ONLY add when PR is ready to merge/full CI is needed label Nov 11, 2025
@mehmetbaykar

Copy link
Copy Markdown

any update on this?

@bbartels

bbartels commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

@yiyeguhu Could you fix the pre-commit issues, all other tests seem to have passed!
See here: https://github.com/vllm-project/vllm/actions/runs/19263038741/job/55072168601?pr=24847

@chaunceyjiang

Copy link
Copy Markdown
Collaborator

@bbartels Could you help submit a new PR based on this one?

@bbartels

Copy link
Copy Markdown
Contributor

@bbartels Could you help submit a new PR based on this one?

@chaunceyjiang Have a look at #28831

@mergify

mergify Bot commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

Hi @yiyeguhu, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

@github-actions

github-actions Bot commented Mar 7, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this pull request should remain open. Thank you!

@github-actions

github-actions Bot commented Apr 6, 2026

Copy link
Copy Markdown

This pull request has been automatically closed due to inactivity. Please feel free to reopen if you intend to continue working on it. Thank you!

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

Labels

frontend ready ONLY add when PR is ready to merge/full CI is needed stale Over 90 days of inactivity tool-calling

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants