From 9ca1f72bd0b40ead0fe13f20364fb876c6607295 Mon Sep 17 00:00:00 2001 From: Joshua Cartu Date: Wed, 2 Dec 2026 20:42:37 +0100 Subject: [PATCH] docs: document DeepSeek V4/V4.1 behavior for tool_choice required MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both docs/api.md and docs/core-design.md stated unconditionally that tool_choice: "required" adds a prompt instruction to call a tool. In Helios, only the Jinja-template and TMLv0 prompt encoders receive the server-appended system instruction (when PromptEncoder::renders_tool_choice returns false in helios/src/server/request.rs). The native DeepSeek V4 and V4.1 prompt encoders return true from renders_tool_choice and handle required mode in their own syntax: in thinking mode, helios/src/frontend/deepseek.rs converts ToolChoice::Required to ToolChoice::Auto so reasoning opens in with no added instruction; in non-thinking mode, the native DeepSeek template opens the DSML tool-call block at the end of the prompt. Updating both specifications aligns the documentation with the implemented runtime behavior without adding runtime complexity. Updated the required-mode descriptions in docs/api.md and docs/core-design.md. Before this change, docs/api.md stated that required mode adds an instruction to call a tool to the prompt, and docs/core-design.md stated that tool_choice=required adds a prompt instruction and requires a completed call to a declared tool. After this change, docs/api.md specifies that Jinja-template and TMLv0 prompt encoders add a system instruction to call a tool to the prompt, while the native DeepSeek V4 and V4.1 prompt encoders add none—rendering required mode identically to "auto" in thinking mode so reasoning starts in and opening the DSML tool-call block at the end of the prompt in non-thinking mode—and that completion validates at least one completed call to a declared tool in all modes. docs/core-design.md now matches that split and links to the conversation and tool semantics section of docs/api.md. No runtime code, wire schemas, or compatibility contracts changed. Expected result: callers and contributors reading either docs/api.md or docs/core-design.md receive a consistent, accurate specification of prompt rendering and completion enforcement for tool_choice: "required" across Jinja-template, TMLv0, and native DeepSeek V4/V4.1 prompt encoders. Verified every documented behavior directly against the checked-out source and tests: PromptEncoder::renders_tool_choice (helios/src/frontend/mod.rs), template_inputs (helios/src/server/request.rs), template_messages (helios/src/server/inference.rs), conversation (helios/src/frontend/deepseek.rs), Encoder::finish (helios/src/server/protocol/encode.rs), and the integration tests required_tools_in_chat_mode_start_inside_the_dsml_envelope and required_and_named_tools_keep_the_thinking_prompt (helios/tests/deepseek_requests.rs). Material limitation: because this commit edits only documentation files (docs/api.md and docs/core-design.md), no compilation, unit test execution, or GPU run was performed on this branch. Signed-off-by: Joshua Cartu Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b --- docs/api.md | 11 ++++++++--- docs/core-design.md | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/api.md b/docs/api.md index 2942b388e..bb08d9b42 100644 --- a/docs/api.md +++ b/docs/api.md @@ -664,9 +664,14 @@ parsing. Tagged parameters, as in GLM, retain malformed JSON values as strings. DeepSeek retains the original text of a `string="false"` parameter that cannot be decoded inside the argument object. Invalid JSON in a whole argument document or a typed XTML value fails parsing. Required mode needs at least one declared -tool, adds an instruction to call a tool to the prompt, and validates that -generation produced at least one -completed call to a declared tool. Sampling is unchanged; no calls are fabricated +tool. Jinja-template and TMLv0 prompt encoders add a system instruction to call +a tool to the prompt. The native DeepSeek V4 and V4.1 prompt encoders add none: +in thinking mode they render required mode identically to `"auto"` so reasoning +starts in ``, and in non-thinking mode their template opens the DSML +tool-call block at the end of the prompt so generation starts inside the +tool-call envelope. In all modes, including DeepSeek thinking mode, completion +validates that generation produced at least one completed call to a declared +tool. Sampling is unchanged; no calls are fabricated and no retries are attempted. Missing calls, including output truncated before a complete call, produce HTTP 500 for buffered requests or a terminal error event for streams. A required-mode stream may deliver partial text before that error, but does not diff --git a/docs/core-design.md b/docs/core-design.md index 09826a289..725b1a2d0 100644 --- a/docs/core-design.md +++ b/docs/core-design.md @@ -1724,8 +1724,11 @@ While device grammar masking is active (outside open reasoning, including prose and tool calls), the request uses MTP width one and the [native replay loop](#native-replay-loop) keeps one step in flight for any decode batch containing it. -`tool_choice=required` adds a prompt instruction and requires a completed call -to a declared tool. Without a grammar it uses ordinary sampling. Named tool +`tool_choice=required` requires a completed call to a declared tool; +Jinja-template and TMLv0 prompt encoders also add a system prompt instruction, +while native DeepSeek V4 and V4.1 encoders do not (see the +[API contracts](api.md#conversation-and-tool-semantics)). Without a grammar it +uses ordinary sampling. Named tool selection filters the definitions to that tool; it does not by itself enable a grammar. The encoder requires a completed call to the selected tool and rejects other tool names. It omits ordinary answer text but preserves reasoning and arguments.