Record Class ConversationTurn

java.lang.Object
java.lang.Record
com.tnsai.session.ConversationTurn

public record ConversationTurn(String id, Instant timestamp, TurnType type, String role, String content, Map<String,Object> metadata) extends Record
Represents a single turn in an agent conversation.

A turn can be a user message, assistant response, tool call, or tool result.

Author:
TnsAI Team
  • Constructor Details

  • Method Details

    • create

      public static ConversationTurn create(TurnType type, String role, String content)
      Creates a turn with minimal parameters.
    • create

      public static ConversationTurn create(TurnType type, String role, String content, Map<String,Object> metadata)
      Creates a turn with metadata.
    • user

      public static ConversationTurn user(String content)
      Creates a user message turn.
    • assistant

      public static ConversationTurn assistant(String content)
      Creates an assistant message turn.
    • system

      public static ConversationTurn system(String content)
      Creates a system message turn.
    • toolCall

      public static ConversationTurn toolCall(String toolName, Map<String,Object> arguments)
      Creates a tool call turn.
    • toolResult

      public static ConversationTurn toolResult(String toolName, String result)
      Creates a tool result turn.
    • getMetadataValue

      public Object getMetadataValue(String key)
      Gets a metadata value.
    • hasMetadata

      public boolean hasMetadata(String key)
      Checks if this turn has a specific metadata key.
    • getToolName

      public String getToolName()
      Gets the tool name if this is a tool-related turn.
    • 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.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component
    • type

      public TurnType type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • role

      public String role()
      Returns the value of the role record component.
      Returns:
      the value of the role record component
    • content

      public String content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component
    • metadata

      public Map<String,Object> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component