Record Class Message
- Record Components:
role- the role of the message sender (user or agent)parts- the content parts of the message (text, file, or data)messageId- the unique identifier for this messagecontextId- the conversation context identifiertaskId- the task identifier this message is associated withreferenceTaskIds- list of reference task identifiersmetadata- additional metadata for the messageextensions- list of protocol extensions used in this message
- All Implemented Interfaces:
Event,EventKind,StreamingEventKind
A Message encapsulates communication content exchanged during agent interactions. It contains the message role (user or agent), content parts (text, files, or data), and contextual metadata for message threading and correlation.
Messages are fundamental to the A2A Protocol's conversational model, enabling rich multi-modal communication between users and agents. Each message has a unique identifier and can reference related tasks and contexts.
Messages implement both EventKind and StreamingEventKind, meaning they can be
sent as standalone events or as part of a streaming response sequence.
This class is mutable (allows setting taskId and contextId) to support post-construction correlation
with tasks and conversation contexts. Use the Message.Builder for construction.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructingMessageinstances with fluent API.static enumDefines the role of the message sender in the conversation. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe identifier when used in streaming responses -
Constructor Summary
ConstructorsConstructorDescriptionMessage(Message.Role role, List<Part<?>> parts, String messageId, @Nullable String contextId, @Nullable String taskId, @Nullable List<String> referenceTaskIds, @Nullable Map<String, Object> metadata, @Nullable List<String> extensions) Compact constructor with validation and defensive copying. -
Method Summary
Modifier and TypeMethodDescriptionstatic Message.Builderbuilder()Creates a new Builder for constructing Message instances.static Message.BuilderCreates a new Builder initialized with values from an existing Message.@Nullable StringReturns the value of thecontextIdrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theextensionsrecord component.final inthashCode()Returns a hash code value for this object.kind()Returns the type identifier for this event.Returns the value of themessageIdrecord component.metadata()Returns the value of themetadatarecord component.parts()Returns the value of thepartsrecord component.Returns the value of thereferenceTaskIdsrecord component.role()Returns the value of therolerecord component.@Nullable StringtaskId()Returns the value of thetaskIdrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
STREAMING_EVENT_ID
The identifier when used in streaming responses- See Also:
-
-
Constructor Details
-
Message
public Message(Message.Role role, List<Part<?>> parts, String messageId, @Nullable String contextId, @Nullable String taskId, @Nullable List<String> referenceTaskIds, @Nullable Map<String, Object> metadata, @Nullable List<String> extensions) Compact constructor with validation and defensive copying.- Parameters:
role- the role of the message sender (user or agent)parts- the content parts of the message (text, file, or data)messageId- the unique identifier for this messagecontextId- the conversation context identifiertaskId- the task identifier this message is associated withreferenceTaskIds- list of reference task identifiersmetadata- additional metadata for the messageextensions- list of protocol extensions used in this message- Throws:
IllegalArgumentException- if role, parts, or messageId is null, or if parts is empty
-
-
Method Details
-
kind
Description copied from interface:EventKindReturns the type identifier for this event.This method provides programmatic type discrimination for routing, logging, and debugging. NOTE: This value is NOT serialized to JSON in protocol v1.0+.
- Specified by:
kindin interfaceEventKind- Specified by:
kindin interfaceStreamingEventKind- Returns:
- the event kind string (e.g., "task", "message")
-
builder
Creates a new Builder for constructing Message instances.- Returns:
- a Message.builder instance
-
builder
Creates a new Builder initialized with values from an existing Message.- Parameters:
message- the Message to copy values from- Returns:
- a new Builder instance initialized with the message's values
-
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
-
parts
Returns the value of thepartsrecord component.- Returns:
- the value of the
partsrecord component
-
messageId
Returns the value of themessageIdrecord component.- Returns:
- the value of the
messageIdrecord component
-
contextId
Returns the value of thecontextIdrecord component.- Returns:
- the value of the
contextIdrecord component
-
taskId
Returns the value of thetaskIdrecord component.- Returns:
- the value of the
taskIdrecord component
-
referenceTaskIds
Returns the value of thereferenceTaskIdsrecord component.- Returns:
- the value of the
referenceTaskIdsrecord component
-
metadata
Returns the value of themetadatarecord component.- Returns:
- the value of the
metadatarecord component
-
extensions
Returns the value of theextensionsrecord component.- Returns:
- the value of the
extensionsrecord component
-