feat: add Tavily search support with Brave-compatible config#661
Closed
akirose wants to merge 2 commits intoHKUDS:mainfrom
Closed
feat: add Tavily search support with Brave-compatible config#661akirose wants to merge 2 commits intoHKUDS:mainfrom
akirose wants to merge 2 commits intoHKUDS:mainfrom
Conversation
Contributor
|
There's another PR which implements support for multiple search engines including Tavily #398 |
Collaborator
|
Because this issue has been inactive for a long time, I will close it. If there are any other problems, please feel free to open a new issue. |
WTHDonghai
pushed a commit
to WTHDonghai/nanobot
that referenced
this pull request
Mar 22, 2026
…KUDS#661) When tiktoken is unavailable, the fallback `len(text) // 3` severely underestimates tokens for CJK text (Chinese/Japanese/Korean characters are ~1-2 tokens each, not 0.33). This causes text exceeding the 8192-token API limit to bypass chunking, resulting in BadRequestError. Use `max(len(text) // 3, len(text.encode("utf-8")) // 4)` instead, which picks the more conservative estimate. For ASCII-heavy text the char-based estimate still wins; for CJK text the byte-based estimate correctly produces ~0.75 tokens per character. Fixes HKUDS#616, fixes HKUDS#634 Signed-off-by: JiangNan <1394485448@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR expands
web_searchfrom Brave-only to a multi-provider setup by adding first-class Tavily support.It centralizes search configuration through
WebSearchConfigand wires the same config through both the main agent and subagents so they share identical search behavior.It also preserves backward compatibility for legacy Brave config (
tools.web.search.apiKey) and adds stronger validation/normalization plus regression tests.Changed files
.gitignoretests/ignore ruleREADME.mdnanobot/config/schema.pyWebSearchConfig(provider,brave_api_key,tavily_api_key,tavily_search_depth) with normalization helpersnanobot/agent/tools/web.pyWebSearchToolto support both Brave and Tavily, with provider-specific request/error handlingnanobot/agent/loop.pyweb_search_configinjection and passed it to tool setup +SubagentManagernanobot/agent/subagent.pyweb_search_configsupport so subagents use the same search settingsnanobot/cli/commands.pyweb_search_configinto bothAgentLoopconstruction pathstests/test_web_search.pytests/test_web_search_tool.pytests/test_web_search_config.pytests/test_search_injection_path.pytests/test_config_search_schema.pyConfig example
{ "tools": { "web": { "search": { "provider": "tavily", "tavilyApiKey": "tvly-xxx", "maxResults": 5, "tavilySearchDepth": "advanced" } } } }Brave example:
{ "tools": { "web": { "search": { "provider": "brave", "braveApiKey": "BSA-xxx", "maxResults": 5 } } } }Test plan
WebSearchConfignormalizesproviderandtavilySearchDepth(trim + lowercase)provider/tavilySearchDepthraises validation errorsbraveApiKeyand still supports legacyapiKeyfallbacktavilyApiKey,search_depth, andmax_resultscorrectlyAgentLoop -> SubagentManager -> WebSearchToolshares the same config object