Package org.a2aproject.sdk.spec
Class Message.Builder
java.lang.Object
org.a2aproject.sdk.spec.Message.Builder
- Enclosing class:
- Message
Builder for constructing
Message instances with fluent API.
The Builder provides a convenient way to construct messages with required and optional fields. If messageId is not provided, a random UUID will be generated automatically.
Example usage:
Message userMessage = Message.builder()
.role(Message.Role.USER)
.parts(List.of(new TextPart("Hello, agent!")))
.contextId("conv-123")
.build();
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds a newMessagefrom the current builder state.Sets the conversation context identifier.extensions(List<String> extensions) Sets the list of protocol extensions used in this message.Sets the unique identifier for this message.Sets additional metadata for the message.Sets the content parts of the message.Sets the content parts of the message from varargs.referenceTaskIds(List<String> referenceTaskIds) Sets the list of reference task identifiers this message relates to.role(Message.Role role) Sets the role of the message sender.Sets the task identifier this message is associated with.
-
Method Details
-
role
Sets the role of the message sender.- Parameters:
role- the message role (required)- Returns:
- this builder for method chaining
-
parts
Sets the content parts of the message.- Parameters:
parts- the list of message parts (required, must not be empty)- Returns:
- this builder for method chaining
-
parts
Sets the content parts of the message from varargs.- Parameters:
parts- the message parts (required, must not be empty)- Returns:
- this builder for method chaining
-
messageId
Sets the unique identifier for this message.If not provided, a random UUID will be generated when
build()is called.- Parameters:
messageId- the message identifier (optional)- Returns:
- this builder for method chaining
-
contextId
Sets the conversation context identifier.- Parameters:
contextId- the context identifier (optional)- Returns:
- this builder for method chaining
-
taskId
Sets the task identifier this message is associated with.- Parameters:
taskId- the task identifier (optional)- Returns:
- this builder for method chaining
-
referenceTaskIds
Sets the list of reference task identifiers this message relates to.- Parameters:
referenceTaskIds- the list of reference task IDs (optional)- Returns:
- this builder for method chaining
-
metadata
Sets additional metadata for the message.- Parameters:
metadata- map of metadata key-value pairs (optional)- Returns:
- this builder for method chaining
-
extensions
Sets the list of protocol extensions used in this message.- Parameters:
extensions- the list of extension identifiers (optional)- Returns:
- this builder for method chaining
-
build
Builds a newMessagefrom the current builder state.If messageId was not set, a random UUID will be generated.
- Returns:
- a new Message instance
- Throws:
IllegalArgumentException- if required fields are missing or invalid
-