tools / search.py

Anonymous web search via DuckDuckGo + Tor, with reformulated fallbacks and multi-source synthesis.

Tools

ToolPurpose
web_searchDDG search via ddgs with Tor SOCKS proxy. 3 retries on transient errors. request_new_tor_identity() is called on 401/403/503 to rotate Tor circuits.
deep_researchSearches multiple reformulations and synthesises results via the LLM. Falls back to web_search when synthesis fails.
fact_checkVerifies a claim by calling deep_research as a sub-process.

Reformulation strategy

  1. Drop years / version numbers / numbers from the query (broaden).
  2. Convert to a question form ("how to X").
  3. Append tutorial / guide / example.

Output cleaning

_clean_for_cpp preserves valid JSON but strips control characters and structural braces from non-JSON text. This prevents the C++ JSON parser inside llama.cpp from crashing on stray {…} in scraped page bodies.