AS AgentScopeAPI 手册 / API Reference

SessionStore

public final class SessionStore
源码Source io/agentscope/harness/coding/session/SessionStore.java:47–250

会话存储,负责持久化与读取数据。位于 io.agentscope.harness.coding.session 包。核心成员包括 load、save、touch、remove、listAll、get。

Durable session registry backed by a JSON file (sessions.json). Mirrors OpenClaw's sessions.json store that tracks session metadata across restarts.

Thread-safe: uses a read-write lock so concurrent reads are non-blocking and writes are serialized. File writes are atomic (write to temp, then rename).

The store file contains a JSON object keyed by sessionKey, where each value is a StoredEntry capturing the subset of SessionEntry fields that need to survive restarts.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
StoredEntry记录record
承载已存储条目数据的记录类型。
JSON-serializable subset of `SessionEntry` for disk persistence.

构造器摘要Constructor Summary

构造器Constructor说明Description
public SessionStore(Path storeFile)
初始化 `SessionStore` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public void load()
从持久化存储恢复数据。
Loads all entries from the store file into memory.
public void save(SessionEntry entry)
保存数据到持久化存储。
Persists a single session entry (upsert).
public void touch(String sessionKey, long lastActivityMs)
执行 `touch` 方法。
Updates only the `lastActivityMs` for the given key without a full entry replace.
public void remove(String sessionKey)
设置移除。
Removes a session entry by key.
public Collection<StoredEntry> listAll()
返回快照的所有已存储条目。
Returns a snapshot of all stored entries.
public Optional<StoredEntry> get(String sessionKey)
按条件读取数据。
Returns a single entry by key, if present.
public int size()
返回大小。
Returns the size.
public Path getStoreFile()
获取存储文件。
The path to the backing store file.

构造器详情Constructor Detail

SessionStore

public SessionStore(Path storeFile)

初始化 SessionStore 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
storeFilePath存储文件(类型 `Path`)。The store file.
源码Source io/agentscope/harness/coding/session/SessionStore.java:114–116

方法详情Method Detail

load

public void load()

从持久化存储恢复数据。

Loads all entries from the store file into memory.

源码Source io/agentscope/harness/coding/session/SessionStore.java:122–145

save

public void save(SessionEntry entry)

保存数据到持久化存储。

Persists a single session entry (upsert).

参数Parameters
名称Name类型Type说明Description
entrySessionEntry条目(类型 `SessionEntry`)。The entry.
源码Source io/agentscope/harness/coding/session/SessionStore.java:148–156

touch

public void touch(String sessionKey, long lastActivityMs)

执行 touch 方法。

Updates only the lastActivityMs for the given key without a full entry replace.

参数Parameters
名称Name类型Type说明Description
sessionKeyString会话键(类型 `String`)。The session key.
lastActivityMslong最后 Activity Ms(类型 `long`)。The last activity ms.
源码Source io/agentscope/harness/coding/session/SessionStore.java:159–186

remove

public void remove(String sessionKey)

设置移除。

Removes a session entry by key.

参数Parameters
名称Name类型Type说明Description
sessionKeyString会话键(类型 `String`)。The session key.
源码Source io/agentscope/harness/coding/session/SessionStore.java:189–198

listAll

public Collection<StoredEntry> listAll()

返回快照的所有已存储条目。

Returns a snapshot of all stored entries.

返回Returns Collection<StoredEntry>
返回集合。Returns collection.
源码Source io/agentscope/harness/coding/session/SessionStore.java:201–208

get

public Optional<StoredEntry> get(String sessionKey)

按条件读取数据。

Returns a single entry by key, if present.

参数Parameters
名称Name类型Type说明Description
sessionKeyString会话键(类型 `String`)。The session key.
返回Returns Optional<StoredEntry>
返回可选。Returns optional.
源码Source io/agentscope/harness/coding/session/SessionStore.java:211–218

size

public int size()

返回大小。

Returns the size.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/coding/session/SessionStore.java:220–227

getStoreFile

public Path getStoreFile()

获取存储文件。

The path to the backing store file.

返回Returns Path
返回路径。Returns path.
源码Source io/agentscope/harness/coding/session/SessionStore.java:230–232

嵌套类详情Nested Class Detail

StoredEntry

@JsonIgnoreProperties(ignoreUnknown = true) public record StoredEntry( String sessionKey, String agentId, String sessionId, String label, String kind, String spawnedBy, int spawnDepth, long createdAtMs, long lastActivityMs, String sessionFilePath, String spawnRunId, String gateKey, String userId)

承载已存储条目数据的记录类型。位于 io.agentscope.harness.coding.session 包。核心成员包括 sessionKey、agentId、sessionId、label、kind、spawnedBy。

JSON-serializable subset of SessionEntry for disk persistence. Uses @JsonIgnoreProperties(ignoreUnknown = true) for forward compatibility when new fields are added.

基于官方固定版本源码静态生成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.