Class ToolPayload

java.lang.Object
com.suncode.pwfl.ai.tool.ToolPayload

@Api public final class ToolPayload extends Object
JSON object exchanged with a tool: arguments chosen by the model, data entered by the user or state the tool keeps between calls. Plugins read it through typed accessors or map it onto their own class, so the tool contract does not depend on the JSON library.
  • Method Details

    • fromJson

      public static ToolPayload fromJson(String json)
      Parameters:
      json - JSON text; blank text is an empty object
      Throws:
      IllegalArgumentException - when the text is not valid JSON
    • of

      public static ToolPayload of(Object value)
      Parameters:
      value - object serialized the way Jackson serializes it, e.g. a record with the tool state
    • getString

      public Optional<String> getString(String name)
      Returns:
      the field as text; empty when the field is missing or null
    • getLong

      public Optional<Long> getLong(String name)
      Returns:
      the field as a number; empty when the field is missing, null or not an integral number
    • getBoolean

      public Optional<Boolean> getBoolean(String name)
      Returns:
      the field as a boolean; empty when the field is missing, null or not a boolean
    • as

      public <T> T as(Class<T> type)
      Throws:
      IllegalArgumentException - when the payload does not match the class
    • toJson

      public String toJson()
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object