Class BaseTool

java.lang.Object
com.hw.langchain.tools.base.BaseTool
Direct Known Subclasses:
InvalidTool, Tool

public abstract class BaseTool extends Object
Interface LangChain tools must implement.
Author:
HamaWhite
  • Field Details

    • name

      public final String name
      The unique name of the tool that clearly communicates its purpose.
    • description

      public final String description
      Used to tell the model how/when/why to use the tool. You can provide few-shot examples as a part of the description.
    • returnDirect

      public final boolean returnDirect
      Whether to return the tool's output directly. Setting this to true means that after the tool is called, the AgentExecutor will stop looping.
  • Constructor Details

    • BaseTool

      protected BaseTool(String name, String description)
    • BaseTool

      protected BaseTool(String name, String description, boolean returnDirect)
  • Method Details

    • isSingleInput

      public boolean isSingleInput()
      Whether the tool only accepts a single input.
    • args

      public Map<String,Object> args()
    • innerRun

      public abstract Object innerRun(String args, Map<String,Object> kwargs)
      Use the tool.
      Parameters:
      args - Tool arguments as a String.
      kwargs - Keyword arguments as a Map<String, Object>.
      Returns:
      Result of using the tool as an Object.
    • toArgsAndKwargs

      public org.apache.commons.lang3.tuple.Pair<Object[],Map<String,Object>> toArgsAndKwargs(Object toolInput)
    • run

      public Object run(Object toolInput, Map<String,Object> kwargs)
      Run the tool.
      Parameters:
      toolInput - Input for the tool, can be a String or a Map<String, Object>.
      kwargs - Keyword arguments for the tool as a Map<String, Object>.
      Returns:
      Result of running the tool as an Object.