Repository navigation
fix(tongyi): strip historical thinking for qwen3.8-max - #4213
Merged
Merged
Conversation
Fixes langgenius#4212. Limit cleanup to normalized preserve_thinking=false and preserve structured tools and source history. Document unmarked-protocol ambiguity in regression tests.
crazywoola
approved these changes
Nov 6, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4212.
Related to langgenius/dify#44964; this PR addresses the confirmed Tongyi outbound-history reinjection path, not every reported stray-tag or pseudo-tool-call symptom.
For
qwen3.8-max,preserve_thinking=Falsedoes not remove reasoning stored as ordinary assistantcontent. This change:strip_history_thinkingfrom the effective parameters after normalization, restricted tomodel == "qwen3.8-max"andpreserve_thinking is False.MultiModalConversation.callandGeneration.callhistory conversion paths. It does not depend on the current turn'senable_thinking.<think>\n...\n</think>protocol blocks from assistant strings, including multiple blocks interleaved with answer text, without trimming block-external whitespace.dify-agent, current-turn thinking capability, response/stream handling, and other Tongyi models unchanged.0.2.26to0.2.27.Explicit compatibility trade-off
Unmarked historical thinking and legitimate assistant prose with the exact same formatting cannot be reliably distinguished. Under this proposal, a complete, non-nested
<think>\n...\n</think>example in assistant prose, including inside a Markdown code fence, is also removed from the next outbound request. This does not alter the original output or stored source history, but can remove a legitimate example from the next model's context. Maintainer review of this trade-off is requested; this is not presented as lossless provenance detection.Inline
<think>example</think>, normal tag mentions, incomplete/orphan tags, different-case/attribute variants, and escaped tags are retained. Matching does not cross another literal think tag to complete a malformed block. No orphan-tag cleanup or output-side filtering is introduced. Reliable source distinction would require trusted provenance or structured reasoning; merely adding a new marker would leave existing unmarked history unresolved.This is separate from #3277, fixed by #3282: that issue was response-chunk content loss, whereas this PR changes outbound assistant history.
Release Notes
qwen3.8-maxwhen preserved thinking is disabled, including when current-turn thinking is off.<think>\n...\n</think>examples in assistant history are interpreted as thinking blocks and removed from subsequent requests, even inside code fences. Ordinary inline tag mentions and incomplete tags are unchanged.Change Type
Screenshots / Videos
Provider request-conversion change; no UI modification. The following reflects assertions at the SDK call boundary:
assistant.content = "<think>\nHistorical reasoning\n</think>Final answer"assistant.content = "Final answer"" "placeholderenable_thinking=Falsestill replays historical reasoningFor the registered vision route, the text is wrapped in
[{"text": ...}]; the same policy applies before wrapping.LLM Plugin Checklist
Areas affected by this change (check all that apply)
The multimodal endpoint's assistant-text conversion is covered; image/video payload behavior is not changed. Tool-flow verification is at the plugin/API boundary, not a full Agent App/Agent Node UI run.
Version
versioninmanifest.yaml(not the one undermeta)dify_plugin>=0.3.0,<0.11.0is declared inpyproject.tomland locked inuv.lock(or kept inrequirements.txtfor legacy plugins withoutuv.lock) — SDK docsVersion:
0.2.26→0.2.27;meta.versionremains unchanged. Dependencies are intentionally unchanged: the existing declaration isdify_plugin>=0.10.2(without the template's upper bound), and the lockfile/test environment uses0.10.2.Testing
dify_plugin==0.10.2,dashscope==1.27.4.messages, normalized parameters, thinking on/off, tools and associated results, interleaved blocks, protocol ambiguity, unchanged non-target models, original-object preservation, and current reasoning output.git diff --check.Commands from the repository root:
The live command additionally requires
DASHSCOPE_API_KEYin the environment and makes real billable API calls; live cases are skipped unless explicitly opted in. Importingdify_pluginfirst preserves the production gevent patch ordering, andPYTHONPATHlets the existing import-order subprocess test resolve the plugin package from the repository root.Not verified: full Dify Agent App UI/database thought persistence, the original production conversation, or whether all reported stray tags/pseudo-tool outputs disappear. No such end-to-end claim is made. These are new-context vs synthetic-history comparisons on the patched plugin, not a production before/after experiment.
AI-assisted implementation and validation; executed test results and known limitations are reported above.