Record Class Message

java.lang.Object
java.lang.Record
dev.dokimos.core.conversation.Message
Record Components:
role - the role of the message sender
content - the message content
metadata - additional metadata about the message
toolCalls - the tool calls made on this turn; empty for a turn that called no tools

public record Message(Message.Role role, String content, Map<String,Object> metadata, List<ToolCall> toolCalls) extends Record
Represents a single message in a conversation.

Each message has a role (USER, ASSISTANT, or SYSTEM), content, optional metadata, and, for an assistant turn, the tool calls it made.

  • Constructor Details

    • Message

      public Message(Message.Role role, String content, Map<String,Object> metadata, List<ToolCall> toolCalls)
      Compact constructor.
    • Message

      public Message(Message.Role role, String content, Map<String,Object> metadata)
      Creates a message with no tool calls. Preserves the three-argument construction used before tool calls were modeled, so existing callers compile and link unchanged.
      Parameters:
      role - the role of the message sender
      content - the message content
      metadata - additional metadata about the message
  • Method Details

    • of

      public static Message of(Message.Role role, String content)
      Creates a message with just role and content.
      Parameters:
      role - the message role
      content - the message content
      Returns:
      a new message
    • user

      public static Message user(String content)
      Creates a user message.
      Parameters:
      content - the message content
      Returns:
      a new user message
    • assistant

      public static Message assistant(String content)
      Creates an assistant message.
      Parameters:
      content - the message content
      Returns:
      a new assistant message
    • assistant

      public static Message assistant(String content, List<ToolCall> toolCalls)
      Creates an assistant message carrying the tool calls it made on this turn.

      With null or empty toolCalls the result equals assistant(String).

      Parameters:
      content - the message content
      toolCalls - the tool calls made on this turn
      Returns:
      a new assistant message whose toolCalls() returns the given calls
    • system

      public static Message system(String content)
      Creates a system message.
      Parameters:
      content - the message content
      Returns:
      a new system message
    • isUser

      public boolean isUser()
      Checks if this message is from a user.
      Returns:
      true if the role is USER
    • isAssistant

      public boolean isAssistant()
      Checks if this message is from an assistant.
      Returns:
      true if the role is ASSISTANT
    • isSystem

      public boolean isSystem()
      Checks if this message is a system message.
      Returns:
      true if the role is SYSTEM
    • hasToolCalls

      public boolean hasToolCalls()
      Checks whether this message carries any tool calls.
      Returns:
      true if at least one tool call is attached
    • 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.
    • role

      public Message.Role 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
    • toolCalls

      public List<ToolCall> toolCalls()
      Returns the value of the toolCalls record component.
      Returns:
      the value of the toolCalls record component