StateService
public abstract class StateService extends ServiceWithLifecycleManager
源码Source
io/agentscope/runtime/engine/services/agent_state/StateService.java:42–81智能体状态管理服务的抽象基类。位于 io.agentscope.runtime.engine.services.agent_state 包,继承自 ServiceWithLifecycleManager。核心成员包括 saveState、exportState。
Abstract base class for agent state management services.
Stores and manages agent states organized by user_id, session_id, and round_id. Supports saving, retrieving, listing, and deleting states.
Usage Example:
`StateService stateService = new InMemoryStateService();
stateService.start().join();
// Save state
int roundId = stateService.saveState("user_123", stateMap, "session_456", null).join();
// Export state
Map<String, Object> state = stateService.exportState("user_123", "session_456", null).join();
`
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public abstract CompletableFuture<Integer> saveState(String userId, Map<String, Object> state, String sessionId, Integer roundId)abstract | 保存状态。 Save serialized state data for a specific user/session. |
public abstract CompletableFuture<Map<String, Object>> exportState(String userId, String sessionId, Integer roundId)abstract | 执行 `exportState` 方法。 Retrieve serialized state data for a user/session. |
方法详情Method Detail
saveState
public abstract CompletableFuture<Integer> saveState(String userId, Map<String, Object> state, String sessionId, Integer roundId)
abstract
保存状态。
Save serialized state data for a specific user/session.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The unique ID of the user |
state | Map<String, Object> | 状态对象(类型 `Map`)。A map representing serialized agent state |
sessionId | String | 会话标识(类型 `String`)。Optional session/conversation ID. Defaults to "default" |
roundId | Integer | round 标识(类型 `Integer`)。Optional conversation round number |
CompletableFuture<Integer>返回CompletableFuture。A CompletableFuture that completes with the round_id in which the state was saved
源码Source
io/agentscope/runtime/engine/services/agent_state/StateService.java:57–62exportState
public abstract CompletableFuture<Map<String, Object>> exportState(String userId, String sessionId, Integer roundId)
abstract
执行 exportState 方法。
Retrieve serialized state data for a user/session.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The unique ID of the user |
sessionId | String | 会话标识(类型 `String`)。Optional session/conversation ID |
roundId | Integer | round 标识(类型 `Integer`)。Optional round number |
CompletableFuture<Map<String, Object>>返回CompletableFuture>。A CompletableFuture that completes with a map representing the agent state, or null if not found
源码Source
io/agentscope/runtime/engine/services/agent_state/StateService.java:76–80