Class ToolSpecification

java.lang.Object
dev.langchain4j.agent.tool.ToolSpecification

public class ToolSpecification extends Object
Describes a tool that language model can execute.

Can be generated automatically from methods annotated with Tool using ToolSpecifications helper.

  • Field Details

  • Method Details

    • name

      public String name()
      Returns the name of the tool.
      Returns:
      the name of the tool.
    • description

      public String description()
      Returns the description of the tool.
      Returns:
      the description of the tool.
    • parameters

      public JsonObjectSchema parameters()
      Returns the parameters of the tool.
    • metadata

      public Map<String,Object> metadata()
      Returns the metadata relevant to the tool.

      NOTE: this metadata is not sent to the LLM provider API by default, you must explicitly specify which metadata keys should be sent when creating a ChatModel.

      NOTE: Currently, tool metadata is supported only by the langchain4j-anthropic module.

    • strict

      public Boolean strict()
      Returns whether this tool should use strict schema enforcement.

      When true, the LLM provider will validate tool calls against this tool's schema server-side. When false, strict enforcement is explicitly disabled for this tool. When null (default), the model-level strict setting is used.

      NOTE: Currently, per-tool strict is supported by the langchain4j-anthropic and langchain4j-open-ai modules.

      Returns:
      true to enable strict enforcement, false to disable, or null to use the model default.
    • equals

      public boolean equals(Object another)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toJson

      public String toJson()
      Serializes this ToolSpecification to a JSON string.
      Returns:
      a JSON string representing this tool specification.
      See Also:
    • fromJson

      public static ToolSpecification fromJson(String json)
      Deserializes a ToolSpecification from a JSON string.
      Parameters:
      json - the JSON string to deserialize.
      Returns:
      the deserialized ToolSpecification.
      See Also:
    • toBuilder

      public ToolSpecification.Builder toBuilder()
    • builder

      public static ToolSpecification.Builder builder()
      Creates builder to build ToolSpecification.
      Returns:
      created builder