跳转到主要内容
const agent = stagehand.agent();
await agent.execute("Sign me up for a library card");
软件始终是确定且可重复的,但AI智能体却难以复现工作流程。Stagehand完美融合了两者的优势:智能与确定性 Stagehand中的Web智能体完全可定制。您可以使用任何LLM/VLM/计算机服务提供商,设置系统提示词,添加自定义工具等。
// For Computer Use Agent (CUA) models
const agent = stagehand.agent({
  provider: "openai",
  model: "computer-use-preview",
  instructions: "You are a helpful assistant that can use a web browser.",
  options: {
    apiKey: process.env.OPENAI_API_KEY,
  },
});

// You can define additional options like max_steps and auto_screenshot
await agent.execute({
  instruction="Sign me up for a library card",
  max_steps=20,
})

参数: AgentOptions

provider
string
必填
指定LLM服务提供商。 当前支持:
  • OpenAI: openai
  • Anthropic: anthropic
model
string
必填
指定LLM模型。 当前支持:
  • OpenAI: computer-use-preview
  • Anthropic: claude-sonnet-4-20250514claude-3-7-sonnet-latest
instructions
string
指定系统提示词
options
object
LLM提供商的配置选项。当前支持OpenAI和Anthropic SDK客户端选项。

返回值: Promise<AgentResult>

success
boolean
表示智能体执行是否未发生错误完成
message
string
来自智能体的摘要或错误信息
actions
AgentAction[]
执行过程中执行的操作列表
completed
boolean
表示智能体是否完全完成任务(即使success为true也可能为false)
metadata
Record<string, unknown> | dict
关于本次执行的可选附加数据