AS AgentScopeAPI 手册 / API Reference

ToolBase

public abstract class ToolBase implements AgentTool
源码Source io/agentscope/core/tool/ToolBase.java:59–387

工具基类,让智能体以受控方式调用外部能力。位于 io.agentscope.core.tool 包,实现 AgentTool。核心成员包括 getName、getDescription、getParameters、isConcurrencySafe、isReadOnly、isReturnDirect。

Abstract base class for tools that participate in permission evaluation and ReAct execution.

Concrete subclasses describe themselves via the builder (name, description, input schema, safety flags) and may override #checkPermissions(Map, PermissionContextState) to plug their own self-check into the permission engine. The default implementation returns PermissionDecision#passthrough(String), which lets the engine fall back to its rule tables and mode-based defaults.

ToolBase implements AgentTool so instances plug directly into the existing Toolkit dispatch. Tools that produce results outside the framework (external tools) should mark externalTool=true; the ToolExecutor surfaces the call through a ToolSuspendException instead of invoking it locally.

Builder usage:

`super(ToolBase.builder()
.name("read")
.description("Read a file")
.inputSchema(schema)
.readOnly(true)
.concurrencySafe(true));
`

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
构建器,用于构建并配置目标实例。
Fluent builder for `ToolBase` subclasses.

字段摘要Field Summary

字段Field类型Type说明Description
dangerousFiles
List<String>
`dangerousFiles` 字段。
Sensitive files; subclasses may replace this list to widen or narrow protection.
dangerousDirectories
List<String>
`dangerousDirectories` 字段。
Sensitive directory names; segment-level matching applies to absolute paths.

构造器摘要Constructor Summary

构造器Constructor说明Description
protected ToolBase(Builder builder)
初始化 `ToolBase` 实例。
Builder-based constructor (preferred).
protected ToolBase(String name, String description, Map<String, Object> inputSchema, boolean readOnly, boolean concurrencySafe, boolean mcp, String mcpName, boolean externalTool, boolean stateInjected)
初始化 `ToolBase` 实例。
Positional constructor used by built-in tools and any subclass that prefers explicit arguments over `#builder()`.

方法摘要Method Summary

方法Method说明Description
public final String getName()
final
获取名称。
Returns the name.
public final String getDescription()
final
获取 `getDescription`。
Returns the description.
public final Map<String, Object> getParameters()
final
获取参数。
Returns the parameters.
public final boolean isConcurrencySafe()
final
判断是否 `isConcurrencySafe`。
Returns whether the concurrency safe.
public final boolean isReadOnly()
final
判断是否 `isReadOnly`。
Returns whether the read only.
public final boolean isReturnDirect()
final
判断是否 `isReturnDirect`。
Whether this tool's result should short-circuit the ReAct loop and be returned directly to the caller as the turn's final answer, instead of being fed back to the model for another reasoning iteration.
public final boolean isExternalTool()
final
判断是否外部工具。
Returns whether the external tool.
public final boolean isStateInjected()
final
判断是否 `isStateInjected`。
Returns whether the state injected.
public final boolean isMcp()
final
判断是否MCP。
Returns whether the mcp.
public final String getMcpName()
final
获取MCP 名称。
Returns the mcp name.
public Mono<ToolResultBlock> callAsync(ToolCallParam param)
调用异步。
Default tool invocation.
public Mono<PermissionDecision> checkPermissions(Map<String, Object> toolInput, PermissionContextState context)
检查权限。
Tool self-check invoked by the permission engine when `allowRules`/`askRules` neither allow nor reject the call outright.
public boolean matchRule(String ruleContent, Map<String, Object> toolInput)
执行 `matchRule` 方法。
Default rule matcher: a `null` `ruleContent` matches every invocation; any non-null pattern is rejected so subclasses can layer their own semantics on top.
public List<PermissionRule> generateSuggestions(Map<String, Object> toolInput)
设置该参数。
Default suggestion: a single tool-name-level `PermissionBehavior#ALLOW` rule sourced from `"suggested"`.
protected boolean isDangerousPath(String filePath)
判断是否 `isDangerousPath`。
Returns whether the dangerous path.
public static Builder builder()
static
返回构建器实例。
Returns the builder.

字段详情Field Detail

dangerousFiles

protected List<String> dangerousFiles

dangerousFiles 字段。声明为 protected List dangerousFiles。

Sensitive files; subclasses may replace this list to widen or narrow protection.

源码Source io/agentscope/core/tool/ToolBase.java:73

dangerousDirectories

protected List<String> dangerousDirectories

dangerousDirectories 字段。声明为 protected List dangerousDirectories。

Sensitive directory names; segment-level matching applies to absolute paths.

源码Source io/agentscope/core/tool/ToolBase.java:76–77

构造器详情Constructor Detail

ToolBase

protected ToolBase(Builder builder)

初始化 ToolBase 实例。

Builder-based constructor (preferred).

参数Parameters
名称Name类型Type说明Description
builderBuilder构建器(类型 `Builder`)。The builder.
源码Source io/agentscope/core/tool/ToolBase.java:80–98

ToolBase

protected ToolBase(String name, String description, Map<String, Object> inputSchema, boolean readOnly, boolean concurrencySafe, boolean mcp, String mcpName, boolean externalTool, boolean stateInjected)

初始化 ToolBase 实例。

Positional constructor used by built-in tools and any subclass that prefers explicit arguments over #builder().

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。The name.
descriptionString描述(类型 `String`)。The description.
inputSchemaMap<String, Object>输入模式(类型 `Map`)。The input schema.
readOnlyboolean读取 Only(类型 `boolean`)。The read only.
concurrencySafebooleanconcurrency 安全(类型 `boolean`)。The concurrency safe.
mcpbooleanMCP(类型 `boolean`)。The mcp.
mcpNameStringMCP 名称(类型 `String`)。The mcp name.
externalToolboolean外部工具(类型 `boolean`)。The external tool.
stateInjectedboolean状态 Injected(类型 `boolean`)。The state injected.
源码Source io/agentscope/core/tool/ToolBase.java:104–125

方法详情Method Detail

getName

public final String getName()
final

获取名称。

Returns the name.

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

getDescription

public final String getDescription()
final

获取 getDescription。

Returns the description.

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

getParameters

public final Map<String, Object> getParameters()
final

获取参数。

Returns the parameters.

返回Returns Map<String, Object>
返回映射。Returns map.
源码Source io/agentscope/core/tool/ToolBase.java:163–166

isConcurrencySafe

public final boolean isConcurrencySafe()
final

判断是否 isConcurrencySafe。

Returns whether the concurrency safe.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/tool/ToolBase.java:168–170

isReadOnly

public final boolean isReadOnly()
final

判断是否 isReadOnly。

Returns whether the read only.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/tool/ToolBase.java:172–175

isReturnDirect

public final boolean isReturnDirect()
final

判断是否 isReturnDirect。

Whether this tool's result should short-circuit the ReAct loop and be returned directly to the caller as the turn's final answer, instead of being fed back to the model for another reasoning iteration.

返回Returns boolean
返回布尔值,表示判断结果。`true` to return the result directly and skip the follow-up model call
源码Source io/agentscope/core/tool/ToolBase.java:184–187

isExternalTool

public final boolean isExternalTool()
final

判断是否外部工具。

Returns whether the external tool.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/tool/ToolBase.java:189–191

isStateInjected

public final boolean isStateInjected()
final

判断是否 isStateInjected。

Returns whether the state injected.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/tool/ToolBase.java:193–195

isMcp

public final boolean isMcp()
final

判断是否MCP。

Returns whether the mcp.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/tool/ToolBase.java:197–199

getMcpName

public final String getMcpName()
final

获取MCP 名称。

Returns the mcp name.

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

callAsync

public Mono<ToolResultBlock> callAsync(ToolCallParam param)

调用异步。

Default tool invocation.

参数Parameters
名称Name类型Type说明Description
paramToolCallParam参数(类型 `ToolCallParam`)。The param.
返回Returns Mono<ToolResultBlock>
返回Mono。Returns mono.
源码Source io/agentscope/core/tool/ToolBase.java:209–220

checkPermissions

public Mono<PermissionDecision> checkPermissions(Map<String, Object> toolInput, PermissionContextState context)

检查权限。

Tool self-check invoked by the permission engine when allowRules/askRules neither allow nor reject the call outright.

参数Parameters
名称Name类型Type说明Description
toolInputMap<String, Object>已解析工具参数。the parsed tool arguments
contextPermissionContextState上下文(类型 `PermissionContextState`)。current permission evaluation context
返回Returns Mono<PermissionDecision>
返回Mono。a Mono emitting the decision; never `null`
源码Source io/agentscope/core/tool/ToolBase.java:235–238

matchRule

public boolean matchRule(String ruleContent, Map<String, Object> toolInput)

执行 matchRule 方法。

Default rule matcher: a null ruleContent matches every invocation; any non-null pattern is rejected so subclasses can layer their own semantics on top.

参数Parameters
名称Name类型Type说明Description
ruleContentString规则内容(类型 `String`)。The rule content.
toolInputMap<String, Object>工具输入(类型 `Map`)。The tool input.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/tool/ToolBase.java:244–246

generateSuggestions

public List<PermissionRule> generateSuggestions(Map<String, Object> toolInput)

设置该参数。

Default suggestion: a single tool-name-level PermissionBehavior#ALLOW rule sourced from "suggested".

参数Parameters
名称Name类型Type说明Description
toolInputMap<String, Object>工具输入(类型 `Map`)。The tool input.
返回Returns List<PermissionRule>
返回列出。Returns list.
源码Source io/agentscope/core/tool/ToolBase.java:253–255

isDangerousPath

protected boolean isDangerousPath(String filePath)

判断是否 isDangerousPath。

Returns whether the dangerous path.

参数Parameters
名称Name类型Type说明Description
filePathString文件路径(类型 `String`)。The file path.
返回Returns boolean
返回布尔值,表示判断结果。`true` when `filePath`'s filename matches one of `#dangerousFiles` (case-insensitive), or when any segment matches one of `#dangerousDirectories`. Also resolves symlinks and re-checks the real path to prevent bypass via symlink pointing at a dangerous target.
源码Source io/agentscope/core/tool/ToolBase.java:263–280

builder

public static Builder builder()
static

返回构建器实例。

Returns the builder.

返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/core/tool/ToolBase.java:308–310

嵌套类详情Nested Class Detail

Builder

public static final class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.core.tool 包。核心成员包括 name、description、inputSchema、readOnly、concurrencySafe、externalTool。

Fluent builder for ToolBase subclasses.

继承成员Inherited Members

继承自Methods inherited from AgentTool
基于官方固定版本源码静态生成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.