Reliable DuckDuckGo web and image search tools for LM Studio with stronger anti-block resilience, better output consistency for LLM tool chaining, and cleaner diagnostics.
What was broken before
The previous implementation had several practical issues in real usage:
Web search sometimes returned only https://duckduckgo.com/ instead of actual results.
DDG redirect links were not decoded correctly, so target URLs were lost.
Internal DuckDuckGo links polluted the final output and looked like "valid" search hits.
Label extraction was noisy because HTML text was not normalized robustly.
Image search frequently failed with Forbidden or Unable to extract vqd token with no useful fallback path.
Image filtering was too strict (URL extension based), dropping valid CDN images without .jpg/.png suffixes.
Download stage could report confusing outcomes (including false-positive success patterns in older behavior).
Tool-output shape encouraged weak orchestration in some models (extra unnecessary calls to downstream image tools).
What is fixed in this reworked version
Web Search quality improvements
Uses https://html.duckduckgo.com/html/ for more stable HTML result pages.
Replaces fragile URL regex extraction with anchor-level parsing (<a href=...>).
Decodes DuckDuckGo redirect links via uddg into real destination URLs.
Filters out internal DuckDuckGo service/home links from results.
Cleans HTML labels and normalizes whitespace for readable output.
Image Search reliability improvements
Added resilient retry/backoff for DDG requests (vqd bootstrap and endpoint).
Multi-source fallback (no API keys)
When DDG image endpoint is blocked or unstable, Image Search now automatically runs a fallback chain:
DuckDuckGo web results (html.duckduckgo.com)
Extract image candidates from top pages (src, data-src, data-original, srcset, markdown image links)
Download and validate candidates (content-type: image/*)
Return renderable local markdown images
Fallback responses include source: "web_fallback" when that path was used.
Output consistency for LLM tool use
Image Search returns renderable markdown images in a consistent shape:
images
count
hint (that images are already downloaded/renderable)
This reduces redundant tool hops and improves assistant decision quality in multi-tool flows.
Better result reliability (general)
Preserves deduplication, pagination (page, pageSize), and safeSearch behavior.