Skip to content

fix(server): DeepSeek V4.1 tool calls in its own DSML format - #812

Merged
davide221 merged 1 commit into
mainfrom
fix/ds41-dsml-v41
Oct 6, 2026
Merged

davide221 merged 1 commit into
mainfrom
fix/ds41-dsml-v41

Conversation

@davide221

@davide221 davide221 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

DeepSeek V4.1 Flash writes tool calls in its own DSML spelling, with a leading space in each tag name:

<|DSML| calls>
<|DSML| invoke name="read_file">
<|DSML| parameter name="path" string="true">main.cpp</|DSML| parameter>
</|DSML| invoke>
</|DSML| calls>

The server rendered the V4 format for V4.1 (<|DSML|tool_calls>, no <|System|>, V4's reasoning-effort text) and parsed only the V4 spelling. Every V4.1 tool call failed with tool_call parse failed, so agents on V4.1 could not call tools. The V4.1 format comes from chat_template.jinja and encoding/encoding.py in the deepseek-ai/DeepSeek-V4.1-Flash repo ("V4.1 changes relative to V4").

Impact

10 tool prompts (two tools, with and without 9K tokens of context), temperature 0, OpenAI tools API, on an R9700 + Ryzen AI Max+ box:

GGUF main this PR
ROCMFP2S 0/10 parsed 10/10
IQ2_XXS / IQ3_XXS experts + MXFP8 dense 0/10 parsed 10/10

Every call picks the right tool and argument. V4 (deepseek4) prompts and parsing are unchanged.

Implementation

  • ChatFormat::DEEPSEEK41, chosen for arch deepseek41, renders the V4.1 prompt:
    • <|System|> at the start in thinking mode or when there is a system prompt or tools;
    • Reasoning Effort: N (range 1-100, ...) in thinking mode (low 50, medium 62, high 75, max 100, or a number);
    • the V4.1 tool block, one schema per line in the model encoder's JSON spelling;
    • tool results as <tool_result> blocks joined into the user turn;
    • mid-conversation system turns.
  • Assistant headers render the same way in every turn, as the V4 renderer does, so a completed turn keeps its prompt prefix for the prefix cache.
  • parse_tool_calls maps the V4.1 tag spelling onto the V4 one before matching (normalize_dsml_tags), so every existing pattern accepts both.

Validation

Check Result
test_server_unit (4 new cases; DEEPSEEK41 added to the prefix-survival test) 613/613 pass
V4.1 renders vs the model repo's encoding/tests reference outputs (chat and tools) byte-identical
Live tool prompts, both GGUFs above 10/10 parsed, 0 parse failures

Notes

  • V4.1 prompts change with this PR (system token, effort line, tool block), so V4.1 outputs differ from main by design.
  • The official template drops earlier reasoning in thinking mode without tools; this renderer keeps every turn's header stable instead, as the V4 renderer already does, so agent turns keep hitting the prefix cache.

🤖 Generated with Claude Code

Review in cubic

…L format

DeepSeek V4.1 spells DSML tags with a leading-space name (<|DSML| calls>,
<|DSML| invoke>, </|DSML| parameter>), opens system turns with <|System|>
and takes a numeric reasoning effort (encoding/encoding.py in the model
repo). The server rendered the V4 format for both models and parsed only
the V4 spelling, so every V4.1 tool call was dropped.

- ChatFormat::DEEPSEEK41 renders the V4.1 prompt: <|System|>, the
  "Reasoning Effort: N (range 1-100, ...)" line in thinking mode, the V4.1
  tool block with one schema per line, tool results joined into the user
  turn, and mid-conversation system turns.
- parse_tool_calls maps the V4.1 tag spelling onto the V4 one before
  matching, so both spellings parse.
- Tests: the chat and tool reference renders from the model repo match
  byte for byte, and a V4.1 tool call parses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@davide221
davide221 merged commit 1a77eae into main Oct 6, 2026
9 checks passed
dusterbloom added a commit to dusterbloom/lucebox-hub that referenced this pull request Oct 6, 2026
dusterbloom added a commit to dusterbloom/lucebox-hub that referenced this pull request Oct 6, 2026
dusterbloom added a commit to dusterbloom/lucebox-hub that referenced this pull request Oct 6, 2026
dusterbloom added a commit to dusterbloom/lucebox-hub that referenced this pull request Oct 6, 2026
@davide221
davide221 deleted the fix/ds41-dsml-v41 branch October 12, 2026 07:37
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