Build AI-powered web automation agents with Mastra and Stagehand
Get your Browserbase API Key
Go over the Dashboard’s Settings tab:
Then copy your API Key directly from the input and set the BROWSERBASE_API_KEY
and BROWSERBASE_PROJECT_ID
environment variables.
Get your OpenAI API Key
Create an OpenAI account and get your API key from the OpenAI platform.
Set the environment variable:
Create a new project
Initialize a new Node.js project:
Install dependencies
Install the required packages:
Create the Stagehand tools
Create src/mastra/tools/index.ts
with the web automation tools:
Create the web agent
Create src/mastra/agents/index.ts
:
Initialize Mastra
Create src/mastra/index.ts
:
Configure Environment
Create a .env
file in the project root:
Start the Agent
Add to your package.json
:
Run the development server:
This starts the Mastra interface where you can interact with your web automation agent.
The integration provides three main tools for your AI agent:
Once your agent is running, try these natural language instructions:
The agent will automatically choose the right tools and execute the web automation tasks.
Find the sample project for this integration
src/mastra/agents/index.ts
You now have a fully functional AI agent that can automate web tasks through natural language! Learn more about advanced features in the Mastra documentation.