RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix: strip reasoning model thinking tags from document exports (#16687)
Wang Qi3660b98ae9df
diff --git a/agent/component/docs_generator.py b/agent/component/docs_generator.pyindex 297fac9b1e..9c89eefbf2 100644--- a/agent/component/docs_generator.py+++ b/agent/component/docs_generator.py@@ -189,7 +189,7 @@ class DocGenerator(Message, ABC):flags=re.DOTALL,)- return content+ return self._strip_thinking(content)def _get_output_directory(self) -> str:os.makedirs(self._default_output_directory, exist_ok=True)diff --git a/agent/component/message.py b/agent/component/message.pyindex 6b03b5f445..d9077313de 100644--- a/agent/component/message.py+++ b/agent/component/message.py@@ -365,10 +365,31 @@ class Message(ComponentBase):return None+ @staticmethod+ def _strip_thinking(content: str) -> str:+ """Remove <think>...</think> reasoning blocks before document export.++ Reasoning models (e.g. DeepSeek-R1, OpenAI o1) embed chain-of-thought+ inside ``<think>`` tags. These blocks must not leak into exported+ Word/PDF/Excel documents.+ """+ if not isinstance(content, str) or not content:+ return content+ # Remove complete think blocks (DOTALL so newlines are matched)+ cleaned = re.sub(r"<think>.*?</think>", "", content, flags=re.DOTALL)+ # Remove any dangling unclosed <think> opening tag + trailing content+ cleaned = re.sub(r"<think>.*$", "", cleaned, flags=re.DOTALL)+ # Remove leftover standalone tags+ cleaned = re.sub(r"</?think>", "", cleaned)+ # Collapse 3+ consecutive newlines left behind by removed blocks+ cleaned = re.sub(r"\n{3,}", "\n\n", cleaned)+ return cleaned.strip()+def _convert_content(self, content):if not self._param.output_format:return+ content = self._strip_thinking(content)import pypandocdoc_id = get_uuid()