ToolExecutionContext
@Deprecated public class ToolExecutionContext
io/agentscope/core/tool/ToolExecutionContext.java:51–310工具执行上下文,让智能体以受控方式调用外部能力。位于 io.agentscope.core.tool 包。核心成员包括 get、contains、getStores、merge、builder、empty。
Facade for passing custom POJOs to tool methods via priority-based resolution.
Two-layer architecture: External interface + Storage layer (ContextStore).
Priority chain: Call → Agent → Toolkit → Spring (highest to lowest)
Example:
`// Register custom POJO
ToolExecutionContext context = ToolExecutionContext.builder()
.register(new UserContext("user123"))
.build();
// Auto-injected by type in tool methods
@Tool
public ToolResultBlock myTool(UserContext ctx) {
return ToolResultBlock.text(ctx.getUserId());
}
`
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | ToolExecutionContext的构建器。 Builder for ToolExecutionContext. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public T T get(String key, Class<T> type) | 按条件读取数据。 Retrieves an object by key and type (for multi-instance scenarios). |
public T T get(Class<T> type) | 按条件读取数据。 Retrieves an object by type only (for singleton scenarios). |
public boolean contains(String key, Class<?> type) | 执行 `contains` 方法。 Checks whether an object with the specified key and type exists in any store. |
public boolean contains(Class<?> type) | 设置该参数。 Checks whether an object of the specified type exists in any store (regardless of key). |
public List<ContextStore> getStores() | 获取 `getStores`。 Gets all stores in priority order. |
public static ToolExecutionContext merge(ToolExecutionContext... contexts)static | 设置该参数。 Merges multiple contexts into priority-based resolution chain. |
public static Builder builder()static | 返回构建器实例。 Creates a new builder for constructing ToolExecutionContext instances. |
public static ToolExecutionContext empty()static | 返回 `empty` 结果。 Creates an empty context. |
public boolean equals(Object o) | 设置该参数。 Performs the equals operation. |
public int hashCode() | 返回 `hashCode` 结果。 Returns the hash code. |
public String toString() | 返回 `toString` 结果。 Returns the to string. |
方法详情Method Detail
get
public T T get(String key, Class<T> type)
按条件读取数据。
Retrieves an object by key and type (for multi-instance scenarios).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key identifying the instance |
type | Class<T> | 类类型到检索。The class type to retrieve |
Tio/agentscope/core/tool/ToolExecutionContext.java:71–80get
public T T get(Class<T> type)
按条件读取数据。
Retrieves an object by type only (for singleton scenarios).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
type | Class<T> | 类类型到检索。The class type to retrieve |
Tio/agentscope/core/tool/ToolExecutionContext.java:89–98contains
public boolean contains(String key, Class<?> type)
执行 contains 方法。
Checks whether an object with the specified key and type exists in any store.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key identifying the instance |
type | Class<?> | 类类型到检查。The class type to check |
booleanio/agentscope/core/tool/ToolExecutionContext.java:107–114contains
public boolean contains(Class<?> type)
设置该参数。
Checks whether an object of the specified type exists in any store (regardless of key).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
type | Class<?> | 类类型到检查。The class type to check |
booleanio/agentscope/core/tool/ToolExecutionContext.java:122–129getStores
public List<ContextStore> getStores()
获取 getStores。
Gets all stores in priority order.
List<ContextStore>io/agentscope/core/tool/ToolExecutionContext.java:136–138merge
public static ToolExecutionContext merge(ToolExecutionContext... contexts)
设置该参数。
Merges multiple contexts into priority-based resolution chain.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
contexts varargs | ToolExecutionContext... | contexts(类型 `ToolExecutionContext...`)。The contexts to merge, in priority order (highest first) |
ToolExecutionContextio/agentscope/core/tool/ToolExecutionContext.java:148–166builder
public static Builder builder()
返回构建器实例。
Creates a new builder for constructing ToolExecutionContext instances.
Builderio/agentscope/core/tool/ToolExecutionContext.java:173–175empty
public static ToolExecutionContext empty()
返回 empty 结果。
Creates an empty context.
ToolExecutionContextio/agentscope/core/tool/ToolExecutionContext.java:182–184equals
public boolean equals(Object o)
设置该参数。
Performs the equals operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
o | Object | o(类型 `Object`)。The o. |
booleanio/agentscope/core/tool/ToolExecutionContext.java:186–192hashCode
public int hashCode()
返回 hashCode 结果。
Returns the hash code.
intio/agentscope/core/tool/ToolExecutionContext.java:194–197toString
public String toString()
返回 toString 结果。
Returns the to string.
Stringio/agentscope/core/tool/ToolExecutionContext.java:199–202嵌套类详情Nested Class Detail
Builder
public static class BuilderToolExecutionContext的构建器。位于 io.agentscope.core.tool 包。核心成员包括 register、addStore、build。
Builder for ToolExecutionContext.