Skip to main content
1

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 environment variable.
2

Get your OpenAI API Key

Create an OpenAI account and get your API key from the OpenAI platform.Set the environment variable:
3

Create a new project

Initialize a new Node.js project:
4

Install dependencies

Install the required packages:
5

Create the Stagehand tools

Create src/mastra/tools/index.ts with the web automation tools:
src/mastra/tools/index.ts
6

Create the browser agent

Create src/mastra/agents/index.ts:
src/mastra/agents/index.ts
7

Initialize Mastra

Create src/mastra/index.ts:
src/mastra/index.ts
8

Configure Environment

Create a .env file in the project root:
.env
9

Start the Agent

Add to your package.json:
package.json
Run the development server:
This starts the Mastra interface where you can interact with your web automation agent.

How it works

The integration provides three main tools for your AI agent:
  • Act: Perform actions like clicking buttons or filling forms
  • Observe: Find and identify elements on web pages
  • Extract: Pull structured data from websites

Try these commands

Once your agent is running, try these natural language instructions:
The agent will automatically choose the right tools and execute the web automation tasks.

Example Agent on GitHub

Find the sample project for this integration

Next steps

  • Custom instructions: Modify the agent’s behavior in src/mastra/agents/index.ts
  • Add tools: Create additional tools for specific automation needs
  • Production setup: Add proper error handling and logging for production use
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.