Skip to Content

Introduction

Set up a fully functional Google Search Agent powered by OpenAIโ€™s GPT model quickly using the Agentica CLI.

Quick CLI Setup

Start the Agentica Setup Wizard with this single command:

npx agentica start google-search-agent

The wizard guides you through:

  • Installing required packages (e.g., [email protected])
  • Choosing your package manager and project type
  • Selecting the GOOGLE SEARCH controller
  • Entering your OPENAI_API_KEY

Once complete, Agentica automatically generates your code, creates a .env file, and installs all dependencies.

Generated Code Overview

The generated code looks like this:

import { Agentica } from "@agentica/core"; import typia from "typia"; import dotenv from "dotenv"; import { OpenAI } from "openai"; import { GoogleSearchService } from "@wrtnlabs/connector-google-search"; dotenv.config(); export const agent = new Agentica({ model: "chatgpt", vendor: { api: new OpenAI({ apiKey: process.env.OPENAI_API_KEY!, }), model: "gpt-4o-mini", }, controllers: [ { name: "GoogleSearch Connector", protocol: "class", application: typia.llm.application<GoogleSearchService, "chatgpt">(), execute: new GoogleSearchService(), }, ], }); const main = async () => { console.log(await agent.conversate("What can you do?")); }; main();

This code instantly sets up your Google Search Agent, ready to perform intelligent search queries on Google.

What This Does

Your Google Search Agent will:

  • Process Google Search Data: Use the GoogleSearchService connector.
  • Leverage OpenAIโ€™s GPT Model: For smart search queries.
  • Maintain Type Safety: With typia.
  • Securely Manage Credentials: Using environment variables via dotenv.

Set up your environment variables in a .env file:

OPENAI_API_KEY=your-openai-api-key SERPAPI_API_KEY=your-serp-api-api-key

Make sure to include your SerpApi API key in the SERPAPI_API_KEY field.

Use Case Example

Imagine asking the agent:

โ€œFind the best pizza places in New York City with outdoor seatingโ€

The agent will search Google for top-rated pizza restaurants in New York City that offer outdoor seating, and provide you with relevant information on locations, ratings, reviews, and features.

Available Functions

For a complete list of functions available in GoogleSearchService, check out the source code:
๐Ÿ‘‰ wrtnlabs/connectors - GoogleSearchService.tsโ€‰

Your AI-powered Google Search Agent is now ready for seamless, automated search queries! ๐Ÿš€

Last updated on