AS AgentScopeAPI 手册 / API Reference

ToolContextState

@JsonPropertyOrder({"max_cache_files", "max_cache_bytes", "activated_groups", "spawn_registry"}) public final class ToolContextState
源码Source 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.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/core/state/ToolContextState.java:94–97

getMaxCacheBytes

public double getMaxCacheBytes()

获取最大缓存字节。

Returns the max cache bytes.

返回Returns double
返回数值结果。Returns a numeric result.
源码Source io/agentscope/core/state/ToolContextState.java:99–102

getReadFileCache

public List<ReadCacheEntry> getReadFileCache()

缓存列出 at 调用时间的快照。

Snapshot of the cache list at call time.

返回Returns List<ReadCacheEntry>
返回列出。Returns list.
源码Source io/agentscope/core/state/ToolContextState.java:105–110

getActivatedGroups

public synchronized List<String> getActivatedGroups()
synchronized

获取 getActivatedGroups。

Returns the activated groups.

返回Returns List<String>
返回列出。Returns list.
源码Source io/agentscope/core/state/ToolContextState.java:112–115

setActivatedGroups

public synchronized void setActivatedGroups(List<String> groups)
synchronized

设置 setActivatedGroups。

Replace the activated tool groups with the given list.

参数Parameters
名称Name类型Type说明Description
groupsList<String>组(类型 `List`)。the new activated groups; `null` clears the list
源码Source io/agentscope/core/state/ToolContextState.java:122–131

addActivatedGroups

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.

参数Parameters
名称Name类型Type说明Description
groupsList<String>组(类型 `List`)。the groups to activate; `null` is a no-op
源码Source io/agentscope/core/state/ToolContextState.java:140–149

removeActivatedGroups

public synchronized void removeActivatedGroups(List<String> groups)
synchronized

移除 removeActivatedGroups。

Removes the given tool groups from the activated set.

参数Parameters
名称Name类型Type说明Description
groupsList<String>组(类型 `List`)。the groups to deactivate; `null` is a no-op
源码Source io/agentscope/core/state/ToolContextState.java:157–162

replaceActivatedGroups

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.

参数Parameters
名称Name类型Type说明Description
toRemoveCollection<String>到移除(类型 `Collection`)。the groups to drop (e.g. META-scoped group names); `null` is a removal no-op
toAddCollection<String>到添加(类型 `Collection`)。the groups to add; `null` is an addition no-op
源码Source io/agentscope/core/state/ToolContextState.java:174–186

getSpawnRegistry

public Map<String, SpawnEntry> getSpawnRegistry()

获取 getSpawnRegistry。

Returns the spawn registry.

返回Returns Map<String, SpawnEntry>
返回映射。Returns map.
源码Source io/agentscope/core/state/ToolContextState.java:188–191

putSpawnEntry

public void putSpawnEntry(String key, SpawnEntry entry)

执行 putSpawnEntry 方法。

Register a spawned subagent entry so it survives session restore and cross-replica routing.

参数Parameters
名称Name类型Type说明Description
keyString键(类型 `String`)。the agent key (e.g. `agent:general-purpose:uuid`)
entrySpawnEntry条目(类型 `SpawnEntry`)。the serializable spawn metadata
源码Source io/agentscope/core/state/ToolContextState.java:199–203

removeSpawnEntry

public void removeSpawnEntry(String key)

移除 removeSpawnEntry。

Remove a spawn entry by key.

参数Parameters
名称Name类型Type说明Description
keyString键(类型 `String`)。The key.
源码Source io/agentscope/core/state/ToolContextState.java:208–212

getCache

public Mono<Optional<ReadCacheEntry>> getCache(String filePath)

获取缓存。

Look up the cached entry for filePath.

参数Parameters
名称Name类型Type说明Description
filePathString文件路径(类型 `String`)。The file path.
返回Returns Mono<Optional<ReadCacheEntry>>
返回Mono>。Returns mono.
源码Source io/agentscope/core/state/ToolContextState.java:245–266

cacheFile

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.

参数Parameters
名称Name类型Type说明Description
filePathString文件路径(类型 `String`)。The file path.
linesList<String>lines(类型 `List`)。The lines.
返回Returns Mono<Void>
返回Mono。Returns mono.
源码Source io/agentscope/core/state/ToolContextState.java:273–302

builder

public static Builder builder()
static

返回构建器实例。

Returns the builder.

返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/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.

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