agentscope-extensions-redis 提供全链路的 Redis 分布式存储实现,是多副本生产部署的首选后端。
添加依赖
一键配置
提供的组件
1. RedisAgentStateStore
Agent 状态持久化到 Redis。支持 Jedis / Lettuce / Redisson 三种客户端。- 单值:
{prefix}{userId}/{sessionId}:{stateKey}— Redis String(JSON) - 列表:
{prefix}{userId}/{sessionId}:{stateKey}:list— Redis List(JSON items) - 增量写入:通过 hash 摘要 + 计数比较,仅 append 新增项
2. RedisStore(BaseStore)
工作区文件系统 KV 存储,供RemoteFilesystemSpec 使用。
put / putIfVersion 使用 Lua 脚本保证原子性(version read + hash write + index update 单次 EVAL),putIfVersion 可作为分布式 CAS 原语。
3. RedisSnapshotSpec
沙箱快照存储到 Redis 二进制 key。适合小工作区 + 短 TTL 场景。注意 Redis 内存代价——大工作区(>50MB)建议用 OSS。
4. RedisSandboxExecutionGuard
基于 RedisSET NX PX 租约的分布式锁,用于 AGENT / GLOBAL 隔离范围下的多副本并发控制。