Use this file to discover all available pages before exploring further.
Stagehand provides built-in action caching to reduce LLM inference calls and improve performance. Simply specify a cacheDir when initializing Stagehand, and actions are automatically cached and reused across runs.
Cache actions from act() by specifying a cache directory in your Stagehand constructor.
import { Stagehand } from "@browserbasehq/stagehand";const stagehand = new Stagehand({ env: "BROWSERBASE", cacheDir: "act-cache", // Specify a cache directory});await stagehand.init();const page = stagehand.context.pages()[0];await page.goto("https://browserbase.github.io/stagehand-eval-sites/sites/iframe-same-proc-scroll/");// First run: uses LLM inference and caches// Subsequent runs: reuses cached actionawait stagehand.act("scroll to the bottom of the iframe");// Variables work with caching tooawait stagehand.act("fill the username field with %username%", { variables: { username: "fakeUsername", },});
Cache agent actions (including Computer Use Agent actions) the same way - just specify a cacheDir. The cache key is automatically generated based on the instruction, start URL, agent execution options, and agent configuration - subsequent runs with the same parameters will reuse cached actions.
import { Stagehand } from "@browserbasehq/stagehand";const stagehand = new Stagehand({ env: "BROWSERBASE", cacheDir: "agent-cache", // Specify a cache directory});await stagehand.init();const page = stagehand.context.pages()[0];await page.goto("https://browserbase.github.io/stagehand-eval-sites/sites/drag-drop/");const agent = stagehand.agent({ mode: "cua", model: { modelName: "google/gemini-2.5-computer-use-preview-10-2025", apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY }, systemPrompt: "You are a helpful assistant that can use a web browser.",});await page.goto("https://play2048.co/");// First run: uses LLM inference and caches// Subsequent runs: reuses cached actionsconst result = await agent.execute({ instruction: "play a gane of 2048", maxSteps: 20,});console.log(JSON.stringify(result, null, 2));
You can organize your caches by using different directory names for different workflows:
// Separate caches for different parts of your automationconst loginStagehand = new Stagehand({ env: "BROWSERBASE", cacheDir: "cache/login-flow"});const checkoutStagehand = new Stagehand({ env: "BROWSERBASE", cacheDir: "cache/checkout-flow"});const dataExtractionStagehand = new Stagehand({ env: "BROWSERBASE", cacheDir: "cache/data-extraction"});