类 SchemaOnlyTool

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

public class SchemaOnlyTool extends Object implements AgentTool
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:


 // Register an external tool using ToolSchema
 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, and parameters
      抛出:
      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.
      参数:
      name - The tool name
      description - The tool description
      parameters - The tool parameters schema
      抛出:
      NullPointerException - if name or description is null
  • 方法详细资料

    • getName

      public String getName()
      从接口复制的说明: AgentTool
      Gets the name of the tool.

      The name should be unique within a toolkit and follow snake_case convention for compatibility with various LLM providers.

      指定者:
      getName 在接口中 AgentTool
      返回:
      The tool name (never null)
    • getDescription

      public String getDescription()
      从接口复制的说明: AgentTool
      Gets the description of the tool.

      The description should clearly explain what the tool does, when it should be used, and what kind of results it returns. This helps the LLM decide when to invoke the tool.

      指定者:
      getDescription 在接口中 AgentTool
      返回:
      The tool description (never null)
    • getParameters

      public Map<String,Object> getParameters()
      从接口复制的说明: AgentTool
      Gets the parameters schema for this tool in JSON Schema format.

      The schema defines the structure of the input parameters that this tool accepts. It should include:

      • type: "object"
      • properties: Map of parameter names to their schemas
      • required: List of required parameter names
      指定者:
      getParameters 在接口中 AgentTool
      返回:
      Map representing the JSON Schema for tool parameters (never null)
    • 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
      参数:
      param - The tool call parameters (ignored)
      返回:
      Never returns normally
      抛出:
      ToolSuspendException - always, to signal external execution is required