Introduction
- playgroundโ You can see the demo code on the playground.
This tutorial guides you through setting up a fully functional Google Shopping Agent using Agentica. With the following code block, you can create an agent that interacts with Google Shopping, powered by OpenAIโs GPT model.
The Complete Google Shopping Agent
First, install the required Google Shopping connector package:
npm install @wrtnlabs/connector-google-shopping
Then, add the following code to your project:
import { Agentica } from "@agentica/core";
import { GoogleShoppingService } from "@wrtnlabs/connector-google-shopping";
import dotenv from "dotenv";
import OpenAI from "openai";
import typia from "typia";
dotenv.config();
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
export const GoogleShoppingAgent = new Agentica({
model: "chatgpt",
vendor: {
api: openai,
model: "gpt-4o-mini",
},
controllers: [
{
name: "Google Shopping Connector",
protocol: "class",
application: typia.llm.application<GoogleShoppingService, "chatgpt">(),
execute: new GoogleShoppingService({
apiKey: process.env.SERP_API_KEY!,
}),
},
],
});
What This Does
With this single setup, your Google Shopping Agent is ready to:
- Process Google Shopping data using the
GoogleShopping
connector. - Leverage OpenAIโs GPT model for intelligent shopping queries.
- Ensure type safety with
typia
. - Securely manage credentials using
dotenv
.
Just set up your environment variables in a .env
file:
OPENAI_API_KEY=your_openai_api_key
SERP_API_KEY=serp_api_key
Make sure to enter the API key from your SerpApi account in the SERP_API_KEY field.
And youโre all set! ๐
Selecting Specific Functions
By using TypeScriptโs Pick
utility type, you can restrict the GoogleShoppingService
to only expose the methods you need.
For example, in the following code, only these six functions are available:
aliExpress
iherb
export const GoogleShoppingAgent = new Agentica({
model: "chatgpt",
vendor: {
api: openai,
model: "gpt-4o-mini",
},
controllers: [
{
name: "Google Shopping Connector",
protocol: "class",
application: typia.llm.application<
Pick<GoogleShoppingService, "aliExpress" | "iherb">,
"chatgpt"
>(),
execute: new GoogleShoppingService({
apiKey: process.env.SERP_API_KEY!,
}),
},
],
});
This ensures that the GoogleShoppingAgent
only has access to these specific functions, making your integration more secure and maintainable.
Use Case Example
Imagine asking the agent:
โWhat are the best medications for hair loss?โ
The agent can then use the iherb
function to search for hair loss medications on iHerb, providing you with the best options available.
Available Functions
For a list of available functions in GoogleShoppingService
, check out the source code:
๐ wrtnlabs/connectors - GoogleShoppingService.tsโ
Thatโs it. This single code block gives you a fully functional Google Shopping Agent, ready for AI-powered google shoppiong automation. ๐