agentscope-extensions-redis provides full-stack Redis distributed storage — the recommended store for multi-replica production deployments.
Dependency
One-Line Setup
Components Provided
1. RedisAgentStateStore
Agent state persisted to Redis. Supports Jedis / Lettuce / Redisson.V0 and V1 key layouts
RedisAgentStateStore uses V0 by default to preserve existing Redis keys. Select V1 explicitly for
Redis Cluster, and configure the same version on every application instance that shares a key
prefix.
For example, given:
alice/s1, while V1 wraps that segment in
the Redis hash tag {alice/s1}.
The session index is a Redis Set. Its members do not change between layouts: the single-state member
is stored as
agent_state, and a list member as messages:list. A missing or blank userId is
normalized to __anon__ in both layouts.
V0 has no hash tag, so Redis Cluster hashes each complete key independently. The state key,
version key, and session-index key used by the optimistic-concurrency Lua script can therefore land
in different slots and cause CROSSSLOT. With V1, Redis hashes only the shared alice/s1 text
inside {...}, placing every key for that session in one slot.
V0 and V1 are separate key namespaces. A store configured for one layout uses only that layout for
reads, writes, exists, delete, and listSessionIds; it does not read data from the other layout.
V1 also applies these structural restrictions:
keyPrefixmust not contain{or}.userIdandsessionIdmust not contain{,}, or/.sessionIdmust not be null or blank.
Migrating from V0 to V1
The library does not automatically migrate or dual-write state. The recommended migration is a stop-write cutover for each key prefix.- Inventory and validate. Identify every application instance using the prefix and inventory
the
(userId, sessionId)pairs that must be retained. Resolve identifiers that violate the V1 restrictions before migration. Do not infer ambiguous identifiers containing/only by splitting V0 key names; use the application’s authoritative IDs. - Choose whether to retain old state. If agent state is disposable or already governed by a short TTL, stop writers, remove or expire the V0 keys, and start with V1. Otherwise continue with the copy procedure below.
- Stop writes and back up Redis. Drain in-flight requests and prevent all instances from writing to the prefix. Take a backup or snapshot before changing keys. Copying live V0 keys without a write barrier can produce mismatched values, versions, and session indexes.
- Copy every session one key at a time. For each V0 session, change only the session segment
from
userId/sessionIdto{userId/sessionId}. Copy all existing keys: single-state values, version keys, lists, list hashes, and the_keyssession index. Copy the session index last so a partially copied session is not reported as present. - Preserve type and TTL. A migration tool can use
DUMP,PTTL, andRESTORE ... REPLACEfor each individual key. TreatPTTL = -1as a non-expiring destination (RESTORETTL0) and skip a key ifPTTL = -2. Use a cluster-aware client so each source and destination command is routed to the correct node. Do not useRENAMEor a multi-key copy/delete command across slots. - Verify before cutover. Compare the V0 and V1 values, Redis types, TTLs, version numbers, list
contents, and
_keysmembers for a representative sample and for total session counts. RunCLUSTER KEYSLOTfor the V1 state, version, and index keys and confirm that the slot numbers are identical. Perform application smoke tests for load, save, compare-and-set, list, and delete on test sessions. - Switch all instances together. Configure every store using the prefix with
KeyLayoutVersion.V1, deploy the instances as one coordinated cutover, and then resume traffic. Running V0 and V1 writers concurrently creates two independently changing copies of a session. - Keep V0 data during an observation window. Do not modify the retained V0 copy after the V1
cutover. If rollback is required before any V1 write, all instances can return to V0. After V1
writes begin, stop writes again and reverse-migrate the changed data before switching back;
otherwise the V1 updates will be invisible. V0 also reintroduces the original Cluster
CROSSSLOTlimitation. - Remove V0 data selectively. After the observation window, delete only the old V0 keys, one key per command. Do not use prefix-wide cleanup because it also deletes V1 keys under the same prefix.
2. RedisStore (BaseStore)
Workspace filesystem KV storage forRemoteFilesystemSpec.
put / putIfVersion use Lua scripts for atomicity.
3. RedisSnapshotSpec
Sandbox snapshots stored as Redis binary keys. Best for small workspaces + short TTL.4. RedisSandboxExecutionGuard
RedisSET NX PX lease-based distributed lock for multi-replica sandbox concurrency control.