类 BaseTool

java.lang.Object
com.google.adk.tools.BaseTool
Direct Known Subclasses:
AbstractMcpTool, AgentTool, BaseRetrievalTool, BuiltInCodeExecutionTool, ExampleTool, FunctionTool, GoogleMapsTool, GoogleSearchTool, IntegrationConnectorTool, LoadArtifactsTool, SetModelResponseTool, SpringAiTool, UrlContextTool, VertexAiSearchTool

public abstract class BaseTool extends Object
所有 ADK 工具的基类。
  • 嵌套类概述

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    用于工具参数的配置类,支持任意键值对(key-value pairs)的配置。
    static class 
    用于在 YAML/JSON 格式中定义工具的配置类。
  • 构造函数概述

    Constructors
    Modifier
    Constructor
    Description
    protected
    BaseTool(String name, String description)
     
    protected
    BaseTool(String name, String description, boolean isLongRunning)
     
  • 方法概述

    Modifier and Type
    Method
    Description
    com.google.common.collect.ImmutableMap<String,Object>
    返回该工具元数据的只读视图。
    Optional<com.google.genai.types.FunctionDeclaration>
    获取(所需的信息或数据) FunctionDeclaration 该工具的表示方式(即如何展示或使用该工具)。
     
    static BaseTool
    fromConfig(BaseTool.ToolConfig config, String configAbsPath)
    根据配置文件创建一个工具实例。
    boolean
     
     
    io.reactivex.rxjava3.core.Completable
    processLlmRequest(LlmRequest.Builder llmRequestBuilder, ToolContext toolContext)
    处理出站(即发送到外部系统的)数据/信息。 LlmRequest.Builder.
    final <I,O> io.reactivex.rxjava3.core.Single<O>
    runAsync(I args, ToolContext toolContext, com.fasterxml.jackson.core.type.TypeReference<? extends O> typeReference)
    调用一个带有通用参数的工具,并将返回的结果转换为指定的类型。
    final <I,O> io.reactivex.rxjava3.core.Single<O>
    runAsync(I args, ToolContext toolContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.core.type.TypeReference<? extends O> typeReference)
    调用一个工具,该工具接受通用的参数以及一个自定义的参数。 ObjectMapper返回结果后,这些结果会被转换为指定的数据类型。
    final <I,O> io.reactivex.rxjava3.core.Single<O>
    runAsync(I args, ToolContext toolContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<? extends O> oClass)
    调用一个工具,该工具接受通用的参数以及一个自定义的参数。 ObjectMapper返回结果后,这些结果会被转换成指定的类类型。
    final <I,O> io.reactivex.rxjava3.core.Single<O>
    runAsync(I args, ToolContext toolContext, Class<? extends O> oClass)
    调用一个带有通用参数的工具,并将返回的结果转换为指定的数据类型(即指定的类)。
    io.reactivex.rxjava3.core.Single<Map<String,Object>>
    runAsync(Map<String,Object> args, ToolContext toolContext)
    调用一个工具。
    final <T> io.reactivex.rxjava3.core.Single<Map<String,Object>>
    runAsync(T args, ToolContext toolContext)
    该函数使用通用的参数调用某个工具,并返回一个包含所有结果的映射(即一个键值对集合)。
    final <T> io.reactivex.rxjava3.core.Single<Map<String,Object>>
    runAsync(T args, ToolContext toolContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    使用自定义方式调用一个带有通用参数的工具。 ObjectMapper 并返回一个包含结果的映射(map)。
    void
    为与该键关联的工具设置自定义元数据。

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造函数详细信息

    • BaseTool

      protected BaseTool(String name, String description)
    • BaseTool

      protected BaseTool(String name, String description, boolean isLongRunning)
  • 方法详细信息(Method Details)

    • name

      public String name()
    • description

      public String description()
    • longRunning

      public boolean longRunning()
    • declaration

      public Optional<com.google.genai.types.FunctionDeclaration> declaration()
      获取(所需的信息或数据) FunctionDeclaration 该工具的表示方式(即如何展示或使用该工具)。
    • customMetadata

      public com.google.common.collect.ImmutableMap<String,Object> customMetadata()
      返回该工具元数据的只读视图。
    • setCustomMetadata

      public void setCustomMetadata(String key, Object value)
      为与该键关联的工具设置自定义元数据。
    • runAsync

      public io.reactivex.rxjava3.core.Single<Map<String,Object>> runAsync(Map<String,Object> args, ToolContext toolContext)
      调用一个工具。
    • runAsync

      public final <T> io.reactivex.rxjava3.core.Single<Map<String,Object>> runAsync(T args, ToolContext toolContext)
      该函数会使用通用的参数调用某个工具,并返回一个包含所有结果的映射(map)。参数的类型为 `args`。 T 需要能够被序列化(即转换为可存储或传输的形式)。 JsonBaseModel.getMapper()
    • runAsync

      public final <T> io.reactivex.rxjava3.core.Single<Map<String,Object>> runAsync(T args, ToolContext toolContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      使用自定义方式调用一个带有通用参数的工具。 ObjectMapper 该方法会返回一个包含结果的映射(map)。参数类型为 `args`。 T 需要能够使用所提供的方法进行序列化(即转换为可存储或传输的形式)。 ObjectMapper.
    • runAsync

      public final <I,O> io.reactivex.rxjava3.core.Single<O> runAsync(I args, ToolContext toolContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<? extends O> oClass)
      调用一个工具,该工具接受通用的参数以及一个自定义的参数。 ObjectMapper返回结果后,这些结果会被转换为指定的类类型。输入数据的类型是…… I 该数据需要具备可序列化的特性(即能够被转换为字节流或其他可存储的形式),并且输出数据的类型也需要被明确指定。 O 需要使用所提供的方法对其进行反序列化(即将其从序列化形式转换回原始数据结构)。 ObjectMapper.
    • runAsync

      public final <I,O> io.reactivex.rxjava3.core.Single<O> runAsync(I args, ToolContext toolContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.core.type.TypeReference<? extends O> typeReference)
      调用一个工具,该工具接受通用的参数以及一个自定义的参数。 ObjectMapper返回结果,并将其转换为指定的类型引用。输入数据的类型为…… I 该数据需要具备可序列化的特性(即能够被转换为字节流或其他格式),并且输出数据的类型也需要被明确指定。 O 需要使用所提供的方法对其进行反序列化(即将其从序列化形式转换回原始数据结构)。 ObjectMapper.
    • runAsync

      public final <I,O> io.reactivex.rxjava3.core.Single<O> runAsync(I args, ToolContext toolContext, Class<? extends O> oClass)
      调用一个带有通用参数的工具,并将返回的结果转换为指定的类类型。输入数据的类型为…… I 该数据需要具备可序列化的特性(即能够被转换为字节流或其他格式),并且输出数据的类型也需要被明确指定。 O 需要能够使用某种方法将其反序列化(即将其从序列化形式转换回原始数据结构)。 JsonBaseModel.getMapper()
    • runAsync

      public final <I,O> io.reactivex.rxjava3.core.Single<O> runAsync(I args, ToolContext toolContext, com.fasterxml.jackson.core.type.TypeReference<? extends O> typeReference)
      调用一个工具,并向其传递通用参数;该工具会将处理结果转换为指定的数据类型并返回。输入的数据类型必须具备可序列化(即能够被转换为字节流)的特性,而输出的数据类型则必须具备可反序列化(即能够从字节流中恢复为原始数据)的特性。 JsonBaseModel.getMapper()
    • processLlmRequest

      @CanIgnoreReturnValue public io.reactivex.rxjava3.core.Completable processLlmRequest(LlmRequest.Builder llmRequestBuilder, ToolContext toolContext)
      处理出站(即发送到外部系统的)数据/信息。 LlmRequest.Builder.

      此实现添加了当前工具的功能/特性。 declaration() 到…… GenerateContentConfig 在构建器(builder)的内部,如果已经存在一个包含函数声明的工具,那么当前工具的声明会被合并到那个工具中;否则,会创建一个新的工具定义(其中包含当前工具的声明)。当前工具本身也会被添加到构建器内部的工具列表中。你可以重写这个方法来处理传出的请求(outgoing requests)。

    • fromConfig

      public static BaseTool fromConfig(BaseTool.ToolConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException
      根据配置文件创建一个工具实例。

      子类应该重写并实现此方法,以便根据配置文件(config)进行自定义初始化。

      Parameters:
      config - The config for the tool.
      configAbsPath - The absolute path to the config file that contains the tool config.
      Returns:
      The tool instance.
      Throws:
      ConfigAgentUtils.ConfigurationException - if the tool cannot be created from the config.