
Qwen3.8-Flash-Next: Preserved Thinking, Cheaper Agents
Summary
Qwen keeps reasoning across every turn by default. Exploit it, or pay for it.
Alibaba's Qwen team dropped Qwen3.8-Flash-Next on August 26, 2026 — open weights, 125B parameters with only 6B activated per token, plus a 51B n-gram embedding table and a 4B multi-token-prediction layer. It is explicitly labelled an early preview of the architecture that will underpin Qwen4, the same way Qwen3-Next previewed Qwen3.5.
The benchmark numbers got the attention: 62.5 on SWE-bench Pro, 81.0 on SWE-bench Multilingual, 73.5 on Toolathlon Verified. But the thing that will actually change your code is buried in the API section of the model card, and almost nobody is talking about it.
Qwen3.8-Flash-Next keeps the thinking blocks from every previous assistant turn in the conversation, by default. Every other reasoning model you have integrated strips them. If you port an existing agent loop over without reading the fine print, you get one of two outcomes: a context window that grows three times faster than you budgeted for, or — if you drop the reasoning fields on the way in — a model that silently loses the continuity the feature exists to provide.
This guide covers what preserved thinking is, how to serve the model so the fields actually appear, how to build a multi-turn loop that round-trips reasoning correctly, and a harness you can run right now to measure what it costs you.
Prerequisites
- Python 3.10+ and
pip install -U openai(verified againstopenai3.5.0) - Either a local server — vLLM, SGLang, TokenSpeed, or
transformers serve— or a QwenCloud API key - For local weights: ~360 GB of VRAM at BF16 across 4 GPUs, or a GGUF quant via llama.cpp if you just want to poke at behaviour
- Familiarity with the OpenAI Chat Completions message format
You do not need a GPU to follow the measurement section — the harness at the end ships with a mock server so you can watch the token accounting work before you rent anything.
What preserved thinking actually is
Take a standard reasoning-model agent loop. Turn 1, the model emits a <think> block and an answer. You append the answer to messages, throw the thinking away, and send turn 2. That is the pattern every OpenAI-compatible integration has used for two years, and it is what the SDK's typed message objects nudge you toward.
Qwen3.8-Flash-Next inverts the default. From the model card: preserved thinking "retains thinking blocks from all historical messages, maintaining a complete reasoning trace across the conversation." Qwen's stated reasons are decision consistency in agent scenarios, less redundant re-reasoning, and — the one that matters for your bill — better KV cache utilisation.
That last point is the non-obvious win. Because the preserved trace is a stable prefix, an inference engine can reuse the cached keys and values for it across turns instead of recomputing. You are paying for more prompt tokens, but a large share of them are cache hits rather than fresh prefill.
Three knobs control the behaviour, and all three have defaults you should know:
| Parameter | Default | What it does |
|---|---|---|
enable_thinking | True | Model thinks before answering; set False for direct responses |
preserve_thinking | True | Keep thinking from all history, not just the latest user message |
reasoning_effort | "xhigh" | One of xhigh, medium, low |
Note the reasoning_effort default. Most vendors default to a middle setting. Qwen defaults to the highest one. If you benchmarked this model against a competitor and found it slow, that is very likely why.
Step 1: Serve it so the fields actually appear
The single most common failure when people first wire this up is that reasoning_content comes back empty and the raw <think> tags land inside content instead. That is not a model problem — it is a missing parser flag. You must pass --reasoning-parser qwen3. If you also want tool calls parsed into structured tool_calls, add the tool-call parser.
# vLLM
vllm serve Qwen/Qwen3.8-Flash-Next \
--port 8000 \
--tensor-parallel-size 4 \
--max-model-len 262144 \
--reasoning-parser qwen3 \
--enable-auto-tool-choice \
--tool-call-parser qwen3_coder
# SGLang
sglang serve --model-path Qwen/Qwen3.8-Flash-Next \
--port 8000 \
--tp-size 4 \
--context-length 262144 \
--reasoning-parser qwen3 \
--tool-call-parser qwen3_coder
# TokenSpeed
tokenspeed serve Qwen/Qwen3.8-Flash-Next \
--port 8000 \
--tensor-parallel-size 4 \
--max-model-len 262144 \
--reasoning-parser qwen3 \
--enable-auto-tool-choice \
--tool-call-parser qwen3_coder
All three expose an OpenAI-compatible API at http://localhost:8000/v1. Point the SDK at it:
export OPENAI_BASE_URL="http://localhost:8000/v1"
export OPENAI_API_KEY="EMPTY"
Step 2: Read the reasoning stream correctly
Streaming deltas carry reasoning on a separate field from content. Annoyingly, frameworks disagree on the name — vLLM and SGLang emit reasoning_content, some gateways emit reasoning. Handle both or you will get intermittent empty traces depending on who is serving.
from openai import OpenAI
client = OpenAI() # reads OPENAI_BASE_URL / OPENAI_API_KEY
messages = [{"role": "user", "content": "Write a Python function to merge two sorted linked lists."}]
completion = client.chat.completions.create(
model="Qwen/Qwen3.8-Flash-Next",
messages=messages,
extra_body={
"chat_template_kwargs": {
"enable_thinking": True,
"preserve_thinking": True,
},
},
reasoning_effort="xhigh",
temperature=1.0, top_p=0.95,
stream=True,
stream_options={"include_usage": True},
)
reasoning_content, answer_content = "", ""
is_answering = False
for chunk in completion:
if not chunk.choices:
print("\nUsage:", chunk.usage)
continue
delta = chunk.choices[0].delta
piece = getattr(delta, "reasoning_content", None) or getattr(delta, "reasoning", None)
if piece:
reasoning_content += piece
if not is_answering:
print(piece, end="", flush=True)
if getattr(delta, "content", None):
if not is_answering:
print("\n--- answer ---")
is_answering = True
answer_content += delta.content
print(delta.content, end="", flush=True)
One omission above is deliberate. top_k and min_p are not first-class Chat Completions parameters, so passing them as keyword arguments raises a TypeError in the SDK. They have to travel inside extra_body, alongside chat_template_kwargs. Qwen recommends top_k=20 and min_p=0.0 for thinking mode, so the full extra_body is:
extra_body={
"top_k": 20,
"min_p": 0.0,
"chat_template_kwargs": {"enable_thinking": True, "preserve_thinking": True},
}
Step 3: Round-trip reasoning through your message history
This is where ported agent loops break. To get preserved thinking, the reasoning has to go back in, attached to the assistant message it came from. Appending only content gives you a conversation the model believes it reasoned about exactly once.
messages.append({
"role": "assistant",
"content": answer_content,
"reasoning_content": reasoning_content,
"reasoning": reasoning_content, # belt and braces: gateways differ
})
Setting both keys is not superstition. The field name is a serving-layer convention, not part of the OpenAI spec, and a request that works against local vLLM can silently drop reasoning when you move it behind a proxy that normalised on the other name.
Step 4: Measure what it costs
Here is a harness that runs the same four-turn conversation twice — once with preserved thinking on, once off — and prints per-turn prompt token counts. Save it as thinking_budget.py.
"""Measure what preserved thinking costs across a multi-turn agent run."""
import os
from openai import OpenAI
MODEL = os.environ.get("QWEN_MODEL", "Qwen/Qwen3.8-Flash-Next")
client = OpenAI()
TURNS = [
"List the files you would inspect first to debug a failing CI job.",
"The failing step is `pytest -q`. Narrow your list to three files.",
"Assume tests/conftest.py sets a stale env var. Propose the one-line fix.",
"Now write the commit message for that fix.",
]
def run(preserve: bool):
messages, rows = [], []
for i, prompt in enumerate(TURNS, start=1):
messages.append({"role": "user", "content": prompt})
resp = client.chat.completions.create(
model=MODEL,
messages=messages,
extra_body={"chat_template_kwargs": {
"enable_thinking": True,
"preserve_thinking": preserve,
}},
reasoning_effort="medium",
temperature=1.0,
top_p=0.95,
)
msg = resp.choices[0].message
reasoning = getattr(msg, "reasoning_content", None) or getattr(msg, "reasoning", "") or ""
messages.append({
"role": "assistant",
"content": msg.content or "",
"reasoning_content": reasoning,
"reasoning": reasoning,
})
u = resp.usage
rows.append((i, u.prompt_tokens, u.completion_tokens))
return rows
def report(label, rows):
print(f"\n{label}")
print(f"{'turn':>4} {'prompt_tok':>11} {'completion_tok':>15}")
for i, pt, ct in rows:
print(f"{i:>4} {pt:>11} {ct:>15}")
print(f" total prompt tokens: {sum(r[1] for r in rows)}")
if __name__ == "__main__":
report("preserve_thinking=True", run(True))
report("preserve_thinking=False", run(False))
Run it:
OPENAI_BASE_URL=http://localhost:8000/v1 OPENAI_API_KEY=EMPTY python3 thinking_budget.py
Output from a mock endpoint that reproduces Qwen's accounting rule (real traces will be larger, but the shape is what matters):
preserve_thinking=True
turn prompt_tok completion_tok
1 13 184
2 209 184
3 404 184
4 596 184
total prompt tokens: 1222
preserve_thinking=False
turn prompt_tok completion_tok
1 13 184
2 209 184
3 224 184
4 236 184
total prompt tokens: 682
Read the second column. With preservation on, prompt tokens climb roughly linearly — every turn carries every prior thought. With it off, growth is nearly flat because only the most recent thinking block survives. Over four turns that is 1,222 versus 682 prompt tokens, and the gap widens with conversation length, not with conversation complexity.
Before you reflexively turn it off: a large fraction of those preserved tokens are a stable prefix, so on an engine with prefix caching they are cache hits, not fresh prefill. The number to optimise is not prompt tokens — it is time-to-first-token and cost after caching. Measure both.
Step 5: reasoning_effort, and the counterintuitive part
reasoning_effort takes xhigh, medium, or low, and defaults to xhigh. The obvious move for a latency-sensitive agent is to drop to low. The model card warns against exactly that:
"In multi-turn agentic tasks, lower reasoning effort does not always reduce overall task completion time. Although it may produce faster per-turn responses, it can also lead to insufficient analysis, more failures, and repeated retries, which may increase total latency and token consumption."
This is a real effect and it is easy to miss, because per-turn latency is the metric your dashboard already tracks. A turn that returns in 800 ms instead of 3 s looks like a win right up until the agent needs four extra turns to recover from a shallow decision. Benchmark wall-clock time to task completion and total tokens per completed task, not per-call latency.
A practical starting point: xhigh for planning and diagnosis turns, medium for execution turns where the plan is already fixed, low only for classification or formatting steps where there is nothing to reason about.
Worked example: a four-turn triage agent
Putting it together — a loop that keeps reasoning in history, varies effort by turn role, and reports the running token cost.
import os, time
from openai import OpenAI
client = OpenAI()
MODEL = os.environ.get("QWEN_MODEL", "Qwen/Qwen3.8-Flash-Next")
PLAN = {"reasoning_effort": "xhigh", "temperature": 1.0, "top_p": 0.95}
EXEC = {"reasoning_effort": "medium", "temperature": 1.0, "top_p": 0.95}
FMT = {"reasoning_effort": "low", "temperature": 0.7, "top_p": 0.80}
STEPS = [
("Triage this bug report: 'uploads over 8MB return 502 after ~30s'.", PLAN),
("Which single subsystem is most likely at fault? Justify in 3 bullets.", EXEC),
("Write the exact nginx directive change you would test first.", EXEC),
("Summarise as a one-line changelog entry. No preamble.", FMT),
]
messages = []
total_prompt = total_completion = 0
t0 = time.time()
for step, (prompt, cfg) in enumerate(STEPS, start=1):
messages.append({"role": "user", "content": prompt})
resp = client.chat.completions.create(
model=MODEL,
messages=messages,
extra_body={
"top_k": 20,
"min_p": 0.0,
"chat_template_kwargs": {"enable_thinking": True, "preserve_thinking": True},
},
**cfg,
)
m = resp.choices[0].message
reasoning = getattr(m, "reasoning_content", None) or getattr(m, "reasoning", "") or ""
messages.append({
"role": "assistant",
"content": m.content or "",
"reasoning_content": reasoning,
"reasoning": reasoning,
})
total_prompt += resp.usage.prompt_tokens
total_completion += resp.usage.completion_tokens
print(f"[{step}] effort={cfg['reasoning_effort']:>6} "
f"think={len(reasoning):>6}ch answer={len(m.content or ''):>5}ch")
print(f"\nprompt={total_prompt} completion={total_completion} "
f"wall={time.time() - t0:.1f}s")
The per-step line is the useful diagnostic. If think stays enormous on your low-effort formatting step, your reasoning_effort is not reaching the server — check that your gateway is forwarding it rather than dropping unknown parameters.
Common pitfalls
QwenCloud and local servers take these parameters differently
This trips up nearly everyone who prototypes locally then moves to the hosted API. Against a local server you wrap the flags in chat_template_kwargs. Against QwenCloud you pass them at the top level of extra_body.
# Local vLLM / SGLang / TokenSpeed
extra_body={"chat_template_kwargs": {"enable_thinking": False, "preserve_thinking": False}}
# QwenCloud (model name also changes, e.g. "qwen3.8-flash")
extra_body={"enable_thinking": False, "preserve_thinking": False}
The failure mode is silent. An unrecognised key inside chat_template_kwargs is ignored rather than rejected, so you get thinking mode when you asked for instruct mode, and the only symptom is a latency and cost regression.
Sampling parameters differ between thinking and non-thinking mode
These are not interchangeable, and using thinking-mode settings for instruct mode is a known cause of repetition loops.
| Parameter | Thinking mode | Instruct (non-thinking) |
|---|---|---|
| temperature | 1.0 | 0.7 |
| top_p | 0.95 | 0.80 |
| top_k | 20 | 20 |
| min_p | 0.0 | 0.0 |
| presence_penalty | 0.0 | 1.5 |
| repetition_penalty | 1.0 | 1.0 |
If you hit endless repetition, Qwen suggests raising presence_penalty between 0 and 2 — with the caveat that higher values can cause language mixing and a small quality drop.
Preserved thinking will walk you into the context ceiling
Native context is 262,144 tokens. A long agent session with preservation on reaches that faster than your prompt-token budget suggests, because reasoning traces are typically several times longer than the answers they produce. Qwen's own guidance is to allocate up to 262,144 tokens for reasoning content and 131,072 for final responses within a 1M context — which is a strong hint about the ratio they expect.
Do not enable YaRN by default
Extending to 1M tokens uses YaRN RoPE scaling, and every notable open-source framework implements static YaRN — the scaling factor stays constant regardless of input length. Turning it on globally degrades quality on short prompts. Enable it only for workloads that genuinely need it, and tune factor to your actual context length rather than leaving it at 4.0.
VLLM_ALLOW_LONG_MAX_MODEL_LEN=1 vllm serve Qwen/Qwen3.8-Flash-Next \
--hf-overrides '{"text_config": {"rope_parameters": {"mrope_interleaved": true, "mrope_section": [11, 11, 10], "rope_type": "yarn", "rope_theta": 10000000, "partial_rotary_factor": 0.25, "factor": 4.0, "original_max_position_embeddings": 262144}}}' \
--max-model-len 1000000
If your typical context is 524,288 tokens, set factor to 2.0 rather than 4.0.
Missing reasoning parser means tags leak into content
Without --reasoning-parser qwen3, the server hands you a content string that literally begins with <think>. Downstream code that renders assistant messages will display raw reasoning to users. Check for this on day one, not after a demo.
Qwen3.8-Flash-Next is not Qwen3.8-Flash
-Next is the open-weight experimental preview. Qwen3.8-Flash is the production version on QwenCloud, with 1M context by default and built-in tools. Benchmarks and behaviour published for one do not automatically transfer to the other.
Quick reference
| Item | Value |
|---|---|
| Model ID | Qwen/Qwen3.8-Flash-Next |
| Released | August 26, 2026 |
| Params | 125B total, 6B activated, +51B n-gram, +4B MTP |
| Weights on disk | ~180B params, BF16 |
| Context | 262,144 native, up to 1,000,000 with YaRN |
| Architecture | Gated DeltaNet + Qwen Sparse Attention, Gated Residual, 512 experts (10 routed + 1 shared) |
| License | qwen-community-1.0 |
| Thinking default | on |
| Preserve thinking default | on |
| reasoning_effort default | xhigh (also medium, low) |
| Required serve flag | --reasoning-parser qwen3 |
| Tool call parser | qwen3_coder |
| Local param placement | extra_body.chat_template_kwargs |
| QwenCloud param placement | extra_body top level |
Next steps
- Run
thinking_budget.pyagainst your own agent's real conversation shape, not the toy four turns here — the crossover point where preservation stops paying for itself depends entirely on trace length. - Instrument time-to-first-token separately from total latency so you can see prefix cache hits doing their job.
- A/B
reasoning_effortper turn role and grade on task completion, not per-call speed. - If you are porting from Kimi, DeepSeek, or GPT-series reasoning models, audit every place your loop constructs an assistant message — that is where preserved thinking gets silently dropped.
- Read the technical report in the QwenLM/Qwen3.8-Flash-Next repo for the n-gram embedding and Gated Residual details, since these carry into Qwen4.
Sources: Qwen3.8-Flash-Next model card, QwenLM/Qwen3.8-Flash-Next, Qwen release blog.
Comments
Be the first to comment
Found this useful?
Get new AI guides for builders by email. Free.
Join 3,617 newsletter subscribers.