66 * TaskState represents the discrete states a task can be in during its execution lifecycle.
77 * States are categorized as either transitional (non-final) or terminal (final), where
88 * terminal states indicate that the task has reached its end state and will not transition further.
9+ * A subset of transitional states are also marked as interrupted, indicating the task execution
10+ * has paused and requires external action before proceeding.
911 * <p>
10- * <b>Transitional States:</b>
12+ * <b>Active Transitional States:</b>
1113 * <ul>
1214 * <li><b>TASK_STATE_SUBMITTED:</b> Task has been received by the agent and is queued for processing</li>
1315 * <li><b>TASK_STATE_WORKING:</b> Agent is actively processing the task and may produce incremental results</li>
16+ * </ul>
17+ * <p>
18+ * <b>Interrupted States:</b>
19+ * <ul>
1420 * <li><b>TASK_STATE_INPUT_REQUIRED:</b> Agent needs additional input from the user to continue</li>
1521 * <li><b>TASK_STATE_AUTH_REQUIRED:</b> Agent requires authentication or authorization before proceeding</li>
1622 * </ul>
2531 * </ul>
2632 * <p>
2733 * The {@link #isFinal()} method can be used to determine if a state is terminal, which is
28- * important for event queue management and client polling logic.
34+ * important for event queue management and client polling logic. The {@link #isInterrupted()}
35+ * method identifies states where the task is paused awaiting external action.
2936 *
3037 * @see TaskStatus
3138 * @see Task
3239 * @see <a href="https://a2a-protocol.org/latest/">A2A Protocol Specification</a>
3340 */
3441public enum TaskState {
3542 /** Task has been received and is queued for processing (transitional state). */
36- TASK_STATE_SUBMITTED (false ),
43+ TASK_STATE_SUBMITTED (false , false ),
3744
3845 /** Agent is actively processing the task (transitional state). */
39- TASK_STATE_WORKING (false ),
46+ TASK_STATE_WORKING (false , false ),
4047
41- /** Agent requires additional input from the user to continue (transitional state). */
42- TASK_STATE_INPUT_REQUIRED (false ),
48+ /** Agent requires additional input from the user to continue (interrupted state). */
49+ TASK_STATE_INPUT_REQUIRED (false , true ),
4350
44- /** Agent requires authentication or authorization to proceed (transitional state). */
45- TASK_STATE_AUTH_REQUIRED (false ),
51+ /** Agent requires authentication or authorization to proceed (interrupted state). */
52+ TASK_STATE_AUTH_REQUIRED (false , true ),
4653
4754 /** Task completed successfully (terminal state). */
48- TASK_STATE_COMPLETED (true ),
55+ TASK_STATE_COMPLETED (true , false ),
4956
5057 /** Task was canceled by user or system (terminal state). */
51- TASK_STATE_CANCELED (true ),
58+ TASK_STATE_CANCELED (true , false ),
5259
5360 /** Task failed due to an error (terminal state). */
54- TASK_STATE_FAILED (true ),
61+ TASK_STATE_FAILED (true , false ),
5562
5663 /** Task was rejected by the agent (terminal state). */
57- TASK_STATE_REJECTED (true ),
64+ TASK_STATE_REJECTED (true , false ),
5865
5966 /** Task state is unknown or cannot be determined (terminal state). */
60- UNRECOGNIZED (true );
67+ UNRECOGNIZED (true , false );
6168
6269 private final boolean isFinal ;
70+ private final boolean isInterrupted ;
6371
64- TaskState (boolean isFinal ) {
72+ TaskState (boolean isFinal , boolean isInterrupted ) {
6573 this .isFinal = isFinal ;
74+ this .isInterrupted = isInterrupted ;
6675 }
6776
6877 /**
@@ -71,10 +80,32 @@ public enum TaskState {
7180 * Terminal states indicate that the task has completed its lifecycle and will
7281 * not transition to any other state. This is used by the event queue system
7382 * to determine when to close queues and by clients to know when to stop polling.
83+ * <p>
84+ * Terminal states: COMPLETED, FAILED, CANCELED, REJECTED, UNRECOGNIZED.
7485 *
7586 * @return {@code true} if this is a terminal state, {@code false} else.
7687 */
7788 public boolean isFinal (){
7889 return isFinal ;
7990 }
91+
92+ /**
93+ * Determines whether this state is an interrupted state.
94+ * <p>
95+ * Interrupted states indicate that the task execution has paused and requires
96+ * external action before proceeding. The task may resume after the required
97+ * action is provided. Interrupted states are NOT terminal - streams should
98+ * remain open to deliver state updates.
99+ * <p>
100+ * Interrupted states: INPUT_REQUIRED, AUTH_REQUIRED.
101+ * <p>
102+ * Per A2A Protocol Specification 4.1.3 (TaskState):
103+ * "TASK_STATE_INPUT_REQUIRED: This is an interrupted state."
104+ * "TASK_STATE_AUTH_REQUIRED: This is an interrupted state."
105+ *
106+ * @return {@code true} if this is an interrupted state, {@code false} else.
107+ */
108+ public boolean isInterrupted () {
109+ return isInterrupted ;
110+ }
80111}
0 commit comments