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(agent/tools): run a DuckDuckGo news search when the channel is news (#19176)
MarMar Labs293de5aad78a
diff --git a/agent/tools/duckduckgo.py b/agent/tools/duckduckgo.pyindex bd072bd242..8056f75569 100644--- a/agent/tools/duckduckgo.py+++ b/agent/tools/duckduckgo.py@@ -77,7 +77,10 @@ class DuckDuckGo(ToolBase, ABC):returntry:- if kwargs.get("topic", "general") == "general":+ # Test for "news" rather than for a web-search value: callers send either+ # "text" or "general" for the web search, so "news" is the only stable+ # discriminator between the two branches.+ if (kwargs.get("channel") or self._param.channel) != "news":with DDGS() as ddgs:if self.check_if_canceled("DuckDuckGo processing"):returndiff --git a/test/unit_test/agent/tools/test_duckduckgo_channel.py b/test/unit_test/agent/tools/test_duckduckgo_channel.pynew file mode 100644index 0000000000..f28225d9e2--- /dev/null+++ b/test/unit_test/agent/tools/test_duckduckgo_channel.py@@ -0,0 +1,94 @@+#+# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#++import pytest++pytest.importorskip("duckduckgo_search")++import agent.tools.duckduckgo as ddg_module # noqa: E402+from agent.tools.duckduckgo import DuckDuckGo, DuckDuckGoParam # noqa: E402+++class _FakeDDGS:+ """Records which search method the tool chose."""++ calls: list[str] = []++ def __enter__(self):+ return self++ def __exit__(self, *_):+ return False++ def text(self, *_a, **_kw):+ _FakeDDGS.calls.append("text")+ return []++ def news(self, *_a, **_kw):+ _FakeDDGS.calls.append("news")+ return []+++def _make_tool(channel):+ # Bypass the canvas-bound __init__ the way test_google_unit.py does, and stub+ # the canvas-touching helpers so _invoke's branch is the only thing exercised.+ tool = DuckDuckGo.__new__(DuckDuckGo)+ param = DuckDuckGoParam()+ param.max_retries = 0+ param.delay_after_error = 0+ param.channel = channel+ tool._param = param+ tool.check_if_canceled = lambda *a, **k: False+ tool._retrieve_chunks = lambda *a, **k: None+ tool.set_output = lambda *a, **k: None+ return tool++[email protected](autouse=True)+def _fake_ddgs(monkeypatch):+ _FakeDDGS.calls = []+ monkeypatch.setattr(ddg_module, "DDGS", _FakeDDGS)++[email protected]("channel", ["news"])+def test_news_channel_runs_a_news_search(channel):+ # The node's own parameter is what the canvas passes; selecting News must not+ # fall through to the general web search.+ _make_tool(channel)._invoke(query="q")+ assert _FakeDDGS.calls == ["news"]+++def test_news_channel_from_kwargs_runs_a_news_search():+ # An LLM tool call supplies `channel` in kwargs rather than on the param.+ _make_tool("text")._invoke(query="q", channel="news")+ assert _FakeDDGS.calls == ["news"]++[email protected]("channel", ["text", "general"])+def test_non_news_channels_run_a_text_search(channel):+ # Callers send either value for a web search; both must keep it.+ _make_tool(channel)._invoke(query="q")+ assert _FakeDDGS.calls == ["text"]+++def test_blank_channel_falls_back_to_the_param():+ # A blank kwarg must not be read as a channel; the node's setting wins.+ _make_tool("news")._invoke(query="q", channel="")+ assert _FakeDDGS.calls == ["news"]