InMemoryStateService
public class InMemoryStateService extends StateService
源码Source
io/agentscope/runtime/engine/services/agent_state/InMemoryStateService.java:43–166In 记忆状态服务,承载智能体的部署、调度与服务化运行。位于 io.agentscope.runtime.engine.services.agent_state 包,继承自 StateService。核心成员包括 start、stop、health、saveState、exportState、InMemoryStateService。
In-memory implementation of StateService using maps for sparse round storage.
Multiple users, sessions, and non-contiguous round IDs are supported. If round_id is null when saving, a new round is appended automatically. If round_id is null when exporting, the latest round is returned.
Structure:
{ user_id: { session_id: { round_id: state_dict } } }
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public InMemoryStateService() | 初始化 `InMemoryStateService` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void start() | 执行启动相关操作。 Returns the start. |
public void stop() | 执行停止相关操作。 Returns the stop. |
public boolean health() | 返回健康状态。 Returns the health. |
public CompletableFuture<Integer> saveState(String userId, Map<String, Object> state, String sessionId, Integer roundId) | 保存状态。 Saves the state. |
public CompletableFuture<Map<String, Object>> exportState(String userId, String sessionId, Integer roundId) | 执行 `exportState` 方法。 Performs the export state operation. |
构造器详情Constructor Detail
InMemoryStateService
public InMemoryStateService()
初始化 InMemoryStateService 实例。
Creates a new instance.
源码Source
io/agentscope/runtime/engine/services/agent_state/InMemoryStateService.java:52–55方法详情Method Detail
start
public void start()
执行启动相关操作。
Returns the start.
源码Source
io/agentscope/runtime/engine/services/agent_state/InMemoryStateService.java:57–63stop
public void stop()
执行停止相关操作。
Returns the stop.
源码Source
io/agentscope/runtime/engine/services/agent_state/InMemoryStateService.java:65–72health
public boolean health()
返回健康状态。
Returns the health.
boolean返回布尔值,表示判断结果。Returns a boolean result.
源码Source
io/agentscope/runtime/engine/services/agent_state/InMemoryStateService.java:74–77saveState
public CompletableFuture<Integer> saveState(String userId, Map<String, Object> state, String sessionId, Integer roundId)
保存状态。
Saves the state.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
state | Map<String, Object> | 状态对象(类型 `Map`)。The state. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
roundId | Integer | round 标识(类型 `Integer`)。The round id. |
CompletableFuture<Integer>返回CompletableFuture。Returns completable future.
源码Source
io/agentscope/runtime/engine/services/agent_state/InMemoryStateService.java:79–111exportState
public CompletableFuture<Map<String, Object>> exportState(String userId, String sessionId, Integer roundId)
执行 exportState 方法。
Performs the export state operation.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
roundId | Integer | round 标识(类型 `Integer`)。The round id. |
CompletableFuture<Map<String, Object>>返回CompletableFuture>。Returns completable future.
源码Source
io/agentscope/runtime/engine/services/agent_state/InMemoryStateService.java:113–143