Skip to main content
Let the agent handle web nuance. Use code for setup, validation, persistence, retries, exact operations, and business rules.

Product workflow shape

const customer = await db.customers.findUniqueOrThrow({ where: { id } });
const companyName = normalizeCompanyName(customer.companyName);

const result = await agent.run({
  startUrl: "https://www.sec.gov/edgar/search/",
  goal: `Find the latest 10-Q filing for ${companyName}. Return structured filing metadata.`,
});

if (result.status !== "completed" || !result.output) {
  await db.agentRuns.update({
    where: { id: runId },
    data: { status: result.status, error: result.error?.message },
  });
  throw new Error(result.error?.message ?? "Filing lookup did not complete.");
}

const filing = validateFiling(result.output);

await db.filings.upsert({
  where: { accessionNumber: filing.accessionNumber },
  create: filing,
  update: filing,
});

await notifyUser(customer.id, filing);
The browser agent handles search and page nuance. Your code owns customer state, validation, persistence, and notifications.

Deterministic browser control

Use deterministic browser control when the workflow needs an exact browser step.
const browser = await web.browser.create({
  policy: { allowedDomains: ["sec.gov"] },
  recording: true,
});

try {
  const check = await browser.playwright.execute({
    code: `
      await page.goto("https://www.sec.gov/edgar/search/");
      return await page.title();
    `,
  });

  if (!String(check.result).includes("SEC")) {
    throw new Error("Unexpected SEC search page title.");
  }
} finally {
  await browser.close();
}
Good uses for deterministic control:
  • Prepare a known page state.
  • Verify a page title, URL, or selector.
  • Download a known file.
  • Recover from a known failure path.
  • Attach an external browser framework through CDP.
Reference: SDK browser reference, SDK resources reference, and SDK agent reference.

Keep the boundary clear

Use prompts for tasks that need browsing judgment. Use code for rules your product must enforce every time.