AS AgentScopeAPI 手册 / API Reference

ContextStore

@Deprecated public interface ContextStore
源码Source io/agentscope/core/tool/ContextStore.java:53–118

定义上下文存储契约的接口。位于 io.agentscope.core.tool 包。核心成员包括 get、contains。

Storage layer abstraction for tool execution context.

This interface defines the storage contract for context objects. It supports two retrieval modes:

  • By type only: get(Class<T>) - suitable for singleton scenarios

  • By key + type: get(String, Class<T>) - suitable for multi-instance scenarios

This design allows handling both simple cases (one UserContext) and complex cases (multiple UserContext instances for different users).

Implementations can be:

  • Simple in-memory Map storage (DefaultContextStore)

  • Custom storage stores (Redis, database, etc.)

Example usage:

`// Single instance per type
DatabaseConfig config = store.get(DatabaseConfig.class);

// Multiple instances of same type
UserContext admin = store.get("admin", UserContext.class);
UserContext guest = store.get("guest", UserContext.class);
`

方法摘要Method Summary

方法Method说明Description
public T T get(String key, Class<T> type)
按条件读取数据。
Retrieves an object by key and type.
public T T get(Class<T> type)
按条件读取数据。
Retrieves an object by type only (without key).
public boolean contains(String key, Class<?> type)
执行 `contains` 方法。
Checks whether an object with the specified key and type exists.
public boolean contains(Class<?> type)
设置该参数。
Checks whether any object of the specified type exists (regardless of key).

方法详情Method Detail

get

public T T get(String key, Class<T> type)

按条件读取数据。

Retrieves an object by key and type.

参数Parameters
名称Name类型Type说明Description
keyString键(类型 `String`)。The key identifying the specific instance
typeClass<T>类类型到检索。The class type to retrieve
返回Returns T
返回T。The object instance, or null if not found
源码Source io/agentscope/core/tool/ContextStore.java:77

get

public T T get(Class<T> type)

按条件读取数据。

Retrieves an object by type only (without key).

参数Parameters
名称Name类型Type说明Description
typeClass<T>类类型到检索。The class type to retrieve
返回Returns T
返回T。The object instance, or null if not found
源码Source io/agentscope/core/tool/ContextStore.java:100

contains

public boolean contains(String key, Class<?> type)

执行 contains 方法。

Checks whether an object with the specified key and type exists.

参数Parameters
名称Name类型Type说明Description
keyString键(类型 `String`)。The key identifying the instance
typeClass<?>类类型到检查。The class type to check
返回Returns boolean
返回布尔值,表示判断结果。true if the object exists, false otherwise
源码Source io/agentscope/core/tool/ContextStore.java:109

contains

public boolean contains(Class<?> type)

设置该参数。

Checks whether any object of the specified type exists (regardless of key).

参数Parameters
名称Name类型Type说明Description
typeClass<?>类类型到检查。The class type to check
返回Returns boolean
返回布尔值,表示判断结果。true if at least one object of this type exists, false otherwise
源码Source io/agentscope/core/tool/ContextStore.java:117
基于官方固定版本源码静态生成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.