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
Everypage.ai() call automatically returns an actionCache:
Replaying Actions
Useagent.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 usingagent.createScriptFromActionCache():
How Replay Works
- XPath First: Attempts to find elements using cached XPaths
- Retry on Failure: Retries up to
maxXPathRetriestimes - LLM Fallback: If XPath fails, falls back to AI using the cached instruction
- 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:- The cached XPath pointed to
li[5]but the element moved toli[4] - The LLM successfully found the correct element using the instruction
- The action completed, but with added latency and cost
- 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
actionCacheto replace your stale recording