AS AgentScopeAPI 手册 / API Reference

ToolValidator

public final class ToolValidator
源码Source io/agentscope/core/tool/ToolValidator.java:47–266

工具校验器,让智能体以受控方式调用外部能力。位于 io.agentscope.core.tool 包。核心成员包括 validateInput、validateToolResultMatch。

Unified validator for tool-related operations.

This class provides validation capabilities for:

  • Schema validation - Validates tool input parameters against JSON Schema using networknt-schema

  • HITL validation - Validates ToolResult messages match pending ToolUse blocks

方法摘要Method Summary

方法Method说明Description
public static String validateInput(String input, Map<String, Object> schema)
static
校验输入。
Validate tool input parameters against a JSON Schema using networknt-schema.
public static void validateToolResultMatch(Msg assistantMsg, List<Msg> inputMsgs)
static
校验 `validateToolResultMatch`。
Validate that ToolResult messages match pending ToolUse blocks.

方法详情Method Detail

validateInput

public static String validateInput(String input, Map<String, Object> schema)
static

校验输入。

Validate tool input parameters against a JSON Schema using networknt-schema.

参数Parameters
名称Name类型Type说明Description
inputString输入参数到校验。The input parameters to validate
schemaMap<String, Object>模式定义(类型 `Map`)。The JSON Schema to validate against (from tool.getParameters())
返回Returns String
返回字符串结果。null if validation passes, or an error message describing the validation failures
源码Source io/agentscope/core/tool/ToolValidator.java:77–106

validateToolResultMatch

public static void validateToolResultMatch(Msg assistantMsg, List<Msg> inputMsgs)
static

校验 validateToolResultMatch。

Validate that ToolResult messages match pending ToolUse blocks.

参数Parameters
名称Name类型Type说明Description
assistantMsgMsgassistant 消息(类型 `Msg`)。The assistant message that may contain pending ToolUse blocks
inputMsgsList<Msg>输入 Msgs(类型 `List`)。The input messages that should contain ToolResult blocks
抛出Throws
  • IllegalStateException 可能抛出 `IllegalStateException`。if validation fails
源码Source io/agentscope/core/tool/ToolValidator.java:229–265
基于官方固定版本源码静态生成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.