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: Improve settings handling in programmatic API

LearningCircuit4dba4b9d4280
diff --git a/examples/api_usage/programmatic/simple_programmatic_example.py b/examples/api_usage/programmatic/simple_programmatic_example.py
index 9df2751a17..95b20c2d6a 100755
--- a/examples/api_usage/programmatic/simple_programmatic_example.py
+++ b/examples/api_usage/programmatic/simple_programmatic_example.py
@@ -6,28 +6,22 @@ Quick example showing how to use the LDR Python API directly.
"""
from local_deep_research.api import detailed_research, quick_summary
+from local_deep_research.api.settings_utils import (
+ create_settings_snapshot,
+)
+
+# Use default settings with minimal overrides
+# This provides all necessary settings with sensible defaults
+settings_snapshot = create_settings_snapshot(
+ overrides={
+ "programmatic_mode": True,
+ "search.tool": "wikipedia", # Use Wikipedia for this example
+ }
+)
-# Create a minimal settings snapshot for programmatic mode
-# You need to specify at least the LLM settings for programmatic mode
-settings_snapshot = {
- "programmatic_mode": True,
- # LLM settings
- "llm.provider": "ollama", # or "openai_endpoint", "openai", etc.
- "llm.model": "gemma3:12b", # or your preferred model
- "llm.temperature": 0.7,
- "llm.local_context_window_size": 8192,
- "llm.max_tokens": 4096,
- "llm.supports_max_tokens": True,
- # Search settings
- "search.tool": "wikipedia", # default search tool
- "search.max_results": 10,
- "search.region": "wt-wt",
- "search.time_period": "all",
- "search.safe_search": True,
- "search.snippets_only": True,
- "search.search_language": "English",
- "search.max_filtered_results": 5,
-}
+# Alternative: Use completely default settings
+# settings_snapshot = get_default_settings_snapshot()
+# Note: You may want to set programmatic_mode in the snapshot
# Example 1: Quick Summary
print("=== Quick Summary ===")
diff --git a/src/local_deep_research/config/search_config.py b/src/local_deep_research/config/search_config.py
index 113a90bdc1..9de29d3596 100644
--- a/src/local_deep_research/config/search_config.py
+++ b/src/local_deep_research/config/search_config.py
@@ -51,6 +51,15 @@ def get_search(
username=username,
settings_snapshot=settings_snapshot,
)
+
+ # Debug: Check if we got a dict instead of a string
+ if isinstance(tool, dict):
+ logger.warning(
+ f"Got dict for search.tool, extracting value: {tool.get('value')}"
+ )
+ if "value" in tool:
+ tool = tool["value"]
+
logger.info(
f"Creating search engine with tool: {tool} (type: {type(tool)})"
)
diff --git a/src/local_deep_research/config/thread_settings.py b/src/local_deep_research/config/thread_settings.py
index 2c53dd7b39..62ec96c1f5 100644
--- a/src/local_deep_research/config/thread_settings.py
+++ b/src/local_deep_research/config/thread_settings.py
@@ -65,7 +65,11 @@ def get_setting_from_snapshot(
hasattr(_thread_local, "settings_context")
and _thread_local.settings_context
):
- return _thread_local.settings_context.get_setting(key, default)
+ value = _thread_local.settings_context.get_setting(key, default)
+ # Extract value from dict structure if needed (same as above)
+ if isinstance(value, dict) and "value" in value:
+ return value["value"]
+ return value
# In CI/test environment with fallback LLM, return default values
if check_fallback_llm and os.environ.get("LDR_USE_FALLBACK_LLM", ""):