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
and BROWSERBASE_PROJECT_ID
environment variables.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 web 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 Run the development server:This starts the Mastra interface where you can interact with your web automation agent.
package.json
:package.json
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: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