tools.brave_search module
Web search via the Brave Search API with rate limiting and key rotation.
- class tools.brave_search.BraveAPIKeyManager[source]
Bases:
objectRound-robin API key manager with automatic rotation.
- load_keys(config)[source]
Load keys from the configured source.
- Parameters:
config – Bot configuration object.
- class tools.brave_search.BraveSearchTask(query, count, country, search_lang, ui_lang, safesearch, future, user_api_key=None, user_id=None, redis_client=None)[source]
Bases:
objectBraveSearchTask.
- Parameters:
- future: Future
- class tools.brave_search.BraveSearchRateLimiter(calls_per_interval=0.5, interval_seconds=1.0)[source]
Bases:
objectGlobal rate limiter that serialises Brave API calls.
- async tools.brave_search.search_with_key(query, count=3, api_key=None)[source]
Execute a Brave search through the shared rate limiter.
This is the entry point for internal callers (e.g.
WebSearchContextManager) that already have a resolved API key and don’t need the tool-context ceremony.
- async tools.brave_search.run(query, count=10, country=None, search_lang=None, ui_lang=None, safesearch='off', ctx=None)[source]
Execute this tool and return the result.
- Parameters:
query (
str) – Search query or input string.count (
int) – Number of results to return.country (
str) – The country value.search_lang (
str) – The search lang value.ui_lang (
str) – The ui lang value.safesearch (
str) – The safesearch value.ctx – Tool execution context providing access to bot internals.
- Returns:
Result string.
- Return type: