Package dev.dokimos.core.conversation
Record Class Message
java.lang.Object
java.lang.Record
dev.dokimos.core.conversation.Message
- Record Components:
role- the role of the message sendercontent- the message contentmetadata- additional metadata about the messagetoolCalls- 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe role of a message sender in a conversation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageCreates an assistant message.static MessageCreates an assistant message carrying the tool calls it made on this turn.content()Returns the value of thecontentrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanChecks whether this message carries any tool calls.booleanChecks if this message is from an assistant.booleanisSystem()Checks if this message is a system message.booleanisUser()Checks if this message is from a user.metadata()Returns the value of themetadatarecord component.static Messageof(Message.Role role, String content) Creates a message with just role and content.role()Returns the value of therolerecord component.static MessageCreates a system message.Returns the value of thetoolCallsrecord component.final StringtoString()Returns a string representation of this record class.static MessageCreates a user message.
-
Constructor Details
-
Message
public Message(Message.Role role, String content, Map<String, Object> metadata, List<ToolCall> toolCalls) Compact constructor. -
Message
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 sendercontent- the message contentmetadata- additional metadata about the message
-
-
Method Details
-
of
Creates a message with just role and content.- Parameters:
role- the message rolecontent- the message content- Returns:
- a new message
-
user
Creates a user message.- Parameters:
content- the message content- Returns:
- a new user message
-
assistant
Creates an assistant message.- Parameters:
content- the message content- Returns:
- a new assistant message
-
assistant
Creates an assistant message carrying the tool calls it made on this turn.With
nullor emptytoolCallsthe result equalsassistant(String).- Parameters:
content- the message contenttoolCalls- the tool calls made on this turn- Returns:
- a new assistant message whose
toolCalls()returns the given calls
-
system
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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
role
Returns the value of therolerecord component.- Returns:
- the value of the
rolerecord component
-
content
Returns the value of thecontentrecord component.- Returns:
- the value of the
contentrecord component
-
metadata
Returns the value of themetadatarecord component.- Returns:
- the value of the
metadatarecord component
-
toolCalls
Returns the value of thetoolCallsrecord component.- Returns:
- the value of the
toolCallsrecord component
-