类 ToolValidator

java.lang.Object
io.agentscope.core.tool.ToolValidator

public final class ToolValidator extends Object
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
  • 方法详细资料

    • validateInput

      public static String validateInput(String input, Map<String,Object> schema)
      Validate tool input parameters against a JSON Schema using networknt-schema.

      This method performs comprehensive JSON Schema validation including:

      • Required fields check
      • Type validation (string, number, integer, boolean, array, object)
      • Enum values validation
      • Minimum/maximum constraints for numbers
      • MinLength/maxLength constraints for strings
      • Pattern matching for strings
      • Nested object and array validation
      参数:
      input - The input parameters to validate
      schema - The JSON Schema to validate against (from tool.getParameters())
      返回:
      null if validation passes, or an error message describing the validation failures
    • validateToolResultMatch

      public static void validateToolResultMatch(Msg assistantMsg, List<Msg> inputMsgs)
      Validate that ToolResult messages match pending ToolUse blocks.

      This validation is used in two scenarios:

      • HITL (Human-in-the-Loop) resumption via agent.call()
      • Hook-based flow control via PostReasoningEvent.gotoReasoning()

      Validation rules:

      • If assistantMsg is null or has no ToolUse blocks: validation passes
      • If assistantMsg has ToolUse blocks but inputMsgs is null/empty: throws exception
      • If inputMsgs is provided: checks that all pending ToolUse IDs have matching ToolResult IDs
      参数:
      assistantMsg - The assistant message that may contain pending ToolUse blocks
      inputMsgs - The input messages that should contain ToolResult blocks
      抛出:
      IllegalStateException - if validation fails