> ## Documentation Index
> Fetch the complete documentation index at: https://java.agentscope.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 概览

> [!NOTE]
>
> **推荐使用 [DistributedStore](https://java.agentscope.io/dev/zh/integration/distributed/index.md) 一键配置**——它同时覆盖 AgentStateStore、BaseStore、SandboxSnapshotSpec、SandboxExecutionGuard。如果只需要单独配置 AgentStateStore，继续阅读本页。

`io.agentscope.core.state.AgentStateStore` 是 AgentScope 用来持久化 Agent 状态的接口——比如 Memory、Workspace、Plan 等组件都会被序列化为 `State` 后由 `AgentStateStore` 落盘，从而支持重启恢复、跨节点共享。

状态通过 `(userId, sessionId)` 二元组寻址：

* `sessionId`——非空、非空白，标识一次会话 / session。
* `userId`——可空。`null` 表示匿名 / 单租户调用方（CLI、测试等）。

## AgentStateStore 与 Thread 日志

本页是 `AgentStateStore` 接口参考。启用日志时，`HarnessAgent` 通过
`ThreadJournalStore` 恢复；只替换 `stateStore` 不会迁移或共享 Thread 日志。主 Thread
会读取 AgentScope 2.0 写入的状态，并在 checkpoint 提交后将最新状态镜像回 2.0 的
`agent_state` 位置，以支持回滚读取；命名 Thread 使用独立状态项。Workspace 的
BaseStore 能保存文件，也不等于具备日志要求的 CAS 和 writer fencing。详见
[Thread 执行日志与恢复](https://java.agentscope.io/dev/zh/docs/harness/session-log.md)。

## 可用实现

| 实现 | 模块 | 适合场景 |
| - | - | - |
| `InMemoryAgentStateStore` | `agentscope-core` | 单元测试 |
| `JsonFileAgentStateStore` | `agentscope-core` | 单机开发（**HarnessAgent 默认**） |
| `RedisAgentStateStore` | `agentscope-extensions-redis` | [多副本生产首选](https://java.agentscope.io/dev/zh/integration/distributed/redis.md) |
| `JdbcAgentStateStore` | `agentscope-extensions-jdbc` | [已有数据库的场景](https://java.agentscope.io/dev/zh/integration/distributed/jdbc.md) |
| `OssAgentStateStore` | `agentscope-extensions-oss` | [阿里云生态](https://java.agentscope.io/dev/zh/integration/distributed/oss.md) |

## 单独配置

```java theme={null}
ReActAgent agent = ReActAgent.builder()
    .name("assistant")
    .model(model)
    .stateStore(stateStore)   // 任选一种 AgentStateStore 实现
    .build();
```

详细用法和代码示例请参阅各后端的文档：

* [Redis](https://java.agentscope.io/dev/zh/integration/distributed/redis.md#1-redisagentstatestore)
* [JDBC](https://java.agentscope.io/dev/zh/integration/distributed/jdbc.md#1-jdbcagentstatestore)
* [OSS](https://java.agentscope.io/dev/zh/integration/distributed/oss.md#1-ossagentstatestore)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.