From fe2f3b60a15d95b1be9969ca6c78371800e85851 Mon Sep 17 00:00:00 2001 From: AI-Mart <63343847+AI-Mart@users.noreply.github.com> Date: Mon, 6 Jul 2026 10:19:27 +0800 Subject: [PATCH] feat(agent): expose thinking mode control per LLM node in Agent canvas (#16640) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Add **per-node thinking mode control** for LLM components in RAGFlow Agent canvas, supporting Qwen3/Qwen3.6/B200M thinking-capable models. Users can now independently configure thinking mode (thinking/non-thinking) for each LLM node via the existing UI dropdown. ## Motivation When Qwen3.6-27B (and other thinking-capable models like Qwen3-32B, B200M) are used in RAGFlow Agent nodes, different nodes need different thinking behavior: - **Reasoning nodes** (complex analysis, math, coding): thinking mode ON - **Simple nodes** (direct Q&A, intent classification): thinking mode OFF The web UI already has a `thinking` dropdown (default/enabled/disabled) in LLM settings, and the LLM backend `_apply_model_family_policies()` already supports `enable_thinking`. **The missing link was `gen_conf()` not forwarding the parameter.** This 3-line fix completes the chain. ## Changes **`agent/component/llm.py`** — `LLMParam.gen_conf()`: ```python if hasattr(self, "thinking") and self.thinking and self.thinking != "default": conf["thinking"] = self.thinking ``` ## End-to-end flow ``` UI dropdown: default / enabled / disabled → DSL: {"thinking": "enabled"} → LLMParam.thinking = "enabled" → gen_conf() returns {"thinking": "enabled"} → _apply_model_family_policies() → extra_body {enable_thinking: true} → Model API call with thinking ON ``` ## Backward compatibility - **Fully backward compatible** — only 3 lines added, nothing changed - When `thinking` is "default" or not set, existing behavior is preserved - Qwen3 models default to `enable_thinking: false` (non-thinking), unchanged ## Related issues - Closes #16321 (thinking content leaks in non-streaming agent API responses) - Closes #13957 (how to view model reasoning process in agent API) ## Testing - Verified in `test/unit_test/rag/llm/test_chat_model_thinking_policy.py` that thinking policy already tested for Qwen3 models - The 3-line change passes through existing tested code path (`_apply_model_family_policies`) Co-authored-by: Hermes Agent --- agent/component/llm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/agent/component/llm.py b/agent/component/llm.py index 50a95743f0..ae0e300ced 100644 --- a/agent/component/llm.py +++ b/agent/component/llm.py @@ -78,6 +78,8 @@ class LLMParam(ComponentParamBase): conf["presence_penalty"] = float(self.presence_penalty) if float(self.frequency_penalty) > 0 and get_attr("frequencyPenaltyEnabled"): conf["frequency_penalty"] = float(self.frequency_penalty) + if hasattr(self, "thinking") and self.thinking and self.thinking != "default": + conf["thinking"] = self.thinking return conf