text stringlengths 0 59.1k |
|---|
// Use Stagehand's observe method with vision capabilities |
const observations = await stagehand.observe({ |
instruction, |
useVision, |
}); |
console.log(`Found ${observations.length} elements matching criteria`); |
return { |
success: true, |
elements: observations, |
count: observations.length, |
instruction, |
url: page.url(), |
}; |
} catch (error) { |
const errorMessage = error instanceof Error ? error.message : String(error); |
throw new Error(`Observation failed: ${errorMessage}`); |
} |
}, |
}); |
``` |
</details> |
Features: |
- AI vision for element location via natural language |
- Identifies buttons, forms, images, interactive elements |
- Returns element selectors and properties |
- Extends beyond CSS selector limitations |
#### Page Act Tool |
Performs web page interactions: |
<details> |
<summary>Show page-act.tool.ts</summary> |
```typescript |
import { createTool } from "@voltagent/core"; |
import { z } from "zod"; |
import { sessionManager } from "../../stagehand-manager"; |
export const pageActTool = createTool({ |
name: "page_act", |
description: "Perform actions on web page elements using natural language", |
parameters: z.object({ |
action: z.string().describe("The action to perform (e.g., 'click the login button')"), |
useVision: z.boolean().optional().default(true).describe("Use vision model to find elements"), |
}), |
execute: async ({ action, useVision }) => { |
try { |
const stagehand = await sessionManager.ensureStagehand(); |
const page = stagehand.page; |
console.log(`Performing action: ${action}`); |
// Use Stagehand's act method |
await stagehand.act({ |
action, |
useVision, |
}); |
console.log(`Action completed: ${action}`); |
return { |
success: true, |
action, |
url: page.url(), |
message: `Successfully performed: ${action}`, |
}; |
} catch (error) { |
const errorMessage = error instanceof Error ? error.message : String(error); |
throw new Error(`Action failed: ${errorMessage}`); |
} |
}, |
}); |
``` |
</details> |
Features: |
- Natural language-based interactions (clicks, form fills) |
- AI vision for element identification |
- Complex interaction sequence handling |
- Multi-step workflow navigation |
#### Screenshot Tool |
Captures visual references: |
<details> |
<summary>Show screenshot.tool.ts</summary> |
```typescript |
import { createTool } from "@voltagent/core"; |
import { z } from "zod"; |
import { sessionManager } from "../../stagehand-manager"; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.