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.

fix(examples): make mock LLM example truly offline + reject search.tool='none' (#3520)

LearningCircuit901d0db8d9e7
diff --git a/.github/workflows/docker-tests.yml b/.github/workflows/docker-tests.yml
index a88eba36bb..e0727bf2a0 100644
--- a/.github/workflows/docker-tests.yml
+++ b/.github/workflows/docker-tests.yml
@@ -903,15 +903,11 @@ jobs:
- name: Load Docker image
run: docker load --input /tmp/ldr-test.tar
- - name: Test basic custom LLM example
- run: |
- docker run --rm \
- -v "$PWD":/app \
- -e PYTHONPATH=/app \
- -w /app \
- ${{ env.TEST_IMAGE }} \
- sh -c "timeout 60s python examples/llm_integration/basic_custom_llm.py"
-
+ # basic_custom_llm.py and advanced_custom_llm.py are intentionally NOT
+ # executed in CI: they run real research pipelines against Wikipedia and
+ # PubMed, which makes them flaky under a 60s budget. The examples are
+ # kept in the repo as documentation and are covered by the compile check
+ # below; mock_llm_example.py exercises the same integration path offline.
- name: Test mock LLM example
run: |
docker run --rm \
@@ -921,15 +917,6 @@ jobs:
${{ env.TEST_IMAGE }} \
sh -c "timeout 60s python examples/llm_integration/mock_llm_example.py"
- - name: Test advanced custom LLM example
- run: |
- docker run --rm \
- -v "$PWD":/app \
- -e PYTHONPATH=/app \
- -w /app \
- ${{ env.TEST_IMAGE }} \
- sh -c "timeout 60s python examples/llm_integration/advanced_custom_llm.py"
-
- name: Test direct import
run: |
docker run --rm \
@@ -963,6 +950,8 @@ jobs:
python -m py_compile examples/api_usage/programmatic/searxng_example.py &&
python -m py_compile examples/api_usage/programmatic/custom_llm_retriever_example.py &&
python -m py_compile examples/api_usage/programmatic/hybrid_search_example.py &&
+ python -m py_compile examples/llm_integration/basic_custom_llm.py &&
+ python -m py_compile examples/llm_integration/advanced_custom_llm.py &&
python -m py_compile examples/api_usage/http/simple_working_example.py &&
python -m py_compile examples/api_usage/http/advanced/http_api_examples.py &&
python -m py_compile examples/api_usage/http/advanced/simple_http_example.py &&
diff --git a/examples/llm_integration/mock_llm_example.py b/examples/llm_integration/mock_llm_example.py
index 5fb8376c0c..ee0646f35b 100644
--- a/examples/llm_integration/mock_llm_example.py
+++ b/examples/llm_integration/mock_llm_example.py
@@ -12,9 +12,11 @@ useful for:
import json
from typing import Any, Dict, List, Optional
+from langchain_core.documents import Document
from langchain_core.language_models import BaseChatModel
from langchain_core.messages import AIMessage, BaseMessage
from langchain_core.outputs import ChatGeneration, ChatResult
+from langchain_core.retrievers import BaseRetriever
from local_deep_research.api import (
create_settings_snapshot,
@@ -184,6 +186,26 @@ class ScenarioMockLLM(BaseChatModel):
return f"scenario_{self.scenario}"
+class MockRetriever(BaseRetriever):
+ """Offline retriever returning canned documents.
+
+ Registered as a search engine to keep the pipeline fully offline —
+ otherwise falling back to the default engines hits live services.
+ """
+
+ def _get_relevant_documents(self, query, *, run_manager=None):
+ return [
+ Document(
+ page_content=f"Mock document 1 about {query}",
+ metadata={"source": "mock://doc1"},
+ ),
+ Document(
+ page_content=f"Mock document 2 about {query}",
+ metadata={"source": "mock://doc2"},
+ ),
+ ]
+
+
def test_basic_mock():
"""Test basic mock functionality."""
print("Testing Basic Mock LLM")
@@ -193,11 +215,12 @@ def test_basic_mock():
snapshot = create_settings_snapshot(
provider="mock",
- overrides={"search.tool": "none"},
+ overrides={"search.tool": "mock_retriever"},
)
result = quick_summary(
query="Tell me about quantum computing",
llms={"mock": mock_llm},
+ retrievers={"mock_retriever": MockRetriever()},
settings_snapshot=snapshot,
iterations=1,
)
@@ -221,11 +244,12 @@ def test_scenario_mocks():
try:
snapshot = create_settings_snapshot(
provider=f"mock_{scenario}",
- overrides={"search.tool": "none"},
+ overrides={"search.tool": "mock_retriever"},
)
result = quick_summary(
query="Test query for scenario",
llms={f"mock_{scenario}": mock_llm},
+ retrievers={"mock_retriever": MockRetriever()},
settings_snapshot=snapshot,
iterations=1,
)
@@ -255,11 +279,12 @@ def test_mock_in_pipeline():
# Test with report generation
snapshot = create_settings_snapshot(
provider="pipeline_mock",
- overrides={"search.tool": "none"},
+ overrides={"search.tool": "mock_retriever"},
)
report = generate_report(
query="Create a comprehensive report",
llms={"pipeline_mock": mock_llm},
+ retrievers={"mock_retriever": MockRetriever()},
settings_snapshot=snapshot,
searches_per_section=1,
)
@@ -283,19 +308,6 @@ def test_mock_with_custom_retriever():
print("\nTesting Mock LLM with Custom Retriever")
print("-" * 40)
- class MockRetriever:
- def get_relevant_documents(self, query):
- return [
- {
- "page_content": f"Document 1 about {query}",
- "metadata": {"source": "test1"},
- },
- {
- "page_content": f"Document 2 about {query}",
- "metadata": {"source": "test2"},
- },
- ]
-
mock_llm = MockLLM(
response_map={
"default": "Analyzed documents and found relevant information.",
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 f3c75f627a..54701b2c44 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
@@ -83,6 +83,17 @@ def create_search_engine(
"settings_snapshot is required for search engine creation in threads"
)
+ if engine_name == "none":
+ # Reject the literal string "none". Historically this silently fell
+ # through to the "auto" engine and hit live networks — callers that
+ # wanted an offline pipeline were unknowingly doing real searches.
+ raise ValueError(
+ "search.tool='none' is not a valid engine. Register a LangChain "
+ "retriever via `retrievers={...}` (see "
+ "examples/llm_integration/mock_llm_example.py) or pick a real "
+ "engine. Previously this silently fell back to 'auto'."
+ )
+
if engine_name not in config:
# Check if engine_name might be a display label instead of a config key
# Display labels have format: "{icon} {base_name} ({category})"
diff --git a/tests/web_search_engines/test_search_engine_factory.py b/tests/web_search_engines/test_search_engine_factory.py
index d48bea2e22..bf212b373b 100644
--- a/tests/web_search_engines/test_search_engine_factory.py
+++ b/tests/web_search_engines/test_search_engine_factory.py
@@ -810,3 +810,12 @@ class TestCreateEngineInstantiation:
assert EngCls._call_kwargs["region"] == "us"
# kwargs max_results should be present
assert EngCls._call_kwargs["max_results"] == 15
+
+ def test_none_engine_rejected(self):
+ """search.tool='none' raises ValueError instead of silent auto-fallback."""
+ from local_deep_research.web_search_engines.search_engine_factory import (
+ create_search_engine,
+ )
+
+ with pytest.raises(ValueError, match="search.tool='none'"):
+ create_search_engine("none", settings_snapshot={"x": 1})