类 ToolExecutionContext
java.lang.Object
io.agentscope.core.tool.ToolExecutionContext
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());
}
- 另请参阅:
-
嵌套类概要
嵌套类 -
方法概要
修饰符和类型方法说明static ToolExecutionContext.Builderbuilder()Creates a new builder for constructing ToolExecutionContext instances.booleanChecks whether an object of the specified type exists in any store (regardless of key).booleanChecks whether an object with the specified key and type exists in any store.static ToolExecutionContextempty()Creates an empty context.boolean<T> TRetrieves an object by type only (for singleton scenarios).<T> TRetrieves an object by key and type (for multi-instance scenarios).Gets all stores in priority order.inthashCode()static ToolExecutionContextmerge(ToolExecutionContext... contexts) Merges multiple contexts into priority-based resolution chain.toString()
-
方法详细资料
-
get
Retrieves an object by key and type (for multi-instance scenarios).- 类型参数:
T- The object type- 参数:
key- The key identifying the instancetype- The class type to retrieve- 返回:
- The object instance, or null if not found
-
get
Retrieves an object by type only (for singleton scenarios).- 类型参数:
T- The object type- 参数:
type- The class type to retrieve- 返回:
- The object instance, or null if not found
-
contains
Checks whether an object with the specified key and type exists in any store.- 参数:
key- The key identifying the instancetype- The class type to check- 返回:
- true if any store contains the object, false otherwise
-
contains
Checks whether an object of the specified type exists in any store (regardless of key).- 参数:
type- The class type to check- 返回:
- true if any store contains the object, false otherwise
-
getStores
Gets all stores in priority order.- 返回:
- Unmodifiable list of stores (never null, may be empty)
-
merge
Merges multiple contexts into priority-based resolution chain.Earlier contexts have higher priority.
- 参数:
contexts- The contexts to merge, in priority order (highest first)- 返回:
- A new merged context
-
builder
Creates a new builder for constructing ToolExecutionContext instances.- 返回:
- A new builder
-
empty
Creates an empty context.- 返回:
- An empty ToolExecutionContext
-
equals
-
hashCode
public int hashCode() -
toString
-