AS AgentScopeAPI 手册 / API Reference
注解annotation io.agentscope.core.tool 2.x

ToolParam

@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface ToolParam
源码Source io/agentscope/core/tool/ToolParam.java:59–104

用于标记工具参数相关元数据的注解。位于 io.agentscope.core.tool 包。核心成员包括 name、required、description。

Annotation to describe parameters of a tool method.

This annotation is required for all parameters of methods annotated with Tool (except ToolEmitter which is auto-injected). It provides metadata for generating JSON schemas that describe the tool's parameters to LLMs.

Usage Example:

`@Tool(name = "calculate_area", description = "Calculate rectangle area")
public double calculateArea(
@ToolParam(name = "width", description = "Width in meters", required = true)
double width,
@ToolParam(name = "height", description = "Height in meters", required = true)
double height,
@ToolParam(name = "unit", description = "Unit of measurement", required = false)
String unit
) {
// Implementation
}
`

Important Notes:

  • The name attribute is required because Java does not preserve parameter names at runtime by default

  • Parameter names should follow snake_case convention for LLM compatibility

  • Descriptions help the LLM understand what values to provide

  • ToolEmitter parameters do not need this annotation (they are framework-injected)

注解元素摘要Annotation Element Summary

元素Element类型Type默认值Default说明Description
requiredbooleantrue
判断是否此参数是必填。
Whether this parameter is required.
descriptionString""
返回 `description` 结果。
The description of this parameter.

方法摘要Method Summary

方法Method说明Description
public String name()
工具参数的名称。
The name of the tool parameter.

注解元素详情Annotation Element Detail

required

public boolean required()

判断是否此参数是必填。

Whether this parameter is required.

返回Returns boolean
返回布尔值,表示判断结果。true if required (default), false if optional
源码Source io/agentscope/core/tool/ToolParam.java:87

description

public String description()

返回 description 结果。

The description of this parameter.

返回Returns String
返回字符串结果。The parameter description, or empty string if not provided
源码Source io/agentscope/core/tool/ToolParam.java:103

方法详情Method Detail

name

public String name()

工具参数的名称。

The name of the tool parameter.

返回Returns String
返回字符串结果。The parameter name as it should appear in the tool schema
源码Source io/agentscope/core/tool/ToolParam.java:76
基于官方固定版本源码静态生成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.