Anothers1993/Qwen3.8-Scoped-Terse-Chat-Template
Qwen3.8 Scoped-Terse Chat Template
中文说明
An operational chat template for Qwen3.8-27B agent workloads. It keeps the official Qwen message, vision, and tool-call formats while changing two defaults that matter in long-running local agents:
- Historical reasoning is scoped to the active user/tool round by default.
lowreasoning effort is tuned for concise completion instead of full-history reconstruction.
This repository contains no model weights.
Status: `v0.1.0-beta`. Validated on SGLang with Qwen3.8-27B NVFP4, DFlash2 speculative decoding, OpenCode, and 2× DGX Spark TP2. Treat the results below as an operational regression test, not a model-quality benchmark.
Why this exists
The official Qwen3.8 template preserves reasoning from all historical assistant messages by default. That can improve continuity and KV-cache reuse, but very long agent sessions may also reactivate completed tasks. Separately, reasoning_effort is a soft instruction rather than a hard token budget: an ambiguous follow-up can spend the entire output allowance on reasoning and return no final text.
This template provides a middle ground:
- completed-turn reasoning is stripped by default;
- reasoning generated after the latest real user query remains available across tool calls;
- explicit
preserve_thinking=truestill restores full-history behavior; minimal → low,high/max → xhighaliases improve harness compatibility;lowfocuses on the latest request, asks a concise clarifying question when the request is ambiguous, targets a short reasoning pass, and requests non-empty final text unless a tool call is required;- image/video placeholders and Qwen XML tool calls are unchanged.
SGLang usage
Download chat_template.jinja, then launch SGLang with:
python -m sglang.launch_server \
--model-path Qwen/Qwen3.8-27B \
--chat-template ./chat_template.jinja \
--reasoning-parser qwen3 \
--tool-call-parser qwen3_coder \
--enable-multimodal \
--host 0.0.0.0 \
--port 30000The template is also suitable for separately quantized Qwen3.8-27B checkpoints when their tokenizer and chat protocol remain compatible with the official model.
Request defaults
from openai import OpenAI
client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")
response = client.chat.completions.create(
model="qwen3.8-27b",
messages=[{"role": "user", "content": "Explain the failure briefly."}],
reasoning_effort="low",
max_tokens=16384,
extra_body={
"chat_template_kwargs": {
"preserve_thinking": False,
"enable_thinking": True,
}
},
)preserve_thinking=False is already the template default. Passing it explicitly is useful when a gateway may inject its own defaults.
To restore the official full-history behavior for a request:
{"chat_template_kwargs": {"preserve_thinking": true}}OpenCode
See `examples/opencode.json`. The important fields are:
{
"reasoning": true,
"interleaved": {"field": "reasoning_content"},
"options": {"reasoningEffort": "low"},
"limit": {"context": 262144, "output": 16384}
}reasoning_content must be declared as interleaved reasoning so it survives assistant/tool round trips without being merged into visible text.
Supported reasoning levels
Unknown values fail closed with a template error.
Regression evidence
A real-world replay used a long OpenCode agent session and the same ambiguous follow-up. The context sizes differ slightly because the second run was a later fork of the session; this is a regression replay, not a controlled quality eval.
Additional live checks covered structured tool calls, a tool-result round trip, image input, preserve_thinking on/off, and all reasoning-level aliases. See `benchmarks/dgx-spark-regression.json`.
Tests
python -m pip install jinja2
python tests/test_chat_template.py chat_template.jinjaThe test suite checks:
- all reasoning-level aliases;
- scoped history by default;
- explicit full-history preservation;
- current-round tool reasoning retention;
- structured tool serialization;
- multimodal placeholders;
- fail-closed handling of unknown reasoning levels.
Limitations
- The 1,024-token target in
lowis instruction-level steering, not a hard runtime budget. Configure a reasonable total output limit and handlefinish_reason=length. - This template does not delete visible conversation messages or tool results. Long sessions still need compaction or a fresh task boundary.
- Quantization, speculative decoding, sampling, and runtime versions can change behavior. Re-run the included tests and your own agent evals before production.
- No claim is made that this template improves benchmark quality.
Provenance and credits
Derived from the official Qwen3.8-27B chat template under Apache-2.0. Operational ideas were informed by the Qwen and SGLang documentation and community work on long-running Qwen agents, including the Qwen Sharp Chat Templates project. The scoped-terse wording and compatibility tests in this repository are maintained independently.
License
Apache License 2.0. See `LICENSE`.
