Record Class ReasoningPart

java.lang.Object
java.lang.Record
org.springframework.ai.chat.messages.part.ReasoningPart
Record Components:
text - the human-readable reasoning, or null when absent
summary - a provider-supplied summary of the reasoning, or null
payload - provider data to replay with this part, or null
attributes - free-form attributes, copied and unmodifiable
All Implemented Interfaces:
MessagePart

public record ReasoningPart(@Nullable String text, @Nullable String summary, @Nullable OpaquePayload payload, Map<String,String> attributes) extends Record implements MessagePart
Model reasoning (thinking) that preceded or accompanied the answer.

The provider-neutral text and summary are for display. The payload() carries what the producing provider requires to be replayed verbatim (a signature, encrypted content, a thought signature) and is only meaningful to that provider; see replayableTo(String).

Since:
2.1.0
Author:
Christian Tzolov
  • Constructor Details

    • ReasoningPart

      public ReasoningPart(@Nullable String text, @Nullable String summary, @Nullable OpaquePayload payload, Map<String,String> attributes)
      Creates an instance of a ReasoningPart record class.
      Parameters:
      text - the value for the text record component
      summary - the value for the summary record component
      payload - the value for the payload record component
      attributes - the value for the attributes record component
  • Method Details

    • withAttributes

      public ReasoningPart 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 ReasoningPart of(String text)
      Creates a plain reasoning part with text only, replayable to any provider.
      Parameters:
      text - the reasoning text
      Returns:
      the part
    • replayableTo

      public boolean replayableTo(String provider)
      Whether this part can be sent to the given provider without losing its payload: true when there is no payload, or when the payload was produced by that provider.
      Parameters:
      provider - the target provider, for example anthropic
      Returns:
      whether the part is replayable to the provider
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • text

      public @Nullable String text()
      Returns the value of the text record component.
      Returns:
      the value of the text record component
    • summary

      public @Nullable String summary()
      Returns the value of the summary record component.
      Returns:
      the value of the summary 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