Skip to content

Commit 3b3a1cb

Browse files
authored
adding mastra integration + docs (#10)
1 parent 3c31af6 commit 3b3a1cb

File tree

9 files changed

+10087
-0
lines changed

9 files changed

+10087
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ Powerful integrations for AgentKit workflows with both Browserbase and Stagehand
4848
#### [**LangChain Integration**](./examples/integrations/langchain/README.md)
4949
Integrate Browserbase with LangChain's ecosystem for advanced AI applications. Build chains that can browse, extract, and interact with web content as part of larger AI workflows.
5050

51+
#### [**Mastra Integration**](./examples/integrations/mastra/README.md)
52+
Powerful web automation combining Browserbase's Stagehand with Mastra's AI agent framework. Enable your Mastra agents to navigate websites, extract data, and perform complex web interactions through natural language commands.
53+
54+
**Key Features:**
55+
- AI-powered web navigation and interaction
56+
- Smart element observation and data extraction
57+
- Session management with automatic timeouts
58+
- Natural language interface to web automation
59+
- Integration with OpenAI models for intelligent decision-making
60+
5161
#### [**Browser-Use Integration**](./examples/integrations/browser-use/README.md)
5262
Streamlined browser automation for AI applications with a focus on simplicity and reliability.
5363

@@ -98,6 +108,7 @@ integrations/
98108
│ ├── vercel/ # Vercel AI SDK integration
99109
│ ├── stripe/ # Stripe Issuing + automation
100110
│ ├── langchain/ # LangChain framework integration
111+
│ ├── mastra/ # Mastra AI agent integration
101112
│ ├── browser-use/ # Simplified browser automation
102113
│ ├── braintrust/ # Evaluation and testing tools
103114
│ ├── agno/ # AI-powered web scraping agents
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output.txt
2+
node_modules
3+
dist
4+
.mastra
5+
.env.development
6+
.env
7+
*.db
8+
9+
memory*
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Stagehand & Mastra Integration
2+
3+
A powerful integration that combines the capabilities of [Browserbase's Stagehand](https:/stagehand.dev) with [Mastra](https://mastra.ai/) for advanced web automation, scraping, and AI-powered web interactions.
4+
5+
## Overview
6+
7+
This project enables AI agents to interact with web pages through the Mastra framework using Stagehand's browser automation capabilities. It provides tools for web navigation, element observation, data extraction, and action execution, all orchestrated through Mastra's agent system.
8+
9+
## Features
10+
11+
- **Web Navigation**: Navigate to websites programmatically
12+
- **Element Observation**: Identify and locate elements on web pages
13+
- **Action Execution**: Perform actions like clicking buttons or filling forms
14+
- **Data Extraction**: Extract structured data from web pages
15+
- **Session Management**: Smart session handling with automatic timeouts and reconnection
16+
- **AI-Powered Interactions**: Leverage OpenAI models for intelligent web interactions
17+
18+
## Installation
19+
20+
### Prerequisites
21+
22+
- Node.js (v18+)
23+
- npm or yarn
24+
- Browserbase account
25+
- OpenAI API access
26+
27+
### Setup
28+
29+
1. Clone the repository:
30+
```
31+
git clone https://github.com/browserbase/Stagehand-Mastra-App.git
32+
cd Stagehand-Mastra-App
33+
```
34+
35+
2. Install dependencies:
36+
```
37+
npm install
38+
```
39+
40+
3. Create a `.env` file with your API keys:
41+
```
42+
BROWSERBASE_PROJECT_ID=your_project_id
43+
BROWSERBASE_API_KEY=your_api_key
44+
OPENAI_API_KEY=your_openai_key
45+
```
46+
47+
## Usage
48+
49+
### Running the development server
50+
51+
```
52+
npm run dev
53+
```
54+
55+
This will start the Mastra development server, giving you access to the integrated web agent.
56+
57+
## Architecture
58+
59+
### Core Components
60+
61+
1. **Stagehand Session Manager**
62+
- Handles browser session initialization and management
63+
- Implements automatic session timeouts
64+
- Provides error recovery and reconnection logic
65+
66+
2. **Mastra Tools**
67+
- `stagehandActTool`: Performs actions on web pages
68+
- `stagehandObserveTool`: Identifies elements on web pages
69+
- `stagehandExtractTool`: Extracts data from web pages
70+
71+
3. **Web Agent**
72+
- AI-powered agent using OpenAI's GPT-4
73+
- Provides natural language interface to web automation
74+
- Integrates all tools into a unified experience
75+
76+
### Flow Diagram
77+
78+
```
79+
User Query → Mastra Agent → Stagehand Tools → Browser Interaction → Web Page → Data/Results → Agent Response
80+
```
81+
82+
## Configuration
83+
84+
The project can be configured through the `.env` file and by modifying the agent instructions in `src/mastra/agents/index.ts`.
85+
86+
## Credits
87+
88+
This project is built with:
89+
- [Mastra](https://mastra.ai) - AI Agent framework
90+
- [Stagehand by Browserbase](https:/stagehand.dev) - Browser automation
91+
- [OpenAI](https://openai.com/) - AI models

0 commit comments

Comments
 (0)