AS AgentScopeAPI 手册 / API Reference

ToolExecutionContext

@Deprecated public class ToolExecutionContext
源码Source 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).

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

get

public T T get(Class<T> type)

按条件读取数据。

Retrieves an object by type only (for singleton scenarios).

参数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/ToolExecutionContext.java:89–98

contains

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

执行 contains 方法。

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

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

contains

public boolean contains(Class<?> type)

设置该参数。

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

参数Parameters
名称Name类型Type说明Description
typeClass<?>类类型到检查。The class type to check
返回Returns boolean
返回布尔值,表示判断结果。true if any store contains the object, false otherwise
源码Source io/agentscope/core/tool/ToolExecutionContext.java:122–129

getStores

public List<ContextStore> getStores()

获取 getStores。

Gets all stores in priority order.

返回Returns List<ContextStore>
返回列出。Unmodifiable list of stores (never null, may be empty)
源码Source io/agentscope/core/tool/ToolExecutionContext.java:136–138

merge

public static ToolExecutionContext merge(ToolExecutionContext... contexts)
static

设置该参数。

Merges multiple contexts into priority-based resolution chain.

参数Parameters
名称Name类型Type说明Description
contexts varargsToolExecutionContext...contexts(类型 `ToolExecutionContext...`)。The contexts to merge, in priority order (highest first)
返回Returns ToolExecutionContext
一种新的已合并上下文。A new merged context
源码Source io/agentscope/core/tool/ToolExecutionContext.java:148–166

builder

public static Builder builder()
static

返回构建器实例。

Creates a new builder for constructing ToolExecutionContext instances.

返回Returns Builder
一种新的构建器。A new builder
源码Source io/agentscope/core/tool/ToolExecutionContext.java:173–175

empty

public static ToolExecutionContext empty()
static

返回 empty 结果。

Creates an empty context.

返回Returns ToolExecutionContext
返回ToolExecutionContext。An empty ToolExecutionContext
源码Source io/agentscope/core/tool/ToolExecutionContext.java:182–184

equals

public boolean equals(Object o)

设置该参数。

Performs the equals operation.

参数Parameters
名称Name类型Type说明Description
oObjecto(类型 `Object`)。The o.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/tool/ToolExecutionContext.java:186–192

hashCode

public int hashCode()

返回 hashCode 结果。

Returns the hash code.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/core/tool/ToolExecutionContext.java:194–197

toString

public String toString()

返回 toString 结果。

Returns the to string.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/tool/ToolExecutionContext.java:199–202

嵌套类详情Nested Class Detail

Builder

public static class Builder

ToolExecutionContext的构建器。位于 io.agentscope.core.tool 包。核心成员包括 register、addStore、build。

Builder for ToolExecutionContext.

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