AS AgentScopeAPI 手册 / API Reference

ListHashUtil

public final class ListHashUtil
源码Source io/agentscope/core/state/ListHashUtil.java:48–171

列表 Hash Util,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.state 包。核心成员包括 computeHash、hasChanged、needsFullRewrite。

Utility class for computing hash values of state lists.

This class provides hash computation for change detection in AgentStateStore implementations. The hash is used to detect if a list has been modified (not just appended) since the last save operation.

The hash computation uses a sampling strategy to avoid iterating over large lists:

  • For small lists (≤5 elements): all elements are included

  • For large lists: samples at positions 0, 1/4, 1/2, 3/4, and last

Usage in AgentStateStore implementations:

`String currentHash = ListHashUtil.computeHash(values);
String storedHash = readStoredHash();

if (storedHash != null && !storedHash.equals(currentHash)) {
// List was modified, need full rewrite
rewriteEntireList(values);
} else if (values.size() > existingCount) {
// List grew, can append incrementally
appendNewItems(values);
}
`

方法摘要Method Summary

方法Method说明Description
public static String computeHash(List<? extends State> values)
static
计算 `computeHash`。
Compute a hash value for a list of state objects.
public static boolean hasChanged(String currentHash, String storedHash)
static
判断是否具有 `hasChanged`。
Check if the list has changed based on hash comparison.
public static boolean needsFullRewrite(List<? extends State> currentValues, String storedHash, int existingCount)
static
执行 `needsFullRewrite` 方法。
Determine if a full rewrite is needed based on list content and existing count.

方法详情Method Detail

computeHash

public static String computeHash(List<? extends State> values)
static

计算 computeHash。

Compute a hash value for a list of state objects.

参数Parameters
名称Name类型Type说明Description
valuesList<? extends State>值(类型 `List`)。the list of state objects to hash
返回Returns String
返回字符串结果。a hex string hash representing the list content
源码Source io/agentscope/core/state/ListHashUtil.java:76–95

hasChanged

public static boolean hasChanged(String currentHash, String storedHash)
static

判断是否具有 hasChanged。

Check if the list has changed based on hash comparison.

参数Parameters
名称Name类型Type说明Description
currentHashString当前 Hash(类型 `String`)。the hash of the current list
storedHashString已存储 Hash(类型 `String`)。the previously stored hash (may be null)
返回Returns boolean
返回布尔值,表示判断结果。true if the list has changed, false otherwise
源码Source io/agentscope/core/state/ListHashUtil.java:131–137

needsFullRewrite

public static boolean needsFullRewrite(List<? extends State> currentValues, String storedHash, int existingCount)
static

执行 needsFullRewrite 方法。

Determine if a full rewrite is needed based on list content and existing count.

参数Parameters
名称Name类型Type说明Description
currentValuesList<? extends State>当前值(类型 `List`)。the current complete list of state objects
storedHashString已存储 Hash(类型 `String`)。the previously stored hash (may be null)
existingCountintexisting 数量(类型 `int`)。the count of items already stored
返回Returns boolean
返回布尔值,表示判断结果。true if full rewrite is needed, false if incremental append is sufficient
源码Source io/agentscope/core/state/ListHashUtil.java:147–170
基于官方固定版本源码静态生成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.