You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deterministic rerun lets you run a browser task once with a full agent, then **re-execute the same task instantly** using a cached script — no LLM, up to 99% cheaper.
506
+
507
+
## Quick start
508
+
509
+
Use `{{double brackets}}` around values that can change between runs. The first call runs the full agent. Every subsequent call with the same template uses the cached script.
// First call — agent explores, creates script (~$0.10, ~60s)
536
+
const result = await client.run(
537
+
"Get the top {{5}} stories from https://news.ycombinator.com as JSON",
538
+
{ workspaceId: workspace.id },
539
+
);
540
+
541
+
// Second call — cached script, different param ($0 LLM, ~5s)
542
+
const result2 = await client.run(
543
+
"Get the top {{10}} stories from https://news.ycombinator.com as JSON",
544
+
{ workspaceId: workspace.id },
545
+
);
546
+
```
547
+
548
+
## How it works
549
+
550
+
The brackets mark which parts are parameters:
551
+
552
+
```
553
+
"Get prices from {{example.com}} for {{electronics}}"
554
+
```
555
+
556
+
- `{{example.com}}` → parameter 1
557
+
- `{{electronics}}` → parameter 2
558
+
559
+
The system strips the values to create a **template**: `"Get prices from {{}} for {{}}"`.
560
+
Template `"Get prices from {{}} for {{}}"` is hashed to a unique ID like `a7f3b2c1`.
561
+
The system checks the workspace for `scripts/a7f3b2c1.py`.
562
+
If no script exists, the full agent runs your task. After completing it, the agent saves a standalone Python script that reproduces the result deterministically — no AI needed.
563
+
If the script exists, it runs directly with the new parameter values. No agent, no LLM. Just the script in a sandbox with browser and proxy.
564
+
565
+
## Auto-detection
566
+
567
+
Caching activates **automatically** when both conditions are met:
568
+
- The task contains `{{` and `}}`
569
+
- A `workspace_id` is provided
570
+
571
+
No extra flags needed. You can override with `cache_script`:
572
+
573
+
| Value | Behavior |
574
+
|-------|----------|
575
+
| `None` (default) | Auto-detect from `{{brackets}}` + workspace |
576
+
| `True` | Force-enable, even without brackets |
577
+
| `False` | Force-disable, even if brackets are present |
578
+
579
+
## Examples
580
+
581
+
### Parameterized scraping
582
+
583
+
Run once, then loop over different keywords at $0 LLM each:
584
+
585
+
```python Python
586
+
# Agent figures out how to scrape intro.co on first call
587
+
result = await client.run(
588
+
"Go to {{https://intro.co/marketplace}} and get all {{logistics}} experts as JSON",
589
+
workspace_id=str(workspace.id),
590
+
)
591
+
592
+
# Instant reruns with different keywords
593
+
for keyword in ["CEO", "marketing", "finance", "e-commerce"]:
594
+
result = await client.run(
595
+
f"Go to {{{{https://intro.co/marketplace}}}} and get all {{{{{keyword}}}}} experts as JSON",
The browser and proxy still run for cached calls (the script may need them), so there is a small infrastructure cost per execution. LLM cost drops to zero.
- [Follow-up tasks](https://docs.browser-use.com/cloud/agent/follow-up-tasks): Run multiple tasks in the same browser session.
32
32
- [Live messages](https://docs.browser-use.com/cloud/agent/streaming): Stream the agent's messages in real time to build custom UIs or monitor progress.
33
33
- [Workspaces & files](https://docs.browser-use.com/cloud/agent/workspaces): Upload files for the agent, download files the agent creates.
34
+
- [Deterministic rerun](https://docs.browser-use.com/cloud/agent/cache-script): Run a task once, then re-execute it for $0 LLM cost.
34
35
- [Human in the loop](https://docs.browser-use.com/cloud/agent/human-in-the-loop): Let a human interact with the live browser while the agent is running. Useful for approvals, payments, complex auth flows, or reviewing agent work before continuing.
0 commit comments