Skip to content

Commit 7afcccc

Browse files
authored
docs: add agent gif, formatting on agent rules, switch orientation of copy … (#1004)
…and chat for contextual menu # why agent should have a visual to show what is going on behind the scenes cursorrules formatting was a little weird it's more intuitive to have copy before chat # what changed # test plan
1 parent a8aa3d7 commit 7afcccc

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

docs/basics/agent.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ description: 'Automate complex workflows with AI powered browser agents'
99
agent.execute("apply for a job at browserbase")
1010
```
1111
`agent` turns high level tasks into **fully autonomous** browser workflows. You can customize the agent by specifying the LLM provider and model, setting custom instructions for behavior, and configuring max steps.
12+
13+
<img src="/images/agent.gif" alt="Agent" />
14+
1215
## Why use `agent()`?
1316

1417
<CardGroup cols={2}>

docs/docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,6 @@
149149
}
150150
},
151151
"contextual": {
152-
"options": ["chatgpt", "claude", "copy", "view"]
152+
"options": ["copy", "chatgpt", "claude", "view"]
153153
}
154154
}

docs/first-steps/ai-rules.mdx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ await page.observe({
134134
instruction: "the instruction to execute",
135135
returnAction: true, // return the action to execute
136136
});
137+
137138
await page.act(results[0]);
138139
```
140+
139141
- When writing code that needs to extract data from the page, use Stagehand `extract`. Explicitly pass the following params by default:
140142

141143
```typescript
@@ -155,8 +157,11 @@ import { Stagehand, Page, BrowserContext } from "@browserbasehq/stagehand";
155157
const stagehand = new Stagehand({
156158
env: "BROWSERBASE"
157159
});
160+
158161
await stagehand.init();
162+
159163
const page = stagehand.page; // Playwright Page with act, extract, and observe methods
164+
160165
const context = stagehand.context; // Playwright BrowserContext
161166
```
162167
### Configuration Options
@@ -208,12 +213,17 @@ Act `action` should be as atomic and specific as possible, i.e. "Click the sign
208213
AVOID actions that are more than one step, i.e. "Order me pizza" or "Send an email to Paul asking him to call me".
209214

210215
## Extract
216+
211217
### Simple String Extraction
218+
212219
```typescript
213220
const signInButtonText = await page.extract("extract the sign in button text");
214221
```
222+
215223
### Structured Extraction with Schema (Recommended)
224+
216225
Always use Zod schemas for structured data extraction:
226+
217227
```typescript
218228
import { z } from "zod";
219229

@@ -224,8 +234,11 @@ const data = await page.extract({
224234
}),
225235
});
226236
```
237+
227238
### Array Extraction
239+
228240
To extract multiple items, wrap the array in a single object:
241+
229242
```typescript
230243
const data = await page.extract({
231244
instruction: "extract the text inside all buttons",
@@ -234,8 +247,11 @@ const data = await page.extract({
234247
})
235248
});
236249
```
250+
237251
### Complex Object Extraction
252+
238253
For more complex data structures:
254+
239255
```typescript
240256
const productData = await page.extract({
241257
instruction: "extract product information from this page",
@@ -248,16 +264,23 @@ const productData = await page.extract({
248264
}),
249265
});
250266
```
267+
251268
### Schema Validation
269+
252270
```typescript
253271
import { validateZodSchema } from "./utils.js";
254272
import { z } from "zod";
273+
255274
const schema = z.object({ name: z.string() });
256275
const isValid = validateZodSchema(schema, { name: "John" }); // true
257276
```
277+
258278
## Agent System
279+
259280
Stagehand provides an Agent System for autonomous web browsing using Computer Use Agents (CUA). Agents execute multi-step workflows using natural language instructions.
281+
260282
### Creating Agents
283+
261284
```typescript
262285
// Basic agent (default)
263286
const agent = stagehand.agent();
@@ -267,15 +290,19 @@ const agent = stagehand.agent({
267290
provider: "openai",
268291
model: "computer-use-preview",
269292
instructions: "You are a helpful assistant that can use a web browser.",
270-
options: { apiKey: process.env.OPENAI_API_KEY }
293+
options: {
294+
apiKey: process.env.OPENAI_API_KEY
295+
}
271296
});
272297

273298
// Anthropic agent
274299
const agent = stagehand.agent({
275300
provider: "anthropic",
276301
model: "claude-sonnet-4-20250514",
277302
instructions: "You are a helpful assistant that can use a web browser.",
278-
options: { apiKey: process.env.ANTHROPIC_API_KEY }
303+
options: {
304+
apiKey: process.env.ANTHROPIC_API_KEY
305+
}
279306
});
280307
```
281308
### Agent Execution
@@ -290,17 +317,21 @@ const result = await agent.execute({
290317
autoScreenshot: true
291318
});
292319
```
320+
293321
### Best Practices
294322
- Be specific with instructions: `"Fill out the contact form with name 'John Doe' and submit it"`
295323
- Break down complex tasks into smaller steps
296324
- Use error handling with try/catch blocks
297325
- Combine agents for navigation with traditional methods for precise data extraction
326+
298327
```typescript
299328
// Good: Specific instructions
300329
await agent.execute("Navigate to products page and filter by 'Electronics'");
330+
301331
// Avoid: Vague instructions
302332
await agent.execute("Do some stuff on this page");
303333
```
334+
304335
## Project Structure Best Practices
305336

306337
- Store configurations in `stagehand.config.ts`

docs/images/agent.gif

2.87 MB
Loading

0 commit comments

Comments
 (0)