Google Trends Tool

Guide for using the Google Trends tool with PraisonAI agents.

The Google Trends tool lets an agent pull trending-topic data through the SerpAPI Google Trends endpoint.

Diagram

Google Trends

User

Agent

GoogleTrendsAPIWrapper

Google Trends API

Trend Data

Overview

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

bash
pip install langchain-community google-search-results
bash
export SERPAPI_API_KEY="${SERPAPI_API_KEY:?Set SERPAPI_API_KEY in your shell}"
python
from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper
from praisonaiagents import Agent, AgentTeam

research_agent = Agent(
    instructions="Research trending topics related to AI",
    tools=[GoogleTrendsAPIWrapper]
)

summarise_agent = Agent(
    instructions="Summarise findings from the research agent",
)

agents = AgentTeam(agents=[research_agent, summarise_agent])
agents.start()

How It Works

Diagram
Google Trends APIGoogleTrendsAPIWrapperAgentUserGoogle Trends APIGoogleTrendsAPIWrapperAgentUser“What is trending on X”run(query)HTTPS requestinterest-over-time dataparsed 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 SERPAPI_API_KEY in the environment

Google Trends here runs through SerpAPI, so set SERPAPI_API_KEY in your shell or .env. Never hard-code the key.

Query specific terms

Trends data is per keyword. Feed the agent concrete terms rather than broad phrases so the returned interest data is meaningful.

Handle quota errors

SerpAPI enforces a monthly search quota. Wrap the call in try/except so the agent can report a clean message when the quota is hit.

Related Tools