Represents a single, stateful operation or conversation between a client and an agent in the A2A Protocol. A Task encapsulates the complete lifecycle of an agent interaction, from submission through completion, cancellation, or failure. It maintains the current state, accumulated artifacts (resp
| 44 | * @see <a href="https://a2a-protocol.org/latest/">A2A Protocol Specification</a> |
| 45 | */ |
| 46 | public record Task(String id, String contextId, TaskStatus status, @Nullable List<Artifact> artifacts, |
| 47 | @Nullable List<Message> history, @Nullable Map<String, Object> metadata) implements EventKind, StreamingEventKind { |
| 48 | |
| 49 | /** |
| 50 | * The identifier when used in streaming responses |
| 51 | */ |
| 52 | public static final String STREAMING_EVENT_ID = "task"; |
| 53 | |
| 54 | /** |
| 55 | * Compact constructor with validation and defensive copying. |
| 56 | * |
| 57 | * @param id the task identifier |
| 58 | * @param contextId the context identifier |
| 59 | * @param status the task status |
| 60 | * @param artifacts the list of artifacts produced by the task |
| 61 | * @param history the message history for this task |
| 62 | * @param metadata additional metadata for the task |
| 63 | * @throws IllegalArgumentException if id, contextId, or status is null |
| 64 | */ |
| 65 | public Task { |
| 66 | Assert.checkNotNullParam("id", id); |
| 67 | Assert.checkNotNullParam("contextId", contextId); |
| 68 | Assert.checkNotNullParam("status", status); |
| 69 | artifacts = artifacts != null ? List.copyOf(artifacts) : List.of(); |
| 70 | history = history != null ? List.copyOf(history) : List.of(); |
| 71 | metadata = (metadata != null) ? Map.copyOf(metadata) : null; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public String kind() { |
| 76 | return STREAMING_EVENT_ID; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Creates a new Builder for constructing Task instances. |
| 81 | * |
| 82 | * @return a new Task.Builder instance |
| 83 | */ |
| 84 | public static Builder builder() { |
| 85 | return new Builder(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Creates a new Builder initialized with values from an existing Task. |
| 90 | * <p> |
| 91 | * This constructor allows for creating a modified copy of an existing Task |
| 92 | * by copying all fields and then selectively updating specific values. |
| 93 | * |
| 94 | * @param task the Task to copy values from |
| 95 | * @return a new Builder instance initialized with the task's values |
| 96 | */ |
| 97 | public static Builder builder(Task task) { |
| 98 | return new Builder(task); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Builder for constructing immutable {@link Task} instances. |
| 103 | * <p> |
nothing calls this directly
no test coverage detected