Serpapi

SerpApiTools enable an Agent to search Google and YouTube for a query.

Prerequisites

The following example requires the google-search-results library and an API key from SerpApi.

1uv pip install -U google-search-results
1export SERP_API_KEY=***

Example

The following agent will search Google for the query: "Whats happening in the USA" and share results.

1from kern.agent import Agent
2from kern.tools.serpapi import SerpApiTools
3
4agent = Agent(tools=[SerpApiTools()])
5agent.print_response("Whats happening in the USA?", markdown=True)

Toolkit Params

ParameterTypeDefaultDescription
api_keyOptional[str]NoneSerpApi API key. If not provided, will use SERP_API_KEY environment variable.
enable_search_googleboolTrueEnable Google search functionality.
enable_search_youtubeboolFalseEnable YouTube search functionality.
allboolFalseEnable all available functions in the toolkit.

Toolkit Functions

FunctionDescription
search_googleSearch Google using the Serpapi API. Parameters include query (str) for the search query and num_results (int, default=10) for the number of results. Returns JSON formatted search results with organic results, recipes, shopping results, knowledge graph, and related questions.
search_youtubeSearch YouTube using the Serpapi API. Parameters include query (str) for the search query. Returns JSON formatted search results with video results, movie results, and channel results.

Developer Resources