Task

Task is a core concept in the A2A protocol. It represents a stateful entity that allows a client to collaborate with a remote agent to achieve a specific outcome and generate corresponding outputs (artifacts).

Task Lifecycle and Interaction

  • Creation: Tasks are always created by the client.
  • State Management: The state of the task is determined and maintained by the remote agent (Server).
  • Session Association: Multiple tasks can belong to the same session via an optional sessionId, facilitating the management of related interactions.
  • Agent Behavior: Upon receiving a task request, the agent can take various actions:
    • Satisfy the request immediately.
    • Schedule work to be performed later.
    • Reject the request.
    • Negotiate a different execution method.
    • Request more information from the client.
    • Delegate to other agents or systems.
  • Continuous Interaction: Even after the initial task goal is met, the client can request more information or make modifications within the same task context (e.g., “Draw a rabbit,” then “Make it red”).
  • Information Transfer: Tasks are not only used to transmit final results (artifacts) and interaction messages (thoughts, instructions, etc.) but also maintain the task’s state and its optional history (state changes and message logs). This is crucial for supporting multi-turn conversational AI interactions.

Task State (TaskState)

Tasks have clearly defined states indicating their stage in the lifecycle:

  • submitted: The task has been submitted.
  • working: The task is currently being processed.
  • input-required: The task requires additional input from the client.
  • completed: The task has been successfully completed.
  • canceled: The task has been canceled.
  • failed: The task execution failed.
  • unknown: The task state is unknown.

Task-Related Interfaces

Below are key interface definitions related to tasks (illustrative):

// Task body
interface Task {
  id: string; // Unique identifier for the task
  sessionId: string; // Client-generated session ID
  status: TaskStatus; // Current status of the task
  history?: Message[]; // Message history log
  artifacts?: Artifact[]; // Collection of artifacts created by the agent
  metadata?: Record<string, any>; // Extended metadata
}

// Task status with an associated message
interface TaskStatus {
  state: TaskState;
  message?: Message; // Additional status update provided to the client
  timestamp?: string; // ISO datetime value
}

// Task state enumeration
type TaskState =
  | "submitted"
  | "working"
  | "input-required"
  | "completed"
  | "canceled"
  | "failed"
  | "unknown";

// Client parameters for creating, continuing, or restarting a task
interface TaskSendParams {
  id: string; // Task ID
  sessionId?: string; // Session ID (if not set, server creates one for a new task)
  message: Message; // The message being sent
  historyLength?: number; // Number of most recent messages to retrieve
  pushNotification?: PushNotificationConfig; // Config for server to send notifications when disconnected
  metadata?: Record<string, any>; // Extended metadata
}

// Status update event sent by the server during sendSubscribe or subscribe requests
interface TaskStatusUpdateEvent {
  id: string;
  status: TaskStatus;
  final: boolean; // Indicates if the event stream has ended
  metadata?: Record<string, any>;
}

// Artifact update event sent by the server during sendSubscribe or subscribe requests
interface TaskArtifactUpdateEvent {
  id: string;
  artifact: Artifact;
  metadata?: Record<string, any>;
}

// Push notification configuration (specific structure not detailed in source document)
interface PushNotificationConfig {
  // ... configuration details
}