类 JsonFileAgentStateStore
- 所有已实现的接口:
AgentStateStore
AgentStateStore implementation.
On-disk layout:
<root>/
__anon__/ ← anonymous (userId == null) sessions
<safe(sessionId)>/
agent_state.json
memory_messages.jsonl
memory_messages.hash
<safe(userId)>/ ← per-user sessions
<safe(sessionId)>/
agent_state.json
...
safe(...) keeps the literal string when it matches
^[a-zA-Z0-9_\-.]+$; otherwise it is Base64-URL encoded (no padding) so the
filesystem accepts it.
Features: atomic file operations, UTF-8 encoding, graceful handling of missing sessions, hash-based append-or-rewrite for list state.
-
构造器概要
构造器构造器说明Create aJsonFileAgentStateStorewith the default root:~/.agentscope/state.JsonFileAgentStateStore(Path rootDirectory) Create aJsonFileAgentStateStorerooted at the given directory. -
方法概要
修饰符和类型方法说明reactor.core.publisher.Mono<Integer> Clear every session under every user.voidDelete a session and all its data.voidDelete a single state entry within a session.booleanCheck if a session exists.Get a single state value.Get a list of state values.Returns the configured root directory (for diagnostics).protected PathgetSessionDir(String userId, String sessionId) Returns the directory under which all state files for(userId, sessionId)live.listSessionIds(String userId) List session identifiers visible under the given user namespace.voidSave a single state value (full replacement).voidSave a list of state values.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 io.agentscope.core.state.AgentStateStore
close
-
构造器详细资料
-
JsonFileAgentStateStore
public JsonFileAgentStateStore()Create aJsonFileAgentStateStorewith the default root:~/.agentscope/state. -
JsonFileAgentStateStore
Create aJsonFileAgentStateStorerooted at the given directory.- 参数:
rootDirectory- root directory under which user / session sub-directories live
-
-
方法详细资料
-
save
从接口复制的说明:AgentStateStoreSave a single state value (full replacement).This method saves a single state object, replacing any existing value with the same key.
- 指定者:
save在接口中AgentStateStore- 参数:
userId- nullable user identifier;null= anonymoussessionId- session identifier; must be non-null and non-blankkey- the state key (e.g.,"agent_state","toolkit_activeGroups")value- the state value to save
-
save
从接口复制的说明:AgentStateStoreSave a list of state values.Different implementations may use different storage strategies:
JsonFileAgentStateStore: incremental append — only new elements are writtenInMemoryAgentStateStore: full replacement — replaces the entire list
Callers should always pass the full list. The implementation decides the storage strategy.
- 指定者:
save在接口中AgentStateStore- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blankkey- the state key (e.g.,"memory_messages")values- the full list of state values
-
get
public <T extends State> Optional<T> get(String userId, String sessionId, String key, Class<T> type) 从接口复制的说明:AgentStateStoreGet a single state value.- 指定者:
get在接口中AgentStateStore- 类型参数:
T- the state type- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blankkey- the state keytype- the expected state type- 返回:
- the state value, or empty if not found
-
getList
public <T extends State> List<T> getList(String userId, String sessionId, String key, Class<T> itemType) 从接口复制的说明:AgentStateStoreGet a list of state values.- 指定者:
getList在接口中AgentStateStore- 类型参数:
T- the item type- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blankkey- the state keyitemType- the expected item type- 返回:
- the list of state values, or empty list if not found
-
exists
从接口复制的说明:AgentStateStoreCheck if a session exists.- 指定者:
exists在接口中AgentStateStore- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blank- 返回:
- true if the session has any persisted state
-
delete
从接口复制的说明:AgentStateStoreDelete a session and all its data.- 指定者:
delete在接口中AgentStateStore- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blank
-
delete
从接口复制的说明:AgentStateStoreDelete a single state entry within a session.- 指定者:
delete在接口中AgentStateStore- 参数:
userId- nullable user identifiersessionId- session identifier; must be non-null and non-blankkey- the state key to delete
-
listSessionIds
从接口复制的说明:AgentStateStoreList session identifiers visible under the given user namespace.Use
userId == nullto list anonymous sessions. Pass a concrete user to list only that user's sessions. There is no API to list across users in one call — that is a separate administrative concern (admin starter handles it by iterating known users).- 指定者:
listSessionIds在接口中AgentStateStore- 参数:
userId- nullable user identifier- 返回:
- set of session identifiers stored under
userId
-
getRootDirectory
Returns the configured root directory (for diagnostics). -
clearAllSessions
Clear every session under every user. Returns the number of session directories removed. -
getSessionDir
Returns the directory under which all state files for(userId, sessionId)live. Subclasses can override this if they need a different layout.
-