Skip to main content
Action Caching records every action taken during a page.ai() call. Replay these recordings later for deterministic, LLM-free automation—dramatically reducing costs and improving execution speed.

Why Use Action Caching?

Recording Actions

Every page.ai() call automatically returns an actionCache:

Replaying Actions

Use agent.runFromActionCache() to replay recorded actions:

Generate Script from Action Cache

Instead of replaying actions programmatically, you can generate a standalone TypeScript script from recorded actions using agent.createScriptFromActionCache():
This outputs a standalone script you can save and run directly—no LLM calls needed:
The generated script uses the cache perform actions to execute the task without LLM calls.

How Replay Works

  1. XPath First: Attempts to find elements using cached XPaths
  2. Retry on Failure: Retries up to maxXPathRetries times
  3. LLM Fallback: If XPath fails, falls back to AI using the cached instruction
  4. Continue or Stop: Stops on first failure by default

Action Cache Format

The cache is a JSON structure containing all recorded steps:

Direct XPath Execution

For maximum control, use the perform helpers to execute actions directly:

Available Perform Actions

Each helper accepts an options object:

When to Use Action Caching

Monitoring Fallback Rates

When a cached XPath no longer matches the page, HyperAgent falls back to the LLM to find the element if the performInstruction is provided. You’ll see logs like this:
What this means:
  • The cached XPath pointed to li[5] but the element moved to li[4]
  • The LLM successfully found the correct element using the instruction
  • The action completed, but with added latency and cost
When to re-record:
  • If you see fallback warnings frequently, the page structure has changed
  • Re-run the original page.ai() task to capture fresh XPaths
  • Save the new actionCache to replace your stale recording
Enable debug: true on your agent to see more detailed logging.