Repository navigation
feat(agent): expose thinking mode control per LLM node in Agent canvas - #16640
Conversation
When Qwen3/Qwen3.6/B200M (and other thinking-capable models) are used
in RAGFlow Agent nodes, there is currently no way to control whether
the model should reason (thinking mode) or answer directly (non-thinking
mode) on a per-node basis.
The web UI already has a `thinking` dropdown (default/enabled/disabled)
for LLM settings, and the LLM backend already supports `enable_thinking`
via `_apply_model_family_policies()`. However, the LLM component
parameter `gen_conf()` method never passes the `thinking` field through.
This commit bridges the gap by forwarding the `thinking` parameter
from the LLMParam to gen_conf(), completing the chain:
UI (default/enabled/disabled)
→ DSL config
→ LLMParam.thinking
→ gen_conf() {"thinking": "..."}
→ _apply_model_family_policies()
→ extra_body {enable_thinking: true/false}
→ model API call
No breaking changes. When thinking is "default" or not set, existing
behaviour is preserved (Qwen3 defaults to non-thinking).
📝 WalkthroughWalkthroughLLMParam.gen_conf() in agent/component/llm.py is modified to include a "thinking" key in the generated configuration dictionary whenever the instance's thinking attribute is set to a truthy value other than "default". ChangesThinking Configuration Support
Estimated code review effort: 1 (Trivial) | ~2 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
agent/component/llm.py (1)
39-51: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winInitialize
self.thinkingin__init__instead of usinghasattr.Every other core value param (
max_tokens,temperature,top_p,presence_penalty,frequency_penalty) is initialized in__init__and read unconditionally.thinkingis the same category of attribute, yet it's read defensively viahasattrat Line 80. This is inconsistent with the class's own pattern (thehasattr/get_attrdefensive style is otherwise reserved for the*Enabledfeature-flag attributes at lines 64-68, not core values), and leavesself.thinkingundefined by default, which risks silent no-ops if some other part of the codebase (e.g. serialization, checks) accessesself.thinkingdirectly without a guard.♻️ Proposed fix
def __init__(self): super().__init__() self.llm_id = "" self.sys_prompt = "" self.prompts = [{"role": "user", "content": "{sys.query}"}] self.max_tokens = 0 self.temperature = 0 self.top_p = 0 self.presence_penalty = 0 self.frequency_penalty = 0 self.output_structure = None self.cite = True self.visual_files_var = None + self.thinking = "default"- if hasattr(self, "thinking") and self.thinking and self.thinking != "default": + if self.thinking and self.thinking != "default": conf["thinking"] = self.thinkingAlso applies to: 80-81
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@agent/component/llm.py` around lines 39 - 51, Initialize the core `thinking` field in `LLM.__init__` alongside `max_tokens`, `temperature`, and the other scalar defaults so it always exists on the instance. Then update the `LLM` logic that currently uses `hasattr` around `self.thinking` to read it directly like the other core params, keeping `get_attr`/`hasattr` only for the `*Enabled` feature-flag attributes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@agent/component/llm.py`:
- Around line 80-81: Map the agent-level thinking setting to the adapter’s
expected contract before building conf in the LLM component. In the logic around
the self.thinking check, normalize/translate the field so downstream adapters
receive the shape they expect (for example, align it with the reasoning handling
used in rag/llm/chat_model.py rather than forwarding thinking verbatim). Update
the configuration assembly in the relevant llm model class so bundle calls
always get the adapter-compatible key/value.
---
Outside diff comments:
In `@agent/component/llm.py`:
- Around line 39-51: Initialize the core `thinking` field in `LLM.__init__`
alongside `max_tokens`, `temperature`, and the other scalar defaults so it
always exists on the instance. Then update the `LLM` logic that currently uses
`hasattr` around `self.thinking` to read it directly like the other core params,
keeping `get_attr`/`hasattr` only for the `*Enabled` feature-flag attributes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b8ffed03-8601-4f08-9e03-126b4b3b320b
📒 Files selected for processing (1)
agent/component/llm.py
| if hasattr(self, "thinking") and self.thinking and self.thinking != "default": | ||
| conf["thinking"] = self.thinking |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Locate and inspect _apply_model_family_policies to confirm it normalizes the "thinking" string value
rg -n "_apply_model_family_policies" -A 30 --type=pyRepository: infiniflow/ragflow
Length of output: 156
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- agent/component/llm.py ---'
if [ -f agent/component/llm.py ]; then
wc -l agent/component/llm.py
sed -n '1,180p' agent/component/llm.py
fi
echo '--- search for thinking handling ---'
rg -n "thinking|model_family|kimi-k2\.5|k2\.5|apply_model_family_policies|completion handler" agent rag api -S
echo '--- candidate python files ---'
fd -a 'llm.py' agent rag api || true
fd -a 'chat_model.py' agent rag api || trueRepository: infiniflow/ragflow
Length of output: 12560
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- rag/llm/chat_model.py (policy section) ---'
sed -n '60,120p' rag/llm/chat_model.py
echo '--- call sites that pass gen_conf / kwargs into model policy ---'
rg -n "apply_model_family_policies|gen_conf|thinking" rag/llm/chat_model.py agent/component/llm.py api/db/services/llm_service.py -n -A 8 -B 4
echo '--- LLMBundle definition ---'
sed -n '1,260p' api/db/services/llm_service.pyRepository: infiniflow/ragflow
Length of output: 50374
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- search for self.thinking assignment / UI contract ---'
rg -n "\bthinking\b" agent api rag web frontend ui -S
echo '--- inspect llm component around parameter declaration / form generation ---'
sed -n '1,140p' agent/component/llm.py
echo '--- inspect any serialization or defaults for thinking ---'
rg -n "thinking.*default|default.*thinking|enabled|disabled" agent api rag web webui frontend -SRepository: infiniflow/ragflow
Length of output: 4769
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- agent/component/llm.py around param object and any thinking defaults ---'
sed -n '1,120p' agent/component/llm.py
echo '--- search for thinking parameter definitions in agent/web ---'
rg -n '"thinking"|thinkingEnabled|thinking_toggle|chat-detail-thinking-toggle|reasoningTip|no_think' web agent api rag -S
echo '--- inspect web message-input toggle section ---'
sed -n '230,280p' web/src/components/message-input/next.tsx
echo '--- inspect web locale text around reasoning tip ---'
sed -n '1110,1145p' web/src/locales/en.tsRepository: infiniflow/ragflow
Length of output: 16989
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- LLMBundle class and backend selection ---'
rg -n "class LLMBundle|backend\s*=|SupportedLiteLLMProvider|_apply_model_family_policies" api/db/services/llm_service.py rag/llm/chat_model.py -A 12 -B 12
echo '--- agent component thinking parameter definition search ---'
rg -n "thinking" agent/component agent/templates web/src -S | head -n 120Repository: infiniflow/ragflow
Length of output: 32471
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- search for thinking field assignment in agent code ---'
rg -n "\bthinking\b\s*[:=]" agent api rag web/src -S
echo '--- component param base and serialization ---'
sed -n '1,260p' agent/component/base.py
echo '--- agent llm component around any config form metadata ---'
rg -n "get_input_form|get_input_elements|gen_conf\(" agent/component/llm.py agent/component/base.py -A 8 -B 8Repository: infiniflow/ragflow
Length of output: 23894
Map thinking to the adapter contract before calling the bundle. self.thinking is forwarded verbatim here, but rag/llm/chat_model.py only normalizes reasoning for kimi-k2.5 and otherwise drops thinking. If agent configs can set this field, it won’t reach downstream in the shape the model adapters expect.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@agent/component/llm.py` around lines 80 - 81, Map the agent-level thinking
setting to the adapter’s expected contract before building conf in the LLM
component. In the logic around the self.thinking check, normalize/translate the
field so downstream adapters receive the shape they expect (for example, align
it with the reasoning handling used in rag/llm/chat_model.py rather than
forwarding thinking verbatim). Update the configuration assembly in the relevant
llm model class so bundle calls always get the adapter-compatible key/value.
🙏 Friendly Bump — This PR is Ready to MergeThis is a 3-line fix that completes an already-tested code path for a highly requested feature. Why this matters
Test coverage already existsSee Related issues
Both are addressed by this PR. Please consider merging. Happy to address any feedback! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16640 +/- ##
==========================================
- Coverage 94.53% 93.16% -1.37%
==========================================
Files 10 10
Lines 713 717 +4
Branches 116 118 +2
==========================================
- Hits 674 668 -6
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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:
The web UI already has a
thinkingdropdown (default/enabled/disabled) in LLM settings, and the LLM backend_apply_model_family_policies()already supportsenable_thinking. The missing link wasgen_conf()not forwarding the parameter.This 3-line fix completes the chain.
Changes
agent/component/llm.py—LLMParam.gen_conf():End-to-end flow
Backward compatibility
thinkingis "default" or not set, existing behavior is preservedenable_thinking: false(non-thinking), unchangedRelated issues
Testing
test/unit_test/rag/llm/test_chat_model_thinking_policy.pythat thinking policy already tested for Qwen3 models_apply_model_family_policies)