ModelBox Open Source

/

AgentKit
Core Concepts/Tools/Built-in Tools/SerpAPI Tool

SerpAPI Tool

Multi-engine search across Google, Bing, Yahoo and more

|

The SerpAPI tool provides search functionality across multiple search engines including Google, Bing, Yahoo, and more.

Installation

import "github.com/model-box/agent-kit/tool/serp_api"

Setup

Requirements

  1. SerpAPI Key: Sign up at SerpAPI
  2. API Access: Free tier includes 100 searches per month

Environment Variables

export SERPAPI_API_KEY="your-serpapi-key"

Usage

package main

import (
    "context"
    "os"
    
    "github.com/model-box/agent-kit/agent"
    "github.com/model-box/agent-kit/model"
    "github.com/model-box/agent-kit/session"
    "github.com/model-box/agent-kit/tool/serp_api"
)

func main() {
    // Create SerpAPI tools
    serpTools := serp_api.NewSerpAPITools()
    
    // Create model
    model := model.Model("gpt-4o").
        SetAPIKey(os.Getenv("OPENAI_API_KEY"))
    
    // Create agent with SerpAPI tools
    agent := agent.New().
        SetModel(model).
        SetSystemPrompt("You are a research assistant with multi-engine search capabilities.").
        AddTool(serpTools.Search()).
        AddTool(serpTools.ImageSearch())
    
    // Create session and run
    session := session.New(agent)
    ctx := context.Background()
    
    response, err := session.Run(ctx, []agent.ChatMessage{
        agent.NewUserMessage("Search for 'golang best practices' on Google and Bing"),
    }, nil)
    
    if err != nil {
        panic(err)
    }
    
    println(response.GetLastMessage().GetContent())
}

Available Tools

Search multiple search engines.

ParameterTypeRequiredDescription
querystringYesThe search query
enginestringNo"google", "bing", "baidu", "yandex", "yahoo", "ebay", "youtube" (default: "google")
locationstringNoLocation for local results (e.g., "Austin, Texas, United States")
hlstringNoLanguage code (e.g., "en", "fr", "de") (default: "en")
glstringNoCountry code (e.g., "us", "uk", "fr") (default: "us")
num_resultsintNoNumber of results per page (default: 10)
startintNoResult offset for pagination (default: 0)
safe_searchstringNo"active" or "off" (default: "off")

Search for images using Google Images.

ParameterTypeRequiredDescription
querystringYesThe image search query
locationstringNoLocation for local results
hlstringNoLanguage code (default: "en")
glstringNoCountry code (default: "us")
num_resultsintNoNumber of results (default: 10)
image_typestringNo"clipart", "face", "lineart", "stock", "photo", "animated"
sizestringNo"large", "medium", "icon"

Supported Search Engines

  • Google: Full support with organic results, knowledge graph, related searches
  • Bing: Web search results
  • Baidu: Chinese search engine
  • Yandex: Russian search engine
  • Yahoo: Web search results
  • eBay: Product search
  • YouTube: Video search

Location Examples

For location-based searches:

  • "Austin, Texas, United States"
  • "London, England, United Kingdom"
  • "Paris, France"
  • "Tokyo, Japan"
  • "Sydney, New South Wales, Australia"

Rate Limits

  • Free plan: 100 searches/month
  • Basic plan: 5,000 searches/month
  • Professional: 30,000 searches/month
  • Business: 100,000+ searches/month

Advanced Features

SerpAPI provides additional data including:

  • Knowledge graphs
  • Related searches
  • People also ask
  • Local pack results
  • Shopping results
  • News results
  • Video results
Edit on GitHub