ContextStore
@Deprecated public interface ContextStore
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key identifying the specific instance |
type | Class<T> | 类类型到检索。The class type to retrieve |
Tio/agentscope/core/tool/ContextStore.java:77get
public T T get(Class<T> type)
按条件读取数据。
Retrieves an object by type only (without key).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
type | Class<T> | 类类型到检索。The class type to retrieve |
Tio/agentscope/core/tool/ContextStore.java:100contains
public boolean contains(String key, Class<?> type)
执行 contains 方法。
Checks whether an object with the specified key and type exists.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key identifying the instance |
type | Class<?> | 类类型到检查。The class type to check |
booleanio/agentscope/core/tool/ContextStore.java:109contains
public boolean contains(Class<?> type)
设置该参数。
Checks whether any object of the specified type exists (regardless of key).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
type | Class<?> | 类类型到检查。The class type to check |
booleanio/agentscope/core/tool/ContextStore.java:117