AS AgentScopeAPI 手册 / API Reference

CosAgentStateStore

public class CosAgentStateStore implements AgentStateStore
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:71–376

COS 智能体状态存储,负责持久化与读取数据。位于 io.agentscope.extensions.cos 包,实现 AgentStateStore。核心成员包括 builder、save、get、getList、exists、delete。

Tencent Cloud COS backed AgentStateStore.

State objects are stored as JSON files in a COS bucket with the following key layout:


{keyPrefix}{userId}/{sessionId}/{stateKey}.json — single State value
{keyPrefix}{userId}/{sessionId}/{stateKey}.list.json — List<State> as JSON array
{keyPrefix}{userId}/{sessionId}/{stateKey}.list.hash — hash for incremental append detection

Usage:

`COSClient cosClient = new COSClient(cred, clientConfig);

AgentStateStore store = CosAgentStateStore.builder()
.cosClient(cosClient)
.bucketName("my-agentscope-bucket")
.keyPrefix("agentscope/state/")
.build();

HarnessAgent agent = HarnessAgent.builder()
.stateStore(store)
.build();
`

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
构建器,用于构建并配置目标实例。
A class in io.agentscope.extensions.cos that connects agents to messaging channels and enterprise platforms.

方法摘要Method Summary

方法Method说明Description
public static Builder builder()
static
返回构建器实例。
Returns the builder.
public void save(String userId, String sessionId, String key, State value)
保存数据到持久化存储。
Performs the save operation.
public void save(String userId, String sessionId, String key, List<? extends State> values)
保存数据到持久化存储。
Performs the save operation.
public T extends State Optional<T> get(String userId, String sessionId, String key, Class<T> type)
按条件读取数据。
Performs the get operation.
public T extends State List<T> getList(String userId, String sessionId, String key, Class<T> itemType)
获取列表。
Returns the list.
public boolean exists(String userId, String sessionId)
判断数据是否存在。
Performs the exists operation.
public void delete(String userId, String sessionId)
删除数据。
Performs the delete operation.
public void delete(String userId, String sessionId, String key)
删除数据。
Performs the delete operation.
public Set<String> listSessionIds(String userId)
列出 `listSessionIds`。
Lists the session ids.
public void close()
关闭连接并释放相关资源。
Releases resources and connections.

方法详情Method Detail

builder

public static Builder builder()
static

返回构建器实例。

Returns the builder.

返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:92–94

save

public void save(String userId, String sessionId, String key, State value)

保存数据到持久化存储。

Performs the save operation.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
keyString键(类型 `String`)。The key.
valueState值(类型 `State`)。The value.
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:96–105

save

public void save(String userId, String sessionId, String key, List<? extends State> values)

保存数据到持久化存储。

Performs the save operation.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
keyString键(类型 `String`)。The key.
valuesList<? extends State>值(类型 `List`)。The values.
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:107–137

get

public T extends State Optional<T> get(String userId, String sessionId, String key, Class<T> type)

按条件读取数据。

Performs the get operation.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
keyString键(类型 `String`)。The key.
typeClass<T>类型(类型 `Class`)。The type.
返回Returns Optional<T>
返回可选。Returns optional.
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:139–152

getList

public T extends State List<T> getList(String userId, String sessionId, String key, Class<T> itemType)

获取列表。

Returns the list.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
keyString键(类型 `String`)。The key.
itemTypeClass<T>条目类型(类型 `Class`)。The item type.
返回Returns List<T>
返回列出。Returns list.
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:154–173

exists

public boolean exists(String userId, String sessionId)

判断数据是否存在。

Performs the exists operation.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:175–188

delete

public void delete(String userId, String sessionId)

删除数据。

Performs the delete operation.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:190–201

delete

public void delete(String userId, String sessionId, String key)

删除数据。

Performs the delete operation.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
keyString键(类型 `String`)。The key.
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:203–212

listSessionIds

public Set<String> listSessionIds(String userId)

列出 listSessionIds。

Lists the session ids.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
返回Returns Set<String>
返回设置。Returns set.
源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:214–231

close

public void close()

关闭连接并释放相关资源。

Releases resources and connections.

源码Source io/agentscope/extensions/cos/CosAgentStateStore.java:233–236

嵌套类详情Nested Class Detail

Builder

public static class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.extensions.cos 包。核心成员包括 cosClient、bucketName、keyPrefix、build。

A class in io.agentscope.extensions.cos that connects agents to messaging channels and enterprise platforms. Declared in io.agentscope.extensions.cos.

继承成员Inherited Members

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