ToolContextState
@JsonPropertyOrder({"max_cache_files", "max_cache_bytes", "activated_groups", "spawn_registry"}) public final class ToolContextState
io/agentscope/core/state/ToolContextState.java:50–355工具上下文状态,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.state 包。核心成员包括 getMaxCacheFiles、getMaxCacheBytes、getReadFileCache、getActivatedGroups、setActivatedGroups、addActivatedGroups。
Read-cache backing for file-touching tools (Read / Write / Edit).
Maintains an ordered LRU list of ReadCacheEntry bounded by both entry count and
total bytes. Cache reads are validated against the file's current mtime; stale entries are
evicted on access. All filesystem interaction runs on Schedulers#boundedElastic() so
Reactor's non-blocking schedulers are never blocked.
Only configuration fields (maxCacheFiles, maxCacheBytes,
activatedGroups) participate in JSON serialization. The in-memory LRU cache itself is
runtime state and is reconstructed empty on deserialization.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
SpawnEntry | 记录record | 承载 Spawn 条目数据的记录类型。 Serializable metadata for a spawned subagent, persisted alongside the parent agent's state
so that `agent_send` can lazily rebuild the live `Agent` instance after session
restore or on a different replica. |
Builder | 类class | 构建器,用于构建并配置目标实例。 A class in io.agentscope.core.state that persists and restores session and memory data across calls. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public int getMaxCacheFiles() | 获取最大缓存文件。 Returns the max cache files. |
public double getMaxCacheBytes() | 获取最大缓存字节。 Returns the max cache bytes. |
public List<ReadCacheEntry> getReadFileCache() | 缓存列出 at 调用时间的快照。 Snapshot of the cache list at call time. |
public synchronized List<String> getActivatedGroups()synchronized | 获取 `getActivatedGroups`。 Returns the activated groups. |
public synchronized void setActivatedGroups(List<String> groups)synchronized | 设置 `setActivatedGroups`。 Replace the activated tool groups with the given list. |
public synchronized void addActivatedGroups(List<String> groups)synchronized | 添加 `addActivatedGroups`。 Adds the given tool groups to the activated set, preserving order and ignoring nulls and
duplicates. |
public synchronized void removeActivatedGroups(List<String> groups)synchronized | 移除 `removeActivatedGroups`。 Removes the given tool groups from the activated set. |
public synchronized void replaceActivatedGroups(Collection<String> toRemove, Collection<String> toAdd)synchronized | 执行 `replaceActivatedGroups` 方法。 Atomically drops the groups in `toRemove` and then adds `toAdd`, preserving
order and ignoring nulls/duplicates. |
public Map<String, SpawnEntry> getSpawnRegistry() | 获取 `getSpawnRegistry`。 Returns the spawn registry. |
public void putSpawnEntry(String key, SpawnEntry entry) | 执行 `putSpawnEntry` 方法。 Register a spawned subagent entry so it survives session restore and cross-replica routing. |
public void removeSpawnEntry(String key) | 移除 `removeSpawnEntry`。 Remove a spawn entry by key. |
public Mono<Optional<ReadCacheEntry>> getCache(String filePath) | 获取缓存。 Look up the cached entry for `filePath`. |
public Mono<Void> cacheFile(String filePath, List<String> lines) | 执行缓存文件相关操作。 Insert `lines` for `filePath` into the cache, evicting older entries to satisfy
both `maxCacheFiles` and `maxCacheBytes`. |
public static Builder builder()static | 返回构建器实例。 Returns the builder. |
方法详情Method Detail
getMaxCacheFiles
public int getMaxCacheFiles()
获取最大缓存文件。
Returns the max cache files.
intio/agentscope/core/state/ToolContextState.java:94–97getMaxCacheBytes
public double getMaxCacheBytes()
获取最大缓存字节。
Returns the max cache bytes.
doubleio/agentscope/core/state/ToolContextState.java:99–102getReadFileCache
public List<ReadCacheEntry> getReadFileCache()
缓存列出 at 调用时间的快照。
Snapshot of the cache list at call time.
List<ReadCacheEntry>io/agentscope/core/state/ToolContextState.java:105–110getActivatedGroups
public synchronized List<String> getActivatedGroups()
获取 getActivatedGroups。
Returns the activated groups.
List<String>io/agentscope/core/state/ToolContextState.java:112–115setActivatedGroups
public synchronized void setActivatedGroups(List<String> groups)
设置 setActivatedGroups。
Replace the activated tool groups with the given list.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
groups | List<String> | 组(类型 `List`)。the new activated groups; `null` clears the list |
io/agentscope/core/state/ToolContextState.java:122–131addActivatedGroups
public synchronized void addActivatedGroups(List<String> groups)
添加 addActivatedGroups。
Adds the given tool groups to the activated set, preserving order and ignoring nulls and duplicates.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
groups | List<String> | 组(类型 `List`)。the groups to activate; `null` is a no-op |
io/agentscope/core/state/ToolContextState.java:140–149removeActivatedGroups
public synchronized void removeActivatedGroups(List<String> groups)
移除 removeActivatedGroups。
Removes the given tool groups from the activated set.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
groups | List<String> | 组(类型 `List`)。the groups to deactivate; `null` is a no-op |
io/agentscope/core/state/ToolContextState.java:157–162replaceActivatedGroups
public synchronized void replaceActivatedGroups(Collection<String> toRemove, Collection<String> toAdd)
执行 replaceActivatedGroups 方法。
Atomically drops the groups in toRemove and then adds toAdd, preserving order and ignoring nulls/duplicates.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toRemove | Collection<String> | 到移除(类型 `Collection`)。the groups to drop (e.g. META-scoped group names); `null` is a removal no-op |
toAdd | Collection<String> | 到添加(类型 `Collection`)。the groups to add; `null` is an addition no-op |
io/agentscope/core/state/ToolContextState.java:174–186getSpawnRegistry
public Map<String, SpawnEntry> getSpawnRegistry()
获取 getSpawnRegistry。
Returns the spawn registry.
Map<String, SpawnEntry>io/agentscope/core/state/ToolContextState.java:188–191putSpawnEntry
public void putSpawnEntry(String key, SpawnEntry entry)
执行 putSpawnEntry 方法。
Register a spawned subagent entry so it survives session restore and cross-replica routing.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。the agent key (e.g. `agent:general-purpose:uuid`) |
entry | SpawnEntry | 条目(类型 `SpawnEntry`)。the serializable spawn metadata |
io/agentscope/core/state/ToolContextState.java:199–203removeSpawnEntry
public void removeSpawnEntry(String key)
移除 removeSpawnEntry。
Remove a spawn entry by key.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
io/agentscope/core/state/ToolContextState.java:208–212getCache
public Mono<Optional<ReadCacheEntry>> getCache(String filePath)
获取缓存。
Look up the cached entry for filePath.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
filePath | String | 文件路径(类型 `String`)。The file path. |
Mono<Optional<ReadCacheEntry>>io/agentscope/core/state/ToolContextState.java:245–266cacheFile
public Mono<Void> cacheFile(String filePath, List<String> lines)
执行缓存文件相关操作。
Insert lines for filePath into the cache, evicting older entries to satisfy both maxCacheFiles and maxCacheBytes.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
filePath | String | 文件路径(类型 `String`)。The file path. |
lines | List<String> | lines(类型 `List`)。The lines. |
Mono<Void>io/agentscope/core/state/ToolContextState.java:273–302builder
public static Builder builder()
返回构建器实例。
Returns the builder.
Builderio/agentscope/core/state/ToolContextState.java:322–324嵌套类详情Nested Class Detail
SpawnEntry
public record SpawnEntry( @JsonProperty("key") String key, @JsonProperty("agent_id") String agentId, @JsonProperty("session_id") String sessionId, @JsonProperty("label") String label, @JsonProperty("depth") int depth)承载 Spawn 条目数据的记录类型。位于 io.agentscope.core.state 包。核心成员包括 key、agentId、sessionId、label、depth、SpawnEntry。
Serializable metadata for a spawned subagent, persisted alongside the parent agent's state
so that agent_send can lazily rebuild the live Agent instance after session
restore or on a different replica.
Builder
public static final class Builder构建器,用于构建并配置目标实例。位于 io.agentscope.core.state 包。核心成员包括 maxCacheFiles、maxCacheBytes、addActivatedGroup、build。
A class in io.agentscope.core.state that persists and restores session and memory data across calls. Declared in io.agentscope.core.state.