Record Class Message
java.lang.Object
java.lang.Record
smile.llm.Message
- Record Components:
role- speaker role.parts- ordered content parts (may be empty when tool fields are set).toolCalls- assistant tool calls;nullor empty when absent.toolCallId- id of the tool call this message answers (role=tool).name- optional function / participant name.
public record Message(Role role, List<ContentPart> parts, List<ToolCall> toolCalls, String toolCallId, String name)
extends Record
Dialog message with OpenAI-style multimodal content parts and optional tool fields.
Text-only messages use a single TextPart. Multimodal turns may
interleave text with ImageUrlPart / VideoUrlPart. Assistant
turns may carry toolCalls(); tool-result turns use toolCallId().
-
Constructor Summary
ConstructorsConstructorDescriptionText-only convenience constructor.Message(Role role, List<ContentPart> parts) Role + content parts (no tool fields).Message(Role role, List<ContentPart> parts, List<ToolCall> toolCalls, String toolCallId, String name) Compact canonical constructor that validates inputs.Message(Role role, ContentPart... parts) Varargs content parts constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageFactory method for an assistant message.static MessageAssistant message with tool calls.content()Concatenates allTextParttext (ignores media parts).final booleanIndicates whether some other object is "equal to" this one.booleanhasAudio()Returns whether any part is audio.final inthashCode()Returns a hash code value for this object.booleanhasMedia()Returns whether any part is an image, video, or audio.booleanReturns whether this assistant message includes tool calls.name()Returns the value of thenamerecord component.parts()Returns the value of thepartsrecord component.role()Returns the value of therolerecord component.static MessageFactory method for a system message.static MessageTool-result message.Returns the value of thetoolCallIdrecord component.Returns the value of thetoolCallsrecord component.final StringtoString()Returns a string representation of this record class.static MessageFactory method for a user message.static Messageuser(ContentPart... parts) Multimodal user message.withParts(List<ContentPart> newParts) Copy with replaced content parts, preserving tool metadata.
-
Constructor Details
-
Message
-
Message
-
Message
Role + content parts (no tool fields).- Parameters:
role- speaker role.parts- content parts.
-
Message
Varargs content parts constructor.- Parameters:
role- speaker role.parts- content parts.
-
-
Method Details
-
content
-
hasMedia
public boolean hasMedia()Returns whether any part is an image, video, or audio.- Returns:
truewhen any part is an image, video, or audio.
-
hasAudio
public boolean hasAudio()Returns whether any part is audio.- Returns:
truewhen any part is audio.
-
hasToolCalls
public boolean hasToolCalls()Returns whether this assistant message includes tool calls.- Returns:
truewhen this assistant message includes tool calls.
-
withParts
Copy with replaced content parts, preserving tool metadata.- Parameters:
newParts- replacement parts.- Returns:
- new message.
-
system
-
user
-
user
Multimodal user message.- Parameters:
parts- ordered content parts.- Returns:
- a user message.
-
assistant
-
assistant
-
tool
-
toString
-
hashCode
-
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
-
parts
-
toolCalls
-
toolCallId
Returns the value of thetoolCallIdrecord component.- Returns:
- the value of the
toolCallIdrecord component
-
name
-