Record Class ToolResultPart

java.lang.Object
java.lang.Record
org.springframework.ai.chat.messages.part.ToolResultPart
Record Components:
id - the id of the tool call this result answers, or null when the provider returned no id (Ollama can)
name - the tool name, or null when unknown
content - the result content, copied and unmodifiable
isError - whether the tool reported an error
payload - provider data to replay with this part, or null
attributes - free-form attributes, copied and unmodifiable
All Implemented Interfaces:
MessagePart

public record ToolResultPart(@Nullable String id, @Nullable String name, List<MessagePart> content, boolean isError, @Nullable OpaquePayload payload, Map<String,String> attributes) extends Record implements MessagePart
The result of one tool call. The nested content lets a result carry media, which a plain string cannot.
Since:
2.1.0
Author:
Christian Tzolov
  • Constructor Details

    • ToolResultPart

      public ToolResultPart(@Nullable String id, @Nullable String name, List<MessagePart> content, boolean isError, @Nullable OpaquePayload payload, Map<String,String> attributes)
      Creates an instance of a ToolResultPart record class.
      Parameters:
      id - the value for the id record component
      name - the value for the name record component
      content - the value for the content record component
      isError - the value for the isError record component
      payload - the value for the payload record component
      attributes - the value for the attributes record component
  • Method Details

    • withAttributes

      public ToolResultPart withAttributes(Map<String,String> attributes)
      Description copied from interface: MessagePart
      Returns a copy of this part with the given attributes replacing the current ones. All other components are unchanged.
      Specified by:
      withAttributes in interface MessagePart
      Parameters:
      attributes - the new attributes, copied
      Returns:
      the copy
    • of

      public static ToolResultPart of(ToolResponseMessage.ToolResponse response)
      Wraps a legacy ToolResponseMessage.ToolResponse as a result part with a single text part. A response without text (a null response data, which the tool execution allows) becomes a part without content, so it converts back to the same response.
      Parameters:
      response - the tool response
      Returns:
      the part
    • toToolResponse

      public ToolResponseMessage.ToolResponse toToolResponse()
      Converts this part back to a legacy ToolResponseMessage.ToolResponse by joining its text content. Non-text content is dropped, since a ToolResponseMessage.ToolResponse can only carry a string, and a part without any text content yields a null response data.
      Returns:
      the tool response
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • id

      public @Nullable String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • name

      public @Nullable String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • content

      public List<MessagePart> content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component
    • isError

      public boolean isError()
      Returns the value of the isError record component.
      Returns:
      the value of the isError record component
    • payload

      public @Nullable OpaquePayload payload()
      Returns the value of the payload record component.
      Specified by:
      payload in interface MessagePart
      Returns:
      the value of the payload record component
    • attributes

      public Map<String,String> attributes()
      Returns the value of the attributes record component.
      Specified by:
      attributes in interface MessagePart
      Returns:
      the value of the attributes record component