Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(langgraph-agent): pin snippets-only search tools (#7189)

Sd602a7f9feb5
diff --git a/changelog.d/+langgraph-agent-pin-snippets-only.misc.md b/changelog.d/+langgraph-agent-pin-snippets-only.misc.md
new file mode 100644
index 0000000000..55334ce3ab
--- /dev/null
+++ b/changelog.d/+langgraph-agent-pin-snippets-only.misc.md
@@ -0,0 +1 @@
+Pin snippets-only engine invariant for langgraph-agent web_search and specialized search tools with regression tests verifying that a global search.snippets_only=false snapshot does not wrap agent searches in FullSearchResults bulk page fetches.
diff --git a/src/local_deep_research/web_search_engines/search_engine_factory.py b/src/local_deep_research/web_search_engines/search_engine_factory.py
index 5f0faf8ae5..477042b09e 100644
--- a/src/local_deep_research/web_search_engines/search_engine_factory.py
+++ b/src/local_deep_research/web_search_engines/search_engine_factory.py
@@ -427,10 +427,11 @@ def create_search_engine(
kwargs["time_period"] = str(raw_time_period)
# Route search.snippets_only to engines when the caller didn't pass one
- # explicitly. get_search() forwards it as a kwarg, but direct callers
- # (langgraph-agent strategy tools, MCP server) only pass a settings_snapshot
- # — without this fallback the user's Settings → Search → Snippets Only choice
- # is silently ignored on those paths and defaults to True. Placed in kwargs
+ # explicitly. get_search() forwards it as a kwarg, and langgraph-agent
+ # strategy tools explicitly force search_snippets_only=True, but other
+ # direct callers (e.g. MCP server) only pass a settings_snapshot — without
+ # this fallback the user's Settings → Search → Snippets Only choice is
+ # silently ignored on those paths and defaults to True. Placed in kwargs
# so it takes precedence over per-engine default_params.
if "search_snippets_only" not in kwargs and settings_snapshot:
resolved_snippets = _resolve_snippets_only(settings_snapshot)
@@ -438,8 +439,9 @@ def create_search_engine(
kwargs["search_snippets_only"] = resolved_snippets
# Mirror get_search(): wrap FullSearchResults when snippets-only is off
- # and the caller did not pass use_full_search. Direct callers (langgraph
- # tools, MCP) never set that flag, so without this the engine fetches
+ # and the caller did not pass use_full_search. Direct callers like the
+ # MCP server never set that flag (langgraph-agent tools explicitly set
+ # use_full_search=False), so without this fallback the engine fetches
# full content (search_snippets_only=False) but the wrapper path that
# actually hydrates ``full_content`` for searxng/ddg/serpapi/etc. never
# runs.
diff --git a/tests/strategies/test_langgraph_agent_strategy.py b/tests/strategies/test_langgraph_agent_strategy.py
index a4611db484..e2959323ad 100644
--- a/tests/strategies/test_langgraph_agent_strategy.py
+++ b/tests/strategies/test_langgraph_agent_strategy.py
@@ -1919,6 +1919,191 @@ class TestSearchToolMakers:
_, call_kwargs = mock_create.call_args
assert call_kwargs["settings_snapshot"] == snapshot
+ def test_make_web_search_tool_forces_snippets_only_despite_snapshot(self):
+ # Documented agent invariant (CONFIGURATION.md search.snippets_only):
+ # langgraph web_search always returns snippets; full pages come
+ # on demand via fetch_content. A global snippets_only=false (meant
+ # for pipeline strategies) must not turn the agent's web_search
+ # into a FullSearchResults bulk page-fetch.
+ from unittest.mock import MagicMock, patch
+ from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (
+ SearchResultsCollector,
+ _make_web_search_tool,
+ )
+
+ mock_engine = MagicMock()
+ mock_engine.run.return_value = []
+ collector = SearchResultsCollector()
+ snapshot = {"search.snippets_only": {"value": False}}
+
+ with patch(
+ "local_deep_research.web_search_engines.search_engine_factory.create_search_engine",
+ return_value=mock_engine,
+ ) as mock_create:
+ tool_fn = _make_web_search_tool(
+ search_engine_name="duckduckgo",
+ model=MagicMock(),
+ settings_snapshot=snapshot,
+ collector=collector,
+ )
+ tool_fn.invoke({"query": "test query"})
+
+ mock_create.assert_called_once()
+ _, call_kwargs = mock_create.call_args
+ assert call_kwargs["search_snippets_only"] is True
+ assert call_kwargs["use_full_search"] is False
+
+ def test_make_web_search_tool_forces_snippets_only_when_snapshot_missing_key(
+ self,
+ ):
+ from unittest.mock import MagicMock, patch
+ from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (
+ SearchResultsCollector,
+ _make_web_search_tool,
+ )
+
+ mock_engine = MagicMock()
+ mock_engine.run.return_value = []
+ collector = SearchResultsCollector()
+
+ with patch(
+ "local_deep_research.web_search_engines.search_engine_factory.create_search_engine",
+ return_value=mock_engine,
+ ) as mock_create:
+ tool_fn = _make_web_search_tool(
+ search_engine_name="duckduckgo",
+ model=MagicMock(),
+ settings_snapshot={},
+ collector=collector,
+ )
+ tool_fn.invoke({"query": "test query"})
+
+ mock_create.assert_called_once()
+ _, call_kwargs = mock_create.call_args
+ assert call_kwargs["search_snippets_only"] is True
+ assert call_kwargs["use_full_search"] is False
+
+ def test_make_specialized_search_tool_forces_snippets_only_despite_snapshot(
+ self,
+ ):
+ from unittest.mock import MagicMock, patch
+ from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (
+ SearchResultsCollector,
+ _make_specialized_search_tool,
+ )
+
+ mock_engine = MagicMock()
+ mock_engine.run.return_value = []
+ collector = SearchResultsCollector()
+ snapshot = {"search.snippets_only": {"value": False}}
+
+ with patch(
+ "local_deep_research.web_search_engines.search_engine_factory.create_search_engine",
+ return_value=mock_engine,
+ ) as mock_create:
+ tool_fn = _make_specialized_search_tool(
+ engine_name="arxiv",
+ description="Arxiv search",
+ model=MagicMock(),
+ settings_snapshot=snapshot,
+ collector=collector,
+ )
+ tool_fn.invoke({"query": "physics"})
+
+ mock_create.assert_called_once()
+ _, call_kwargs = mock_create.call_args
+ assert call_kwargs["search_snippets_only"] is True
+ assert call_kwargs["use_full_search"] is False
+
+ def test_make_specialized_search_tool_forces_snippets_only_when_snapshot_missing_key(
+ self,
+ ):
+ from unittest.mock import MagicMock, patch
+ from local_deep_research.advanced_search_system.strategies.langgraph_agent_strategy import (
+ SearchResultsCollector,
+ _make_specialized_search_tool,
+ )
+
+ mock_engine = MagicMock()
+ mock_engine.run.return_value = []
+ collector = SearchResultsCollector()
+
+ with patch(
+ "local_deep_research.web_search_engines.search_engine_factory.create_search_engine",
+ return_value=mock_engine,
+ ) as mock_create:
+ tool_fn = _make_specialized_search_tool(
+ engine_name="arxiv",
+ description="Arxiv search",
+ model=MagicMock(),
+ settings_snapshot={},
+ collector=collector,
+ )
+ tool_fn.invoke({"query": "physics"})
+
+ mock_create.assert_called_once()
+ _, call_kwargs = mock_create.call_args
+ assert call_kwargs["search_snippets_only"] is True
+ assert call_kwargs["use_full_search"] is False
+
+ def test_forced_snippets_only_behavior_through_real_factory(
+ self, monkeypatch
+ ):
+ # Behavioral test through the real factory: forced kwargs
+ # (search_snippets_only=True, use_full_search=False) must ensure
+ # the built engine has search_snippets_only=True and is NOT wrapped
+ # in FullSearchResults, preventing precedence regressions inside
+ # the factory.
+ from local_deep_research.web_search_engines import search_engine_factory
+ from local_deep_research.web_search_engines.engines.full_search import (
+ FullSearchResults,
+ )
+ from local_deep_research.web_search_engines.search_engine_base import (
+ BaseSearchEngine,
+ )
+
+ class _MockBaseEngine(BaseSearchEngine):
+ def _get_previews(self, query: str):
+ return []
+
+ real_gsmc = search_engine_factory.get_safe_module_class
+
+ def _fake_gsmc(module_path: str, class_name: str):
+ if class_name == "FullSearchResults":
+ return real_gsmc(module_path, class_name)
+ return _MockBaseEngine
+
+ monkeypatch.setattr(
+ "local_deep_research.web_search_engines.search_engine_factory.get_safe_module_class",
+ _fake_gsmc,
+ )
+
+ snapshot = {
+ "search.tool": {"value": "searxng"},
+ "search.engine.web.searxng.supports_full_search": {"value": True},
+ "search.snippets_only": {"value": False},
+ }
+
+ # Baseline: unforced factory call wraps in FullSearchResults when snippets_only=False
+ unforced = search_engine_factory.create_search_engine(
+ "searxng",
+ settings_snapshot=snapshot,
+ programmatic_mode=True,
+ )
+ assert isinstance(unforced, FullSearchResults)
+
+ # Forced call (as passed by agent tool factories) overrides snapshot:
+ # returns unwrapped engine with snippets-only enabled
+ forced = search_engine_factory.create_search_engine(
+ "searxng",
+ settings_snapshot=snapshot,
+ search_snippets_only=True,
+ use_full_search=False,
+ programmatic_mode=True,
+ )
+ assert not isinstance(forced, FullSearchResults)
+ assert forced.search_snippets_only is True
+
class TestFetchProgressAdapter:
"""Bulk-fetch ``(done, total)`` hook → throttled UI milestones."""
diff --git a/tests/web_search_engines/test_factory_full_search_wrapper.py b/tests/web_search_engines/test_factory_full_search_wrapper.py
index 0c9c5c3ca9..b83c8f049a 100644
--- a/tests/web_search_engines/test_factory_full_search_wrapper.py
+++ b/tests/web_search_engines/test_factory_full_search_wrapper.py
@@ -480,7 +480,7 @@ class TestRegistryFullSearchWrapperEndToEnd:
def test_create_search_engine_snapshot_snippets_only_false_wraps(
self, engine_name, mock_llm
):
- """Direct create_search_engine callers (langgraph tools) wrap when
+ """Direct create_search_engine callers without explicit flags (e.g. MCP) wrap when
the snapshot says search.snippets_only=False, matching get_search."""
settings_snapshot = {
"search.tool": {"value": engine_name},
@@ -563,6 +563,35 @@ class TestRegistryFullSearchWrapperEndToEnd:
assert not isinstance(result, FullSearchResults)
+ @pytest.mark.parametrize("engine_name", FULL_SEARCH_ENGINES)
+ def test_create_search_engine_forced_snippets_only_beats_snapshot_false(
+ self, engine_name, mock_llm
+ ):
+ """Explicit search_snippets_only=True and use_full_search=False beats snapshot snippets_only=False."""
+ settings_snapshot = {
+ "search.tool": {"value": engine_name},
+ "search.snippets_only": {"value": False},
+ f"search.engine.web.{engine_name}.supports_full_search": {
+ "value": True,
+ "ui_element": "checkbox",
+ },
+ f"search.engine.web.{engine_name}.api_key": {
+ "value": "mock-api-key"
+ },
+ }
+
+ result = create_search_engine(
+ engine_name,
+ llm=mock_llm,
+ settings_snapshot=settings_snapshot,
+ programmatic_mode=True,
+ search_snippets_only=True,
+ use_full_search=False,
+ )
+
+ assert not isinstance(result, FullSearchResults)
+ assert result.search_snippets_only is True
+
def _quality_check_disabled_snapshot(self, engine_name):
return {
"search.tool": {"value": engine_name},