类 JsonSession
java.lang.Object
io.agentscope.core.session.JsonSession
- 所有已实现的接口:
Session
JSON file-based session implementation.
This implementation stores session state as JSON files on the filesystem. Each session is stored in a directory named by the session ID.
Features:
- Multi-module session support
- Atomic file operations
- UTF-8 encoding
- Graceful handling of missing sessions
- Configurable storage directory
-
构造器概要
构造器构造器说明Create a JsonSession with the default session directory.JsonSession(Path sessionDirectory) Create a JsonSession with a custom session directory. -
方法概要
修饰符和类型方法说明reactor.core.publisher.Mono<Integer> Clear all sessions (for testing or cleanup).voiddelete(SessionKey sessionKey) Delete a session and all its data.voiddelete(SessionKey sessionKey, String key) Delete a single state entry within a session.booleanexists(SessionKey sessionKey) Check if a session exists.get(SessionKey sessionKey, String key, Class<T> type) Get a single state value from a JSON file.getList(SessionKey sessionKey, String key, Class<T> itemType) Get a list of state values from a JSONL file.Get the session directory path.List all session keys.voidsave(SessionKey sessionKey, String key, State value) Save a single state value to a JSON file.voidsave(SessionKey sessionKey, String key, List<? extends State> values) Save a list of state values to a JSONL file with hash-based change detection.
-
构造器详细资料
-
JsonSession
public JsonSession()Create a JsonSession with the default session directory.Uses the user's home directory with ".agentscope/sessions" as the default storage location for session files.
-
JsonSession
Create a JsonSession with a custom session directory.- 参数:
sessionDirectory- Directory to store session files
-
-
方法详细资料
-
save
Save a single state value to a JSON file.The state is stored in the session directory as {key}.json with pretty formatting.
-
save
Save a list of state values to a JSONL file with hash-based change detection.This method uses hash-based change detection to handle both append-only and mutable lists:
- If the hash changes (list was modified), the entire file is rewritten
- If the list shrinks, the entire file is rewritten
- If the list only grows (append-only), only new items are appended
- If nothing changes, the operation is skipped
-
get
Get a single state value from a JSON file. -
getList
Get a list of state values from a JSONL file. -
exists
Check if a session exists. -
delete
Delete a session and all its data. -
delete
从接口复制的说明:SessionDelete a single state entry within a session. -
listSessionKeys
List all session keys.- 指定者:
listSessionKeys在接口中Session- 返回:
- set of all session keys
-
getSessionDirectory
Get the session directory path.- 返回:
- Path to the session directory
-
clearAllSessions
Clear all sessions (for testing or cleanup).- 返回:
- Mono that completes when all sessions are deleted
-