Skip to content

The agent that grows with you

feat(browser): give Lightpanda an on-disk HTTP cache

Adrià Arrufat6973ce3ac2ea
diff --git a/tests/tools/test_browser_lightpanda_serve.py b/tests/tools/test_browser_lightpanda_serve.py
index 73200bac14f..dc9676fa127 100644
--- a/tests/tools/test_browser_lightpanda_serve.py
+++ b/tests/tools/test_browser_lightpanda_serve.py
@@ -5,6 +5,7 @@ import json
import os
import stat
import subprocess
+from pathlib import Path
from unittest.mock import patch
import pytest
@@ -112,6 +113,7 @@ class TestLaunch:
assert err is None
assert calls["argv"] == [
"/opt/lightpanda", "serve", "--host", "127.0.0.1", "--port", "43111",
+ "--http-cache-dir", str(_isolate / "http-cache"),
]
kw = calls["kwargs"]
assert kw["stdin"] is subprocess.DEVNULL
@@ -129,6 +131,17 @@ class TestLaunch:
assert record["owner_pid"] == os.getpid()
assert record["start_time"] == 111
+ def test_http_cache_dir_is_shared_across_sessions(self, monkeypatch, _isolate):
+ _, _, first = self._launch(monkeypatch)
+ with lp._servers_lock:
+ lp._servers.clear()
+ _, _, second = self._launch(monkeypatch)
+ cache = str(_isolate / "http-cache")
+ assert first["argv"][first["argv"].index("--http-cache-dir") + 1] == cache
+ assert second["argv"][second["argv"].index("--http-cache-dir") + 1] == cache
+ assert Path(cache).is_dir()
+ assert not list(Path(cache).glob("*.json")) # never confused with a session record
+
def test_block_private_networks_flag(self, monkeypatch):
_, err, calls = self._launch(monkeypatch, block_private_networks=True)
assert err is None
diff --git a/tools/browser_lightpanda.py b/tools/browser_lightpanda.py
index bb64d2c82a9..9d35d7ffe32 100644
--- a/tools/browser_lightpanda.py
+++ b/tools/browser_lightpanda.py
@@ -115,6 +115,19 @@ def _state_dir() -> Path:
return path
+def _http_cache_dir() -> Path:
+ """Filesystem HTTP cache shared by every Lightpanda this Hermes spawns.
+
+ Shared rather than per-session so a cached asset survives session churn.
+ Lightpanda holds it in sqlite (WAL); a write that loses a race is a cache
+ miss, never a failed page load, and ``--http-cache-entry-limit`` (default
+ 1000) bounds it without Hermes managing eviction.
+ """
+ path = _state_dir() / "http-cache"
+ path.mkdir(parents=True, exist_ok=True)
+ return path
+
+
def _record_path(session_name: str) -> Path:
return _state_dir() / f"{session_name}.json"
@@ -216,7 +229,10 @@ def launch_lightpanda(
)
port = _pick_free_loopback_port()
- argv = [binary, "serve", "--host", "127.0.0.1", "--port", str(port)]
+ argv = [
+ binary, "serve", "--host", "127.0.0.1", "--port", str(port),
+ "--http-cache-dir", str(_http_cache_dir()),
+ ]
if block_private_networks:
argv.append("--block-private-networks")
log_path = str(_state_dir() / f"{session_name}.log")
diff --git a/website/docs/user-guide/features/browser.md b/website/docs/user-guide/features/browser.md
index 1b2df2a39ac..33369e1ba7c 100644
--- a/website/docs/user-guide/features/browser.md
+++ b/website/docs/user-guide/features/browser.md
@@ -455,7 +455,7 @@ AGENT_BROWSER_ENGINE=lightpanda
The engine works with both browser drivers:
-- **Browser Use mode (the default).** Hermes launches `lightpanda serve --host 127.0.0.1 --port <free>` itself — one process per `browser_exec` session name (or per task) — and points the Browser Use CLI at it. No Chromium, Playwright or Node.js is needed. The process is reaped after `browser.inactivity_timeout`, on exit, and by the orphan sweep if Hermes crashes. Lightpanda has no graphical renderer, so `capture_screenshot()` is unavailable and the tool description tells the model to work text-first; it also holds one page per session, so the model is told to call `new_tab()` once and `goto_url()` afterwards (tracked upstream in [lightpanda-io/browser#1962](https://github.com/lightpanda-io/browser/issues/1962)).
+- **Browser Use mode (the default).** Hermes launches `lightpanda serve --host 127.0.0.1 --port <free>` itself — one process per `browser_exec` session name (or per task) — and points the Browser Use CLI at it. No Chromium, Playwright or Node.js is needed. The process is reaped after `browser.inactivity_timeout`, on exit, and by the orphan sweep if Hermes crashes. All of these processes share one on-disk HTTP cache at `$HERMES_HOME/cache/browser-use/lightpanda/http-cache`, so repeat visits skip re-downloading assets; delete that directory to clear it. Lightpanda has no graphical renderer, so `capture_screenshot()` is unavailable and the tool description tells the model to work text-first; it also holds one page per session, so the model is told to call `new_tab()` once and `goto_url()` afterwards (tracked upstream in [lightpanda-io/browser#1962](https://github.com/lightpanda-io/browser/issues/1962)).
- **Built-in browser tools** (`/browser use off`). Hermes drives Lightpanda through `agent-browser --engine lightpanda` over CDP, the same way it drives local Chrome, with **automatic Chrome fallback**: Lightpanda handles the actions it supports (navigate, snapshot, click, type, scroll, back, press, eval) and Hermes transparently retries on Chrome for anything it doesn't. Screenshots and `browser_vision` are routed straight to Chrome.
**When the engine is ignored.** `browser.engine` is the lowest-precedence browser setting: a cloud provider (including the Nous subscription browser — and on never-configured setups, any `BROWSERBASE_API_KEY` / `BROWSER_USE_API_KEY` in `~/.hermes/.env` auto-selects one), Camofox, a `browser.cdp_url` / `/browser connect` override, or `browser.use_real_profile` all take precedence. Picking Lightpanda in `hermes tools` writes `cloud_provider: local` for you; `/browser status` and `hermes doctor` report when the engine is configured but shadowed, and by what.