Package akka.javasdk.agent
Record Class UserMessage
- Record Components:
contents- The list of message content elements (text, images, etc.)
Represents a user message that can contain multimodal content for interaction with AI models.
A UserMessage encapsulates one or more MessageContent elements, allowing
agents to send text, images, or both.
Multimodal message with text and image:
UserMessage message = UserMessage.from(
MessageContent.TextMessageContent.from("What's in this image?"),
ImageMessageContent.from("https://example.com/photo.jpg")
);
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionUserMessage(List<MessageContent> contents) Creates an instance of aUserMessagerecord class. -
Method Summary
Modifier and TypeMethodDescriptioncontents()Returns the value of thecontentsrecord component.final booleanIndicates whether some other object is "equal to" this one.static UserMessagefrom(MessageContent... messageContent) Create a multimodal message from one or more content elements.static UserMessageCreate a text-only message.final inthashCode()Returns a hash code value for this object.booleanWhether this message consists of a singleMessageContent.TextMessageContentand nothing else.text()The text of this message.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
UserMessage
Creates an instance of aUserMessagerecord class.- Parameters:
contents- the value for thecontentsrecord component
-
-
Method Details
-
isTextOnly
public boolean isTextOnly()Whether this message consists of a singleMessageContent.TextMessageContentand nothing else. -
text
The text of this message.- Throws:
ClassCastException- if the first content element is not aMessageContent.TextMessageContent
-
from
Create a text-only message. -
from
Create a multimodal message from one or more content elements. -
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). -
contents
Returns the value of thecontentsrecord component.- Returns:
- the value of the
contentsrecord component
-