Stagehand

活跃
GitHub TypeScript MIT

简介

Stagehand 是 Browserbase 推出的浏览器 Agent SDK,为 AI 编码助手提供网页操作能力。支持 act、extract、observe 三种核心原语,让 AI Agent 能够自然地浏览和操作网页,是构建浏览器 Agent 的首选工具。

核心特性

  • 三原语 API — act(执行动作)、extract(提取数据)、observe(观察页面)三种核心操作
  • 自然语言与代码混合 — 在同一工作流中自由切换 AI 驱动和确定性代码控制
  • 自动缓存与自愈 — 重复操作自动缓存跳过 LLM 推理,页面变化时自动修复
  • TypeScript/Python 双 SDK — 同时提供 TS 和 Python 实现,适配不同技术栈
  • Zod 结构化数据提取 — 使用 Zod schema 定义提取目标,返回类型安全的结构化数据
  • Agent 模式 — 内置 agent() 方法支持多步骤复杂任务的自主执行

适用场景

💡 构建能自动浏览和操作网页的浏览器 Agent
💡 自动化测试需要登录或复杂交互的 Web 应用
💡 从任意网站批量提取结构化产品或价格数据
💡 构建 RAG 系统的实时网页数据采集层
💡 创建可复用的网页自动化工作流脚本

快速开始

npm install @browserbasehq/stagehand

import { Stagehand } from "@browserbasehq/stagehand";

const stagehand = new Stagehand({
  env: "LOCAL",
});
await stagehand.init();

const page = stagehand.context.pages()[0];
await page.goto("https://github.com/browserbase");

await stagehand.act("click on the stagehand repo");

const { author, title } = await stagehand.extract(
  "extract the author and title of the latest PR",
  {
    author: z.string(),
    title: z.string(),
  }
);

console.log(author, title);
await stagehand.close();

相关项目