类 SchemaOnlyTool

java.lang.Object
io.agentscope.core.tool.ToolBase
io.agentscope.core.tool.SchemaOnlyTool
所有已实现的接口:
AgentTool

public class SchemaOnlyTool extends ToolBase
An external tool implementation that only contains schema definition without execution logic.

This class is used for registering external tools that will be executed outside the framework. When a model returns a call to a SchemaOnlyTool, the framework will catch the ToolSuspendException thrown by callAsync(ToolCallParam) and convert it to a pending ToolResultBlock, then return a suspended message to the user.

The callAsync(ToolCallParam) method throws a ToolSuspendException to signal that this tool requires external execution.

Example usage:


 ToolSchema schema = ToolSchema.builder()
     .name("query_database")
     .description("Query external database")
     .parameters(Map.of(
         "type", "object",
         "properties", Map.of("sql", Map.of("type", "string")),
         "required", List.of("sql")
     ))
     .build();

 toolkit.registerSchema(schema);
 // Or: toolkit.registerAgentTool(new SchemaOnlyTool(schema));
 
另请参阅:
  • 构造器详细资料

    • SchemaOnlyTool

      public SchemaOnlyTool(ToolSchema schema)
      Creates a new SchemaOnlyTool from a ToolSchema.
      参数:
      schema - The tool schema containing name, description, parameters, and strict mode
      抛出:
      NullPointerException - if schema is null
    • SchemaOnlyTool

      public SchemaOnlyTool(String name, String description, Map<String,Object> parameters)
      Creates a new SchemaOnlyTool with the specified name, description, and parameters.

      Strict mode is set to null (unspecified).

      参数:
      name - The tool name
      description - The tool description
      parameters - The tool parameters schema
      抛出:
      NullPointerException - if name or description is null
    • SchemaOnlyTool

      public SchemaOnlyTool(String name, String description, Map<String,Object> parameters, Boolean strict)
      Creates a new SchemaOnlyTool with the specified name, description, parameters, and strict mode configuration.

      The parameters map is defensively copied to prevent external mutations from affecting the tool's internal state.

      参数:
      name - The tool name
      description - The tool description
      parameters - The tool parameters schema
      strict - Whether the tool should use strict schema validation (null if unspecified)
      抛出:
      NullPointerException - if name or description is null
  • 方法详细资料

    • getStrict

      public Boolean getStrict()
      从接口复制的说明: AgentTool
      Gets strict mode configuration for this tool schema.

      When strict mode is enabled, compatible model providers are expected to enforce stricter adherence to the tool parameter schema. Returning null means no explicit strict mode preference is provided.

      返回:
      strict mode value (true/false) or null when unspecified
    • callAsync

      public reactor.core.publisher.Mono<ToolResultBlock> callAsync(ToolCallParam param)
      Throws a ToolSuspendException to signal that this tool requires external execution.

      The framework will catch this exception and convert it to a pending ToolResultBlock. The agent will then return a suspended message with GenerateReason.TOOL_SUSPENDED containing the tool use blocks that need external execution.

      指定者:
      callAsync 在接口中 AgentTool
      覆盖:
      callAsync 在类中 ToolBase
      参数:
      param - The tool call parameters (ignored)
      返回:
      Never returns normally
      抛出:
      ToolSuspendException - always, to signal external execution is required