Class Task.Builder
- Enclosing class:
- Task
Task instances.
The Builder pattern is used to enforce immutability of Task objects while providing a fluent API for setting required and optional fields. This approach ensures that once a Task is created, its state cannot be modified directly, which is important for thread-safety and protocol correctness.
Example usage:
Task task = Task.builder()
.id("task-123")
.contextId("context-456")
.status(new TaskStatus(TaskState.WORKING))
.artifacts(List.of(new Artifact(...)))
.history(List.of(userMessage))
.metadata(Map.of("key", "value"))
.build();
-
Method Summary
Modifier and TypeMethodDescriptionSets the list of artifacts produced by the agent during task execution.build()Builds an immutableTaskfrom the current builder state.Sets the context identifier associating this task with a conversation or session.Sets the conversation history for this task.Sets the conversation history using a varargs array of messages.Sets the unique identifier for this task.Sets arbitrary metadata associated with the task.status(TaskStatus status) Sets the current status of the task.
-
Method Details
-
id
Sets the unique identifier for this task.- Parameters:
id- the task ID (required)- Returns:
- this builder for method chaining
-
contextId
Sets the context identifier associating this task with a conversation or session.Multiple tasks may share the same contextId if they are part of a multi-turn conversation or related workflow.
- Parameters:
contextId- the context ID (required)- Returns:
- this builder for method chaining
-
status
Sets the current status of the task.The status includes the state (SUBMITTED, WORKING, COMPLETED, etc.), an optional message, and a timestamp.
- Parameters:
status- the task status (required)- Returns:
- this builder for method chaining
- See Also:
-
artifacts
Sets the list of artifacts produced by the agent during task execution.Artifacts represent the agent's responses or output, which may include text, files, data, or other content types. Artifacts accumulate over the lifetime of the task, especially in streaming scenarios.
- Parameters:
artifacts- the list of artifacts (optional)- Returns:
- this builder for method chaining
- See Also:
-
history
Sets the conversation history for this task.The history contains all messages exchanged between the client and agent as part of this task, providing context for multi-turn interactions.
- Parameters:
history- the list of messages (optional)- Returns:
- this builder for method chaining
- See Also:
-
history
Sets the conversation history using a varargs array of messages.This is a convenience method for setting history without creating a List explicitly.
- Parameters:
history- the messages to include in the history- Returns:
- this builder for method chaining
- See Also:
-
metadata
Sets arbitrary metadata associated with the task.Metadata can be used to store custom information about the task, such as client identifiers, routing information, or application-specific data.
- Parameters:
metadata- map of metadata key-value pairs (optional)- Returns:
- this builder for method chaining
-
build
Builds an immutableTaskfrom the current builder state.- Returns:
- a new Task instance
- Throws:
IllegalArgumentException- if any required field (id, contextId, status) is null
-