@mastra/stagehand 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @mastra/stagehand
2
+
3
+ AI-powered browser automation for Mastra agents using [Stagehand](https://github.com/browserbase/stagehand).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/stagehand
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { Agent } from '@mastra/core';
15
+ import { StagehandBrowser } from '@mastra/stagehand';
16
+
17
+ // Create a Stagehand browser
18
+ const browser = new StagehandBrowser({
19
+ model: 'openai/gpt-4o',
20
+ headless: true,
21
+ });
22
+
23
+ // Create an agent with the browser
24
+ const agent = new Agent({
25
+ name: 'web-agent',
26
+ instructions: 'You are a helpful web assistant.',
27
+ model: { provider: 'openai', modelId: 'gpt-4o' },
28
+ browser,
29
+ });
30
+
31
+ // Use the agent to browse the web with natural language
32
+ const result = await agent.generate('Go to google.com and search for "Mastra AI"');
33
+ ```
34
+
35
+ ## Configuration
36
+
37
+ ```typescript
38
+ const browser = new StagehandBrowser({
39
+ // Environment: 'LOCAL' or 'BROWSERBASE'
40
+ env: 'LOCAL',
41
+
42
+ // Model for AI operations (default: 'openai/gpt-4o')
43
+ model: 'openai/gpt-4o',
44
+ // Or with custom config:
45
+ model: {
46
+ modelName: 'openai/gpt-4o',
47
+ apiKey: process.env.OPENAI_API_KEY,
48
+ },
49
+
50
+ // Run headless (default: true)
51
+ headless: true,
52
+
53
+ // CDP URL for connecting to existing browser
54
+ cdpUrl: 'ws://localhost:9222',
55
+
56
+ // Browserbase config (when env: 'BROWSERBASE')
57
+ apiKey: process.env.BROWSERBASE_API_KEY,
58
+ projectId: process.env.BROWSERBASE_PROJECT_ID,
59
+
60
+ // Logging verbosity (0: silent, 1: errors, 2: verbose)
61
+ verbose: 1,
62
+ });
63
+ ```
64
+
65
+ ## Tools
66
+
67
+ StagehandBrowser exposes 6 AI-powered tools:
68
+
69
+ ### Core AI Tools
70
+
71
+ - **stagehand_act** - Perform actions using natural language
72
+ - **stagehand_extract** - Extract structured data from pages
73
+ - **stagehand_observe** - Discover actionable elements
74
+
75
+ ### Navigation & State
76
+
77
+ - **stagehand_navigate** - Navigate to a URL
78
+ - **stagehand_screenshot** - Take screenshots
79
+ - **stagehand_close** - Close the browser
80
+
81
+ ## Comparison with AgentBrowser
82
+
83
+ | Feature | AgentBrowser | StagehandBrowser |
84
+ | ----------- | ----------------------------- | ---------------------------- |
85
+ | Approach | Deterministic refs ([ref=e1]) | Natural language |
86
+ | Token cost | Low | Higher (LLM calls) |
87
+ | Speed | Fast | Slower |
88
+ | Reliability | High (exact refs) | Variable (AI interpretation) |
89
+ | Best for | Structured workflows | Unknown/dynamic pages |
90
+
91
+ ## License
92
+
93
+ Apache-2.0