Mastra is a powerful framework for building AI agents that can interact with GBOX’s headless browser infrastructure. It allows you to create sophisticated AI assistants that can automate tasks, perform web scraping, and interact with web applications.
Create src/mastra/agents/index.ts with the following content:
Copy
import { createOpenAI } from "@ai-sdk/openai";import { Agent } from "@mastra/core/agent";import { searchRedditTool } from "../tools";import dotenv from "dotenv";// Load environment variablesdotenv.config();// Configure OpenAI with API keyconst openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY || "",});export const webAgent = new Agent({ name: "Web Assistant", instructions: ` You are product manager and a helpful web assistant that can navigate websites and extract information. You can use the searchReddit tool to find relevant information on Reddit. When searching for information: 1. Use the searchReddit tool to find relevant posts 2. Summarize the key findings from multiple posts 3. Highlight different perspectives or opinions found 4. Provide context about the discussions `, model: openai("gpt-4o"), tools: { searchRedditTool },});
5
Initialize Mastra
Create src/mastra/index.ts with the following content:
Copy
import { Mastra } from "@mastra/core/mastra";import { ConsoleLogger } from "@mastra/core/logger";import { webAgent } from "./agents";export const mastra = new Mastra({ agents: { webAgent }, logger: new ConsoleLogger({ name: "Mastra", level: "info", }),});