# Class BaseTool

java.lang.Object
com.google.adk.tools.BaseTool

Direct Known Subclasses:
  `AbstractMcpTool, AgentTool, BaseRetrievalTool, BuiltInCodeExecutionTool, ExampleTool, FunctionTool, GoogleMapsTool, GoogleSearchTool, IntegrationConnectorTool, LoadArtifactsTool, SetModelResponseTool, UrlContextTool, VertexAiSearchTool`

public abstract class BaseTool extends Object
The base class for all ADK tools.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `BaseTool.ToolArgsConfig`
  Configuration class for tool arguments that allows arbitrary key-value pairs.
  `static class`
  `BaseTool.ToolConfig`
  Configuration class for a tool definition in YAML/JSON.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `BaseTool(String name, String description)`
  `protected`
  `BaseTool(String name, String description, boolean isLongRunning)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `com.google.common.collect.ImmutableMap<String,Object>`
  `customMetadata()`
  Returns a read-only view of the tool metadata.
  `Optional<com.google.genai.types.FunctionDeclaration>`
  `declaration()`
  Gets the `FunctionDeclaration` representation of this tool.
  `String`
  `description()`
  `static BaseTool`
  `fromConfig(BaseTool.ToolConfig config, String configAbsPath)`
  Creates a tool instance from a config.
  `boolean`
  `longRunning()`
  `String`
  `name()`
  `io.reactivex.rxjava3.core.Completable`
  `processLlmRequest(LlmRequest.Builder llmRequestBuilder, ToolContext toolContext)`
  Processes the outgoing `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)`
  Calls a tool with generic arguments, returning the results converted to a specified type reference.
  `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)`
  Calls a tool with generic arguments and a custom `ObjectMapper`, returning the results converted to a specified type reference.
  `final <I,O> io.reactivex.rxjava3.core.Single<O>`
  `runAsync(I args, ToolContext toolContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<? extends O> oClass)`
  Calls a tool with generic arguments and a custom `ObjectMapper`, returning the results converted to a specified class.
  `final <I,O> io.reactivex.rxjava3.core.Single<O>`
  `runAsync(I args, ToolContext toolContext, Class<? extends O> oClass)`
  Calls a tool with generic arguments, returning the results converted to a specified class.
  `io.reactivex.rxjava3.core.Single<Map<String,Object>>`
  `runAsync(Map<String,Object> args, ToolContext toolContext)`
  Calls a tool.
  `final <T> io.reactivex.rxjava3.core.Single<Map<String,Object>>`
  `runAsync(T args, ToolContext toolContext)`
  Calls a tool with generic arguments and returns a map of results.
  `final <T> io.reactivex.rxjava3.core.Single<Map<String,Object>>`
  `runAsync(T args, ToolContext toolContext, com.fasterxml.jackson.databind.ObjectMapper objectMapper)`
  Calls a tool with generic arguments using a custom `ObjectMapper` and returns a map of results.
  `void`
  `setCustomMetadata(String key, Object value)`
  Sets custom metadata to the tool associated with a key.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### 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()
    Gets the `FunctionDeclaration` representation of this tool.

  - ### customMetadata

    public com.google.common.collect.ImmutableMap<String,Object> customMetadata()
    Returns a read-only view of the tool metadata.

  - ### setCustomMetadata

    public void setCustomMetadata(String key, Object value)
    Sets custom metadata to the tool associated with a key.

  - ### runAsync

    public io.reactivex.rxjava3.core.Single<Map<String,Object>> runAsync(Map<String,Object> args, ToolContext toolContext)
    Calls a tool.

  - ### runAsync

    public final <T> io.reactivex.rxjava3.core.Single<Map<String,Object>> runAsync(T args, ToolContext toolContext)
    Calls a tool with generic arguments and returns a map of results. The args type `T` need to be serializable with `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)
    Calls a tool with generic arguments using a custom `ObjectMapper` and returns a map of results. The args type `T` needs to be serializable with the provided `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)
    Calls a tool with generic arguments and a custom `ObjectMapper`, returning the results converted to a specified class. The input type `I` needs to be serializable and the output type `O` needs to be deserializable with the provided `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)
    Calls a tool with generic arguments and a custom `ObjectMapper`, returning the results converted to a specified type reference. The input type `I` needs to be serializable and the output type `O` needs to be deserializable with the provided `ObjectMapper`.

  - ### runAsync

    public final <I,O> io.reactivex.rxjava3.core.Single<O> runAsync(I args, ToolContext toolContext, Class<? extends O> oClass)
    Calls a tool with generic arguments, returning the results converted to a specified class. The input type `I` needs to be serializable and the output type `O` needs to be deserializable with `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)
    Calls a tool with generic arguments, returning the results converted to a specified type reference. The input type needs to be serializable and the output type needs to be deserializable with `JsonBaseModel.getMapper()`

  - ### processLlmRequest

    @CanIgnoreReturnValue public io.reactivex.rxjava3.core.Completable processLlmRequest(LlmRequest.Builder llmRequestBuilder, ToolContext toolContext)
    Processes the outgoing `LlmRequest.Builder`.

    This implementation adds the current tool's `declaration()` to the `GenerateContentConfig` within the builder. If a tool with function declarations already exists, the current tool's declaration is merged into it. Otherwise, a new tool definition with the current tool's declaration is created. The current tool itself is also added to the builder's internal list of tools. Override this method for processing the outgoing request.

  - ### fromConfig

    public static BaseTool fromConfig(BaseTool.ToolConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException
    Creates a tool instance from a config.

    Subclasses should override and implement this method to do custom initialization from a 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.