feat: add Valkey cache configuration to client and session start
Summary
Adds first-class Valkey cache configuration across the Python SDK. Users can now pass connection details (host, port, TLS, auth, TTL, key prefix) either at the client level (propagated as env vars to the local SEA server) or per-session via a valkey_cache param on sessions.start().
Note: This PR depends on the Valkey implementation (https://github.com/browserbase/stagehand/pull/2264) being merged first in stagehand.
Issue
N/A
Changes
src/stagehand/_client.py- Added 7 Valkey-related instance variables and constructor/with_optionsparams to bothStagehandandAsyncStagehandsrc/stagehand/_custom/sea_server.py- ExtendedSeaServerConfig,_HasLocalModeStateprotocol,LocalModeKwargs,_build_process_env(env var propagation),configure_client_base_url, andcopy_local_mode_kwargswith Valkey fields. Also warns when credentials are sent without TLS on non-local hosts, and when client-level Valkey params are used in remote mode.src/stagehand/_custom/session.py- Threadedvalkey_cacheparam through_sync_startand_async_startsrc/stagehand/resources/sessions.py- Addedvalkey_cacheparam toSessionsResource.start()andAsyncSessionsResource.start()with docstrings and body serializationsrc/stagehand/types/session_start_params.py- NewValkeyCacheOptionsTypedDict (host required, port/tls/password/username/cache_ttl/key_prefix optional) with camelCase aliases, plusvalkey_cachefield onSessionStartParamssrc/stagehand/types/__init__.py- Re-exportValkeyCacheOptionstests/api_resources/test_sessions.py- Addedvalkey_cachedict to existing sync/async session start teststests/test_valkey_cache.py- New test file coveringSeaServerConfigdefaults, env var propagation, client constructor params,with_optionspreserve/override, TypedDict shape, signature inspection, falsy-but-valid values (port=0, ttl=0), and empty string edge cases
Tests
tests/test_valkey_cache.py covers the full surface: dataclass fields, env var generation, client param acceptance, with_options behavior, type exports, method signatures, edge cases for falsy values, and the remote-mode warning. Existing test_sessions.py tests updated to exercise the new param in the session start call.
Blockers / Future work
- Depends on the Valkey caching implementation landing in the upstream
stagehandrepo first
Additional context
The local SEA binary and server receives Valkey config as environment variables (VALKEY_HOST, VALKEY_PORT, VALKEY_TLS, VALKEY_PASSWORD, VALKEY_USERNAME, CACHE_TTL, VALKEY_KEY_PREFIX). For remote mode, the valkeyCache object is sent in the session start request body. No new runtime dependencies added.
Summary by cubic
Adds first-class Valkey cache support to the Python SDK. Configure Valkey at the client level (local SEA via env vars) or per session with valkey_cache for remote requests, with safety warnings and updated docs/tests.
-
New Features
- Client: new params
valkey_host,valkey_port,valkey_tls,valkey_password,valkey_username,valkey_cache_ttl,valkey_key_prefix; propagated to the local SEA asVALKEY_*andCACHE_TTL. - Sessions:
sessions.start()acceptsvalkey_cache(host required; port/tls/password/username/cache_ttl/key_prefix optional), serialized with camelCase keys and documented in the method docstring. - Types: added and re-exported
ValkeyCacheOptionsinstagehand.types. - Safety: warns if client-level Valkey params are set in remote mode (ignored) and if a password is used without TLS on non-local hosts.
- Client: new params
-
Migration
- Local mode: pass Valkey params on
Stagehand/AsyncStagehand(or via.with_options()); the SEA binary must be built with@valkey/valkey-glidefor caching to activate. - Remote mode: pass
valkey_cachetosessions.start(). - Notes:
port=0andcache_ttl=0are allowed; empty strings are sent as provided; prefer TLS when sending credentials. - Requires the Valkey caching implementation in the upstream
stagehandserver to be available.
- Local mode: pass Valkey params on