feat(community): add Brave Search web search tool (#3528)

* feat(community): add Brave Search web search tool

Add a community web_search provider backed by the official Brave Search
API (https://api.search.brave.com/res/v1/web/search). API key is read
from the tool config (inline api_key) or the BRAVE_SEARCH_API_KEY env
var. Output schema (title/url/content) matches existing search tools.
No new dependencies (uses the existing httpx). Also wires up the setup
wizard, doctor health check, config example, and EN/ZH docs.

* refactor(community): drop redundant [:count] slice in Brave search

The Brave API already caps results via the `count` request param, so
client-side slicing was redundant. Tests now simulate the API honoring
`count` instead of relying on the slice. Addresses PR review nit.

* style(tests): apply ruff format to test_doctor.py

Collapse multiline write_text calls onto single lines to satisfy the
CI ruff formatter (lint-backend was failing on format --check).
This commit is contained in:
Ryker_Feng
2026-06-13 22:47:35 +08:00
committed by GitHub
parent 8955b3222a
commit 6e839342a7
10 changed files with 582 additions and 7 deletions
+16 -4
View File
@@ -457,8 +457,9 @@ def check_web_tool(config_path: Path, *, tool_name: str, label: str) -> CheckRes
data = _load_yaml_file(config_path)
tool_uses = [t.get("use", "") for t in data.get("tools", []) if t.get("name") == tool_name]
if not tool_uses:
tool_entries = [t for t in data.get("tools", []) if t.get("name") == tool_name]
tool_uses = [t.get("use", "") for t in tool_entries]
if not tool_entries:
return CheckResult(
label,
"warn",
@@ -476,6 +477,7 @@ def check_web_tool(config_path: Path, *, tool_name: str, label: str) -> CheckRes
"infoquest": "INFOQUEST_API_KEY",
"exa": "EXA_API_KEY",
"firecrawl": "FIRECRAWL_API_KEY",
"brave": "BRAVE_SEARCH_API_KEY",
},
"web_fetch": {
"infoquest": "INFOQUEST_API_KEY",
@@ -484,14 +486,24 @@ def check_web_tool(config_path: Path, *, tool_name: str, label: str) -> CheckRes
},
}
for use in tool_uses:
for tool_entry in tool_entries:
use = tool_entry.get("use", "")
for provider, detail in free_providers.get(tool_name, {}).items():
if provider in use:
return CheckResult(label, "ok", detail)
for use in tool_uses:
for tool_entry in tool_entries:
use = tool_entry.get("use", "")
for provider, var in key_providers.get(tool_name, {}).items():
if provider in use:
configured_key = tool_entry.get("api_key")
if isinstance(configured_key, str) and configured_key.strip():
if configured_key.startswith("$"):
ref_var = configured_key[1:]
if os.environ.get(ref_var):
return CheckResult(label, "ok", f"{provider} ({ref_var} set via api_key)")
else:
return CheckResult(label, "ok", f"{provider} (api_key configured)")
val = os.environ.get(var)
if val:
return CheckResult(label, "ok", f"{provider} ({var} set)")
+8
View File
@@ -510,6 +510,14 @@ SEARCH_PROVIDERS: list[SearchProvider] = [
env_var="FIRECRAWL_API_KEY",
extra_config={"max_results": 5},
),
SearchProvider(
name="brave",
display_name="Brave Search",
description="Independent index, official API, API key required",
use="deerflow.community.brave.tools:web_search_tool",
env_var="BRAVE_SEARCH_API_KEY",
extra_config={"max_results": 5},
),
]
WEB_FETCH_PROVIDERS: list[WebProvider] = [