Repository navigation
[Feat] kimi-k3: Stream tool-call arguments incrementally - #48775
Merged
Merged
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
This was referenced Nov 6, 2026
…rip; skip nameless calls when streaming
Collaborator
Author
|
/rerun-test test_kimik3_detector.py test_serving_chat.py |
Contributor
|
🚀 |
Collaborator
Author
|
/tag-and-rerun-ci |
kpham-sgl
added a commit
that referenced
this pull request
Nov 10, 2026
kpham-sgl
added a commit
that referenced
this pull request
Nov 11, 2026
kpham-sgl
added a commit
that referenced
this pull request
Nov 11, 2026
4 of 5 tasks
4 of 5 tasks
This was referenced Nov 13, 2026
5 tasks done
ihciah
added a commit
to ihciah/sglang
that referenced
this pull request
Nov 30, 2026
Port sgl-project#48775 to sglang-processor. SGLang now streams a Kimi-K3 call's name and `{` once its header is complete, string values as they arrive and typed values once they close; the port still sent each call whole once `<|close|>call<|sep|>` arrived, so 28 of the 46 tool-parity cases had drifted. `kimi_k3.rs` streams through a port of `_stream_calls`, including skipping malformed XTML, and headers a call or tools close cuts short, as the one-shot parse does. A call the stream leaves open is incomplete, and a stop then does not finish as `tool_calls`: `ToolDetector::has_incomplete_call` carries that into `openai/chat.rs` and `parser/tools.rs`, as `serving_chat`'s `_incomplete_tool_call_indices` does. Regenerate `tool_parity/kimik3.json` and add malformed, cut-header and split-value inputs. In `openai_parity/kimi-k3.json`, update the two streamed tool cases and add `tools_stream_unclosed`, generated with Kimi-K3 on the OpenAI wire and its pre-sgl-project#45972 ids, which this path still writes.
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.
Port of #48414
Takes the Kimi-K3 tool-call streaming changes from #48414:
function_call/kimik3_detector.py, the incremental streaming, with its tests.ToolCallItem.source_textincore_types.py, the XTML each streamed delta came from. It is excluded from serialization; [Feat] kimi-k3: Shape chat responses to the K3 wire format #48777's K3 token provenance reads it.serving_chat.py, only the skip of incomplete calls in_check_for_unstreamed_tool_args.Left on the branch:
response_channel_open. Main's grammar already lets the output start inside the open response channel, and it still requires the tools section after that channel closes.$dynamicRefstrip beforecheck_schema. The metaschema gives$dynamicRefthe same format-only rule as$ref.kimik3_structural_tag.py. With xgrammar 0.2.7, main's strict grammar accepts a raw UTF-8 property name and rejects only its\u-escaped spelling, which constrained decoding never emits. The fallback dropped the whole argument to its bare type, so a wrong key, a wrong type, or a missing required property passed.Summary
KimiK3Detector.parse_streaming_incrementconverts XTML to JSON as it arrives. A string argument streams character by character, so it no longer waits for<|close|>call<|sep|>. A non-string argument is buffered until its close marker, which keeps the non-streaming decoder's string fallback for invalid JSON. A call with no tool name is skipped whole, as the non-streaming decoder does. EachToolCallItemcarries its XTMLsource_text.incomplete_tool_call_indices._check_for_unstreamed_tool_argsnow skips such a call at stream end instead of synthesizing its remaining arguments.Changes to existing code
incomplete_tool_call_indices(the response-template-driven detectors on main, besides K3): at stream end, a call that never closed is no longer completed with synthesized arguments./v1/responsesalready skips such calls.Verification
Unit tests, run locally (macOS, CPU, xgrammar 0.2.7 as pinned):
test_serving_chat.py: 181 passed and 1 failed. On main: 180 passed and the same 1 failed (test_streaming_created_is_stable_across_chunks), becausetml-renderersis not installed locally.function_calltests: 753 passed and 4 failed. On main: 747 passed and the same 4 failed (test_deepseekv41_detector.py).detect_and_parse. Every truncation point of a two-call stream leaves each closed call's arguments as valid JSON.pre-commit runpasses on the changed files.CI States
Latest PR Test (Base): 🚫 Run #42781532883
Latest PR Test (Extra): ❌ Run #42781532801
Latest PR Test (AMD ROCm 10): ⏳ Run #42781533054
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: