Implementation:CrewAIInc CrewAI Serper Dev Tool
| Knowledge Sources | |
|---|---|
| Domains | Web Search, Tool Integration, Information Retrieval |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
SerperDevTool is a CrewAI tool that performs internet searches via the Serper.dev API, supporting both general web search and news search with structured, typed result processing.
Description
The tool extends BaseTool and provides configurable internet search functionality through the Serper.dev Google Search API. It defines multiple TypedDict classes for strongly typed response data:
- KnowledgeGraph -- Title, type, website, image, description, and attributes from Google's knowledge panel.
- OrganicResult -- Title, link, snippet, position, and sitelinks for standard search results.
- PeopleAlsoAskResult -- Question, snippet, title, and link for "People Also Ask" results.
- RelatedSearchResult -- Related search queries.
- NewsResult -- Title, link, snippet, date, source, and image for news results.
- FormattedResults -- The top-level container combining all result types.
The _run method orchestrates the search workflow: it validates the search query, calls _make_api_request to POST to the appropriate Serper endpoint (https://google.serper.dev/search or /news) with the API key from SERPER_API_KEY, then delegates to type-specific processors that extract and normalize fields, limiting results to n_results. Configurable country, location, and locale filters allow for geo-targeted searches. Results can optionally be saved to timestamped files.
Usage
Use this tool when agents need to perform internet searches, gather web intelligence, retrieve news articles, or find information about topics, companies, products, or people. It supports two search types: "search" for general web results and "news" for news-specific results.
Code Reference
Source Location
- Repository: CrewAI
- File: lib/crewai-tools/src/crewai_tools/tools/serper_dev_tool/serper_dev_tool.py
- Lines: 1-343
Signature
class SerperDevTool(BaseTool):
name: str = "Search the internet with Serper"
description: str = (
"A tool that can be used to search the internet with a search_query. "
"Supports different search types: 'search' (default), 'news'"
)
args_schema: type[BaseModel] = SerperDevToolSchema
base_url: str = "https://google.serper.dev"
n_results: int = 10
save_file: bool = False
search_type: str = "search"
country: str | None = ""
location: str | None = ""
locale: str | None = ""
env_vars: list[EnvVar] # Requires SERPER_API_KEY
Import
from crewai_tools.tools.serper_dev_tool.serper_dev_tool import SerperDevTool
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| search_query | str | Yes | The search query to use for internet search |
| search_type | str | No | Type of search: "search" (default) or "news" |
| save_file | bool | No | Whether to save results to a timestamped file (default: False) |
Constructor Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| base_url | str | No | Base URL for Serper API (default: "https://google.serper.dev") |
| n_results | int | No | Maximum number of results to return (default: 10) |
| save_file | bool | No | Whether to save results to file by default (default: False) |
| search_type | str | No | Default search type: "search" or "news" (default: "search") |
| country | str | No | Country code for geo-targeted results (e.g., "us") |
| location | str | No | Location string for geo-targeted results |
| locale | str | No | Locale code for language-specific results (e.g., "en") |
Outputs
| Name | Type | Description |
|---|---|---|
| return | FormattedResults | Dictionary containing searchParameters, organic results, knowledgeGraph, peopleAlsoAsk, relatedSearches, news (for news search type), and credits used |
Usage Examples
Basic Usage
import os
os.environ["SERPER_API_KEY"] = "your-serper-api-key"
from crewai_tools.tools.serper_dev_tool.serper_dev_tool import SerperDevTool
# General web search
tool = SerperDevTool(n_results=5)
results = tool._run(search_query="CrewAI multi-agent framework")
# News search with geo-targeting
tool = SerperDevTool(search_type="news", country="us", n_results=10)
results = tool._run(search_query="artificial intelligence breakthroughs")
# Save results to file
tool = SerperDevTool(save_file=True)
results = tool._run(search_query="Python best practices 2025")