Skip to content

server: DSML tool calls stream their arguments as they are written - #2191

Merged
ashhart merged 5 commits into
mainfrom
lead/dsml-stream
Nov 5, 2026
Merged

ashhart merged 5 commits into
mainfrom
lead/dsml-stream

Conversation

@ashhart

@ashhart ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

DeepSeek-V4 and V4.1 tool calls now stream their arguments as they are written, like GLM and XML calls already do (#1975). Before, a DSML call arrived in one piece at the block's closer, so a client saw nothing while a long file was being written.

On the issue's probe (a 2,000-character Write, fed 3 bytes at a time, host only), DSML goes from 1 argument delta at byte 2249 to 671 deltas, the first at byte 165. GLM and Qwen XML are unchanged.

When a call's header goes out. A DSML block is validated as a whole, so a header sent at the name could announce a call the whole reply then rejects, and two of #684's containment tests would fail. So the header waits until the first parameter is whole and the next tag has been written. The cost is that the first parameter's value isn't streamed: file_path first streams the large value, while a call whose first parameter is the large one sends nothing until it closes.

What else changes

  • /v1/messages and /v1/responses get one delta per arguments piece. The Messages route has a test; Responses follows by construction and isn't tested end to end.
  • stream: false with finish_reason: "length", cut inside a DSML call after its header: the reply now returns the cut call as the stream sent it, as GLM and XML do, where before it kept the open block in content.
  • A block that breaks after a header went out: the stream has sent that call, while the whole reply keeps the block as text. Same kind of gap as GLM and XML, pinned by a test.

Unchanged: requests without tools, parallel_tool_calls: false, reasoning text, XML and GLM calls, strict tools, and every block that breaks before its first header.

Host tests only: no GPU, model or timing runs. The issue's measurements on DeepSeek-V4.1 hardware still need someone with the model.

…1975)

A DSML block (<|DSML|tool_calls>, V4.1's <|DSML| calls> or the grammar's
<|DSML|function_calls>) used to wait for its closer and go out as one
header and one arguments delta per call. tool_dsml_stream.zig now reads the
block as tool_dsml.calls does, over resumed indexes: a call's header goes out
once its first parameter is whole in the block's spelling and that
spelling's next parameter opener or invoke closer follows, with the
arguments written so far in one piece; later string values go out as
JSON-escaped pieces (holding back a tail that could start a parameter,
invoke or block closer), typed values as compact JSON at their closer, and
the joined pieces equal the whole reply's arguments byte for byte.

A block that breaks before a header goes out (an unoffered name, mixed
spellings, junk, a bad flag or JSON value, a block closed with its invoke
open, a value the reply never closes) still waits for its closer and parses
whole, so it sends nothing, as before. A block cut by max_tokens after a
header is open, so the whole reply returns the cut call as the stream sent
it (#1238).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant