web_search_context
Web Search Context Manager.
Manages per-channel web-search configuration and provides automatic
context injection by generating search queries (via a cheap LLM) and
fetching results from the Brave Search API.
Adapted for the v3 multi-platform architecture: channel keys use the
platform:channel_id composite format.
-
class web_search_context.WebSearchContextManager(redis_client, default_api_key='', config=None)[source]
Bases: object
Per-channel automatic web-search context injection.
For every incoming message the manager:
1. Checks the channel config (enabled by default).
2. Calls search_query_generator.generate_search_queries() to
decide whether web search is warranted.
Runs Brave searches via the shared rate-limiter in
tools.brave_search.
Returns XML-formatted results for injection into the LLM context.
- Parameters:
-
-
__init__(redis_client, default_api_key='', config=None)[source]
Initialize the instance.
- Parameters:
redis_client (Redis) – Redis connection client.
default_api_key (str) – The default api key value.
config (Any) – Bot config (for api_key_encryption_db_path).
- Return type:
None
-
async set_channel_config(channel_key, enabled=True, max_queries=2, results_per_query=3)[source]
Set the channel config.
- Parameters:
channel_key (str) – The channel key value.
enabled (bool) – The enabled value.
max_queries (int) – The max queries value.
results_per_query (int) – The results per query value.
- Returns:
The result.
- Return type:
Dict[str, Any]
-
async get_channel_config(channel_key)[source]
Retrieve the channel config.
- Parameters:
channel_key (str) – The channel key value.
- Returns:
The result.
- Return type:
Optional[Dict[str, Any]]
-
async disable_channel(channel_key)[source]
Disable channel.
- Parameters:
channel_key (str) – The channel key value.
- Returns:
True on success, False otherwise.
- Return type:
bool
-
async remove_channel_config(channel_key)[source]
Delete the specified channel config.
- Parameters:
channel_key (str) – The channel key value.
- Returns:
True on success, False otherwise.
- Return type:
bool
-
async search_for_message(channel_key, message_content, *, user_id='', redis_client=None, channel_id='')[source]
Run automatic web search for message_content.
Returns XML-formatted context suitable for injection into the
LLM message list, or None when no search is warranted.
- Return type:
Optional[str]
- Parameters:
-