Brave Search

BraveSearch enables an Agent to search the web for information using the Brave search engine.

Prerequisites

The following examples requires the brave-search library.

1uv pip install -U brave-search
1export BRAVE_API_KEY=***

Example

1from kern.agent import Agent
2from kern.tools.bravesearch import BraveSearchTools
3
4agent = Agent(
5 tools=[BraveSearchTools()],
6 description="You are a news agent that helps users find the latest news.",
7 instructions=[
8 "Given a topic by the user, respond with 4 latest news items about that topic."
9 ],
10 )
11agent.print_response("AI Agents", markdown=True)

Toolkit Params

ParameterTypeDefaultDescription
api_keyOptional[str]NoneBrave API key. If not provided, will use BRAVE_API_KEY environment variable.
fixed_max_resultsOptional[int]NoneA fixed number of maximum results.
fixed_languageOptional[str]NoneA fixed language for the search results.
enable_brave_searchboolTrueEnable or disable the brave_search function.
allboolFalseEnable all available functions in the toolkit.

Toolkit Functions

FunctionDescription
brave_searchSearches Brave for a specified query. Parameters include query (str) for the search term, max_results (int, default=5) for the maximum number of results, country (str, default="US") for the country code for search results, and search_lang (str, default="en") for the language of the search results. Returns a JSON formatted string containing the search results.

Developer Resources