Google Serper Search Tool

Guide for using the Google Serper Search tool with PraisonAI agents.

The Google Serper Search tool lets an agent query Google results through the Serper API.

Diagram

Google Serper

User

Agent

GoogleSerperAPIWrapper

Serper API

Results

Overview

The Google Serper Search tool is a tool that allows you to search the web using the Google Serper API.

bash
pip install langchain-community python-dotenv
export SERPER_API_KEY="${SERPER_API_KEY:?Set SERPER_API_KEY in your shell}"
export OPENAI_API_KEY="${OPENAI_API_KEY:?Set OPENAI_API_KEY in your shell}"
python
from praisonaiagents import Agent, AgentTeam
from langchain_community.utilities import GoogleSerperAPIWrapper
import os
from dotenv import load_dotenv

load_dotenv()

os.environ['SERPER_API_KEY'] = os.getenv('SERPER_API_KEY')

search = GoogleSerperAPIWrapper()

data_agent = Agent(instructions="Suggest me top 5 most visited websites for Dosa Recipe", tools=[search])
editor_agent = Agent(instructions="List out the websites with their url and a short description")
agents = AgentTeam(agents=[data_agent, editor_agent])
agents.start()

How It Works

Diagram
Serper APIGoogleSerperAPIWrapperAgentUserSerper APIGoogleSerperAPIWrapperAgentUser“Search for X”run(query)HTTPS requestresultsparsed resultfinal answer

Getting Started

  1. Simple Usage
    1. Install dependencies (see Overview above)
    2. Set required API keys in your environment
    3. Run the agent example in Overview
  2. With Configuration

    Use the same tool with an agent — see the Overview example, or pass env vars from the sections above.

Best Practices

Keep SERPER_API_KEY in the environment

Set SERPER_API_KEY in your shell or .env. GoogleSerperAPIWrapper reads it automatically — never hard-code the key.

Reuse one wrapper instance

Create a single GoogleSerperAPIWrapper() and pass it to the agent. It is cheaper than re-instantiating per call.

Handle rate limits

Serper returns HTTP 429 when the plan quota is exceeded. Wrap the call in try/except so the agent can degrade to another search tool.

Related Tools