AS AgentScopeAPI 手册 / API Reference

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
userIdString用户标识(类型 `String`)。The unique ID of the user
stateMap<String, Object>状态对象(类型 `Map`)。A map representing serialized agent state
sessionIdString会话标识(类型 `String`)。Optional session/conversation ID. Defaults to "default"
roundIdIntegerround 标识(类型 `Integer`)。Optional conversation round number
返回Returns 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–62

exportState

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
userIdString用户标识(类型 `String`)。The unique ID of the user
sessionIdString会话标识(类型 `String`)。Optional session/conversation ID
roundIdIntegerround 标识(类型 `Integer`)。Optional round number
返回Returns 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

继承成员Inherited Members

继承自Methods inherited from ServiceWithLifecycleManager
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.