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.

chore(engines): centralize User-Agent on USER_AGENT across 9 search engines (#4130) (#4179)

LearningCircuit38583800f34b
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_github.py b/src/local_deep_research/web_search_engines/engines/search_engine_github.py
index 9ef2646be0..869eacbc1b 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_github.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_github.py
@@ -7,6 +7,7 @@ from langchain_core.language_models import BaseLLM
from loguru import logger
from ...config import llm_config, search_config
+from ...constants import USER_AGENT
from ...security.safe_requests import safe_get
from ...utilities.json_utils import extract_json, get_llm_response_text
from ..search_engine_base import BaseSearchEngine
@@ -73,7 +74,7 @@ class GitHubSearchEngine(BaseSearchEngine):
# Set up API headers
self.headers = {
"Accept": "application/vnd.github.v3+json",
- "User-Agent": "Local-Deep-Research-Agent",
+ "User-Agent": USER_AGENT,
}
# Add authentication if API key provided
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_gutenberg.py b/src/local_deep_research/web_search_engines/engines/search_engine_gutenberg.py
index fe60b3b0f5..06e4f8ebf5 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_gutenberg.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_gutenberg.py
@@ -6,6 +6,7 @@ import requests
from langchain_core.language_models import BaseLLM
from loguru import logger
+from ...constants import USER_AGENT
from ...security.safe_requests import safe_get
from ..rate_limiting import RateLimitError
from ..search_engine_base import BaseSearchEngine
@@ -77,9 +78,7 @@ class GutenbergSearchEngine(BaseSearchEngine):
self.search_url = f"{self.base_url}/books/"
# User-Agent header for API requests
- self.headers = {
- "User-Agent": "LocalDeepResearch/1.0 (https://github.com/LearningCircuit/local-deep-research)"
- }
+ self.headers = {"User-Agent": USER_AGENT}
def _build_query_params(self, query: str) -> Dict[str, Any]:
"""Build query parameters for the API request."""
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py b/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py
index 76416384c5..553aac4379 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py
@@ -5,7 +5,7 @@ from typing import Any, Dict, List, Optional
from langchain_core.language_models import BaseLLM
from loguru import logger
-from ...constants import SNIPPET_LENGTH_LONG
+from ...constants import SNIPPET_LENGTH_LONG, USER_AGENT
from ...advanced_search_system.filters.journal_reputation_filter import (
JournalReputationFilter,
)
@@ -107,7 +107,7 @@ class NasaAdsSearchEngine(BaseSearchEngine):
# API configuration
self.api_base = "https://api.adsabs.harvard.edu/v1"
self.headers = {
- "User-Agent": "Local-Deep-Research-Agent",
+ "User-Agent": USER_AGENT,
"Accept": "application/json",
}
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py b/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py
index 5fd0c3f6e9..81eb6ab064 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py
@@ -5,7 +5,7 @@ from typing import Any, Dict, List, Optional
from langchain_core.language_models import BaseLLM
from loguru import logger
-from ...constants import SNIPPET_LENGTH_LONG
+from ...constants import SNIPPET_LENGTH_LONG, USER_AGENT
from ...advanced_search_system.filters.journal_reputation_filter import (
JournalReputationFilter,
)
@@ -102,7 +102,7 @@ class OpenAlexSearchEngine(BaseSearchEngine):
# API configuration
self.api_base = "https://api.openalex.org"
self.headers = {
- "User-Agent": f"Local-Deep-Research-Agent{f' ({email})' if email else ''}",
+ "User-Agent": f"{USER_AGENT} ({email})" if email else USER_AGENT,
"Accept": "application/json",
}
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_openlibrary.py b/src/local_deep_research/web_search_engines/engines/search_engine_openlibrary.py
index 7bc56e481d..3cacdea7b0 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_openlibrary.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_openlibrary.py
@@ -7,6 +7,7 @@ import requests
from langchain_core.language_models import BaseLLM
from loguru import logger
+from ...constants import USER_AGENT
from ...security.safe_requests import safe_get
from ..rate_limiting import RateLimitError
from ..search_engine_base import BaseSearchEngine
@@ -67,9 +68,7 @@ class OpenLibrarySearchEngine(BaseSearchEngine):
# User-Agent header is important for Open Library API
# They may block requests without a proper User-Agent
- self.headers = {
- "User-Agent": "LocalDeepResearch/1.0 (https://github.com/LearningCircuit/local-deep-research)"
- }
+ self.headers = {"User-Agent": USER_AGENT}
def _build_query_params(self, query: str) -> Dict[str, Any]:
"""Build query parameters for the API request."""
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_pubchem.py b/src/local_deep_research/web_search_engines/engines/search_engine_pubchem.py
index b6be0d7749..f78680b887 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_pubchem.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_pubchem.py
@@ -6,6 +6,7 @@ from urllib.parse import quote
from langchain_core.language_models import BaseLLM
from loguru import logger
+from ...constants import USER_AGENT
from ...security.safe_requests import safe_get
from ..rate_limiting import RateLimitError
from ..search_engine_base import BaseSearchEngine
@@ -60,9 +61,7 @@ class PubChemSearchEngine(BaseSearchEngine):
)
# User-Agent header for API requests
- self.headers = {
- "User-Agent": "LocalDeepResearch/1.0 (https://github.com/LearningCircuit/local-deep-research)"
- }
+ self.headers = {"User-Agent": USER_AGENT}
def _search_compounds(self, query: str) -> List[str]:
"""Search for compound names matching the query."""
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_stackexchange.py b/src/local_deep_research/web_search_engines/engines/search_engine_stackexchange.py
index 7eafafc6e3..b8038186dd 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_stackexchange.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_stackexchange.py
@@ -9,6 +9,7 @@ import requests
from langchain_core.language_models import BaseLLM
from loguru import logger
+from ...constants import USER_AGENT
from ...security.safe_requests import safe_get
from ..rate_limiting import RateLimitError
from ..search_engine_base import BaseSearchEngine
@@ -122,7 +123,7 @@ class StackExchangeSearchEngine(BaseSearchEngine):
# User-Agent and required headers for API requests
self.headers = {
- "User-Agent": "LocalDeepResearch/1.0 (https://github.com/LearningCircuit/local-deep-research)",
+ "User-Agent": USER_AGENT,
"Accept-Encoding": "gzip, deflate",
}
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_wikinews.py b/src/local_deep_research/web_search_engines/engines/search_engine_wikinews.py
index aaf67634f1..d758935221 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_wikinews.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_wikinews.py
@@ -8,14 +8,13 @@ import requests
from langchain_core.language_models import BaseLLM
from loguru import logger
+from ...constants import USER_AGENT
from ...utilities.json_utils import extract_json, get_llm_response_text
from ...utilities.search_utilities import remove_think_tags, LANGUAGE_CODE_MAP
from ..search_engine_base import BaseSearchEngine
from ...security import safe_get
-HEADERS = {
- "User-Agent": "local-deep-research-wikinews-search-engine (github.com/LearningCircuit/local-deep-research)"
-}
+HEADERS = {"User-Agent": USER_AGENT}
WIKINEWS_LANGUAGES = [
"ru",
"sr",
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_zenodo.py b/src/local_deep_research/web_search_engines/engines/search_engine_zenodo.py
index cf602f18d6..27ec7fe85b 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_zenodo.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_zenodo.py
@@ -8,6 +8,7 @@ import requests
from langchain_core.language_models import BaseLLM
from loguru import logger
+from ...constants import USER_AGENT
from ...security.safe_requests import safe_get
from ..rate_limiting import RateLimitError
from ..search_engine_base import BaseSearchEngine
@@ -70,9 +71,7 @@ class ZenodoSearchEngine(BaseSearchEngine):
self.search_url = f"{self.base_url}/api/records"
# User-Agent header for API requests
- self.headers = {
- "User-Agent": "LocalDeepResearch/1.0 (https://github.com/LearningCircuit/local-deep-research)"
- }
+ self.headers = {"User-Agent": USER_AGENT}
def _build_query_params(self, query: str) -> Dict[str, Any]:
"""Build query parameters for the API request."""
diff --git a/tests/web_search_engines/test_engine_user_agents.py b/tests/web_search_engines/test_engine_user_agents.py
new file mode 100644
index 0000000000..0fefd757b9
--- /dev/null
+++ b/tests/web_search_engines/test_engine_user_agents.py
@@ -0,0 +1,120 @@
+"""Regression tests for the User-Agent invariant across search engines.
+
+Follow-up to issue #4130: nine search-engine modules used to hand-roll
+their own User-Agent strings (mostly ``"LocalDeepResearch/1.0 (...)"``
+with the version pinned to 1.0, or ad-hoc ``"Local-Deep-Research-Agent"``)
+instead of referencing the centralized ``USER_AGENT`` constant. The
+strings drifted over time and never carried the actual project version.
+
+This test sweeps the engine source files and asserts that any
+``"User-Agent": ...`` header set against the canonical ``USER_AGENT``
+constant rather than a literal string, so future copy-pastes can't
+silently re-introduce stale version numbers.
+
+Engines that are deliberately NOT included here:
+ * ``search_engine_searxng.py`` — sends a full browser UA + Referer +
+ Upgrade-Insecure-Requests on purpose, because some public SearXNG
+ instances rate-limit non-browser scrapers. Touching this risks
+ breaking real users.
+ * ``search_engine_wayback.py`` — uses a hybrid bot-identifying UA
+ (``"Mozilla/5.0 (Local Deep Research Bot; research project)"``)
+ that is honest, just not the canonical constant.
+"""
+
+import re
+from pathlib import Path
+
+import pytest
+
+
+SRC_ROOT = (
+ Path(__file__).resolve().parents[2]
+ / "src"
+ / "local_deep_research"
+ / "web_search_engines"
+ / "engines"
+)
+
+# Engines that are required to use ``USER_AGENT`` (with or without a
+# polite-pool suffix). See module docstring for the rationale behind
+# the SearXNG/Wayback exclusions.
+CANONICAL_UA_ENGINES = [
+ "search_engine_github.py",
+ "search_engine_gutenberg.py",
+ "search_engine_stackexchange.py",
+ "search_engine_wikinews.py",
+ "search_engine_pubchem.py",
+ "search_engine_openlibrary.py",
+ "search_engine_nasa_ads.py",
+ "search_engine_zenodo.py",
+ "search_engine_openalex.py",
+]
+
+
+def _source(filename: str) -> str:
+ path = SRC_ROOT / filename
+ assert path.is_file(), f"engine source not found: {path}"
+ return path.read_text(encoding="utf-8")
+
+
+# The pre-fix strings that must never reappear. These are the exact
+# literals that lived in the source before the #4130 follow-up. A more
+# general pattern is enforced separately by
+# ``test_no_string_literal_user_agent``.
+_LEGACY_LITERALS = (
+ "LocalDeepResearch/1.0 (https://github.com/LearningCircuit/local-deep-research)",
+ "Local-Deep-Research-Agent",
+ "local-deep-research-wikinews-search-engine",
+)
+
+
[email protected]("filename", CANONICAL_UA_ENGINES)
+def test_no_legacy_user_agent_string(filename):
+ """No engine should hand-roll one of the pre-fix UA literals."""
+ src = _source(filename)
+ for legacy in _LEGACY_LITERALS:
+ assert legacy not in src, (
+ f"{filename} still contains the legacy UA literal {legacy!r}. "
+ "Use USER_AGENT from local_deep_research.constants instead."
+ )
+
+
[email protected]("filename", CANONICAL_UA_ENGINES)
+def test_user_agent_constant_is_imported(filename):
+ """USER_AGENT must be imported from the central constants module."""
+ src = _source(filename)
+ assert re.search(
+ r"from\s+\.{2,3}constants\s+import\s+[^\n]*\bUSER_AGENT\b", src
+ ), (
+ f"{filename} does not import USER_AGENT from ...constants — the "
+ "canonical source of truth for the project User-Agent."
+ )
+
+
[email protected]("filename", CANONICAL_UA_ENGINES)
+def test_no_string_literal_user_agent(filename):
+ """Any ``"User-Agent": ...`` header must reference USER_AGENT, not a
+ bare string literal.
+
+ Catches new hand-rolled UAs even if they don't match one of the
+ historical legacy literals — e.g. someone bumping the version by
+ hand to ``"LocalDeepResearch/2.0 (...)"``.
+ """
+ src = _source(filename)
+ # Find every ``"User-Agent": <value>`` site. The regex stops at the
+ # first comma or closing brace so multi-key dicts work.
+ matches = re.findall(r'"User-Agent"\s*:\s*([^,\n}]+?)(?=[,\n}])', src)
+ assert matches, (
+ f"Sanity check: expected at least one User-Agent header in "
+ f"{filename}, found none — the test is checking the wrong thing."
+ )
+ for value in matches:
+ stripped = value.strip()
+ # Accept either the bare constant, or an f-string composition
+ # involving the constant (used for polite-pool email suffixing
+ # in OpenAlex).
+ assert "USER_AGENT" in stripped, (
+ f"{filename} sets User-Agent to {stripped!r}, which does not "
+ "reference the USER_AGENT constant. Use USER_AGENT (or a "
+ "composition like f'{USER_AGENT} ({email})') instead."
+ )