feat(tools): add DeepSeek Search as a web_search provider

Add a standalone `deepseek` search backend that calls the DeepSeek Search
API (POST https://api.deepseek.com/v1/tools/search), following the
provider layout used by AnySearch (#5607) and Bocha (#4182).

This is a search-only integration. It does not touch the DeepSeek LLM
provider, does not inject a `web_search` tool into model requests, and
does not implement the Fetch endpoint.

- Trim and truncate queries to the API's 128 Unicode-character limit
  locally, rejecting whitespace-only queries without a network call.
- Clamp `count` to the API's 1-50 range and always send
  `need_content: false` so page bodies stay out of the model context.
- Format results from `summary`, falling back to `snippet` when a summary
  is missing or blank, and include `date` when present. Cap each result's
  text at 500 characters: live responses reach ~4,500 characters, so ten
  uncapped results cost roughly 10k tokens per call.
- Return actionable 401 and 402 messages; retry 408/429/5xx once after
  1.0s like the Brave provider; surface `error.message` for other 4xx,
  tag-stripped because the upstream body is untrusted. Unexpected
  transport errors report the exception type only, with the detail
  logged when tool log content is allowed.
- Read the key from `tools.web.search.apiKey` or `DEEPSEEK_API_KEY` and
  fall back to DuckDuckGo when neither is set, like other keyed
  providers. The key is never logged or echoed in errors.
- Register the provider for the CLI wizard and WebUI settings, and reuse
  the bundled DeepSeek brand asset.
This commit is contained in:
moran authored and chengyongru committed 2026-10-19 16:50:17 +08:00
1 parent 5d886fbb20
commit e5b469ebd4
5 files changed
+759 -2

No files matched your search

+37
View File
@@ -1417,6 +1417,43 @@ def test_update_web_search_settings_can_clear_optional_api_key(
assert saved.tools.web.search.api_key == ""
def test_update_web_search_settings_accepts_deepseek_with_api_key(
tmp_path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
config_path = tmp_path / "config.json"
config = Config()
config.tools.web.search.provider = "duckduckgo"
save_config(config, config_path)
monkeypatch.setattr("nanobot.config.loader._current_config_path", config_path)
payload = update_web_search_settings(
{"provider": ["deepseek"], "api_key": ["sk-deepseek-search"]}
)
saved = load_config(config_path)
assert saved.tools.web.search.provider == "deepseek"
assert saved.tools.web.search.api_key == "sk-deepseek-search"
option = next(item for item in payload["web_search"]["providers"] if item["name"] == "deepseek")
assert option["label"] == "DeepSeek"
assert option["credential"] == "api_key"
def test_update_web_search_settings_requires_deepseek_api_key(
tmp_path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
config_path = tmp_path / "config.json"
config = Config()
save_config(config, config_path)
monkeypatch.setattr("nanobot.config.loader._current_config_path", config_path)
with pytest.raises(WebUISettingsError, match="api_key is required"):
update_web_search_settings({"provider": ["deepseek"]})
assert load_config(config_path).tools.web.search.provider == "duckduckgo"
def test_settings_payload_includes_effective_transcription_config(
tmp_path,
monkeypatch: pytest.MonkeyPatch,