Skip to main content
Long-running browser-agent tasks need structure. Treat the agent run as one part of a workflow, not the whole system.

Break work into phases

1. Prepare job context.
2. Run the browser agent for one scoped goal.
3. Validate output and source URLs.
4. Persist results.
5. Continue, retry, or ask for review.
Prefer several scoped runs over one vague prompt that tries to finish an entire business process.

Set budgets

const agent = web.agent({
  model,
  browser: { policy: { allowedDomains: ["sam.gov"] } },
  maxTurns: 12,
  maxToolCalls: 20,
  timeoutMs: 180_000,
  toolTimeoutMs: 30_000,
});
Budgets help your product fail clearly when a site is slow, blocked, or more complex than expected.

Return blockers clearly

Do not treat a blocked run as a successful empty result. Persist the status, error, page evidence, and any artifacts.
if (result.status === "blocked") {
  await db.agentRuns.update({
    where: { id: runId },
    data: {
      status: "blocked",
      summary: result.text,
      browserId: result.browserId,
    },
  });
}
Use agent.session(...) when multiple related tasks should share one browser.
const session = await agent.session({
  startUrl: "https://www.sec.gov/edgar/search/",
});

try {
  const company = await session.run("Find Apple's latest 10-Q filing.");
  const detail = await session.run("Open the filing detail page and summarize the exhibits.");
  console.log(company.text, detail.text);
} finally {
  await session.close();
}

Production checklist

  • Constrain domains.
  • Request structured output.
  • Set turn, tool, and time budgets.
  • Stream progress for user-facing jobs.
  • Store status, result, source URLs, and artifacts.
  • Return blockers instead of inventing missing data.
  • Require approval for high-impact actions.