Streaming and Asynchronous Operations
The A2A protocol is explicitly designed for tasks that may not complete immediately. Many AI-driven operations are long-running, involve multiple steps, produce incremental results, or need human intervention. A2A provides mechanisms to manage such asynchronous interactions so that clients receive updates effectively, whether they stay connected or operate in a more disconnected fashion.
Streaming with Server-Sent Events (SSE)
For tasks that produce incremental results (such as generating a long document or streaming media) or provide ongoing status updates, A2A supports real-time communication over Server-Sent Events (SSE). This suits clients that can maintain an active HTTP connection with the A2A server.
- Server capability: The A2A server must declare streaming support by setting
capabilities.streaming: truein its Agent Card. - Initiating a stream: The client calls
SendStreamingMessageto send an initial message (a prompt or command, for example) and subscribe to updates for that task at the same time. - Server response and connection: If the subscription succeeds, the server responds with HTTP 200 and
Content-Type: text/event-stream. The connection stays open so the server can push events to the client. - Event structure and types: Each event carries a
StreamResponsewhose payload is one of:task(Task): a snapshot of the task’s current state;message(Message): a message from the agent;statusUpdate(TaskStatusUpdateEvent): a change in the task’s lifecycle state (for example from working to input-required or completed), which can also carry intermediate agent messages;artifactUpdate(TaskArtifactUpdateEvent): new or updated artifacts produced by the task, used to stream large files or data structures in chunks, with fields such asappendandlastChunkto help reassemble them.
- Stream termination: The protocol requires the server to close the stream when the task reaches a terminal state (
TASK_STATE_COMPLETED,TASK_STATE_FAILED,TASK_STATE_CANCELED, orTASK_STATE_REJECTED). Whether a stream also closes at an interrupted state (TASK_STATE_INPUT_REQUIRED,TASK_STATE_AUTH_REQUIRED) varies: section 11.7 describes closing there, while section 7.6.1 recommends keeping already-open response streams for out-of-band authentication. Decide from the last observed task state, never from the mere fact that the stream closed; the Task runtime guide tracks the difference. - Resubscription: If the SSE connection breaks while the task is still active, the client can reconnect to the stream with
SubscribeToTask. The first event of the new stream is the currentTasksnapshot — a calibration point, not a replay of the updates that were missed while disconnected.
How events are framed depends on the protocol binding:
| Binding | Streaming mechanism | Content of each event |
|---|---|---|
| JSON-RPC 2.0 | SSE (text/event-stream) | The data field is a JSON-RPC response object whose result is a StreamResponse |
| HTTP+JSON/REST | SSE (text/event-stream) | The data field is a StreamResponse JSON object directly |
| gRPC | Server-streaming RPC | Each stream message is a StreamResponse |
An SSE response with the HTTP+JSON binding looks like this — one artifact delivered in two chunks, then the terminal state:
HTTP/1.1 200 OK
Content-Type: text/event-stream
data: {"task": {"id": "task-8f20", "contextId": "ctx-41ab", "status": {"state": "TASK_STATE_WORKING"}}}
data: {"artifactUpdate": {"taskId": "task-8f20", "contextId": "ctx-41ab", "artifact": {"artifactId": "artifact-77c3", "name": "trip-plan.md", "parts": [{"text": "# Trip Plan\n\nDay 1: "}]}}}
data: {"artifactUpdate": {"taskId": "task-8f20", "contextId": "ctx-41ab", "append": true, "lastChunk": true, "artifact": {"artifactId": "artifact-77c3", "name": "trip-plan.md", "parts": [{"text": "arrive, check in, sunset walk."}]}}}
data: {"statusUpdate": {"taskId": "task-8f20", "contextId": "ctx-41ab", "status": {"state": "TASK_STATE_COMPLETED"}}}Read the trace frame by frame. The stream opens with the Task in TASK_STATE_WORKING. The two artifactUpdate events carry the same artifactId, so they assemble one artifact: the first chunk arrives unmarked, the second sets append: true to extend it and lastChunk: true to end its chunk sequence. Only then does the statusUpdate deliver the terminal state, at which point the stream closes. This is the same trace used on the Task
and Artifact
pages, and it passes the trace validator
in the runtime guide. In real transport every SSE frame — the last one included — ends with a blank line before it is dispatched (event-stream interpretation
).
To run the validator on this sample yourself: copy the four data: payloads from the block above into trace.jsonl, one JSON object per line in arrival order, save the checker from section 4 of the runtime guide
as task-trace-lint.jq, and run:
jq -s -r -f task-trace-lint.jq trace.jsonlOK: 4 event(s), last state TASK_STATE_COMPLETEDFrom a saved SSE response, sed -n 's/^data: //p' stream.txt > trace.jsonl extracts the same four lines. Both forms assume what this example guarantees: every event is a single data: line. A complete SSE event may also span several data: lines — the event-stream interpretation
joins them with newlines before dispatch — so a multi-line payload needs that joining step before it becomes one JSON object per line.
After a dropped connection, do not guess: query with GetTask, or resubscribe with SubscribeToTask and calibrate against the Task snapshot in its first event. The runtime guide lays out the recovery branches
by task state.
When to use streaming
- Real-time progress monitoring of long-running tasks.
- Receiving large results (artifacts) incrementally.
- Interactive, conversational exchanges where immediate feedback or partial responses help.
- Applications that need low-latency updates from the agent.
Push notifications for disconnected scenarios
For very long-running tasks (minutes, hours, even days), or when clients cannot or prefer not to hold a persistent connection (mobile clients, serverless functions), A2A supports asynchronous updates through push notifications: the A2A server actively notifies a client-provided webhook when a significant task update occurs.
- Server capability: The A2A server must declare support by setting
capabilities.pushNotifications: truein its Agent Card. - Configuration: The client gives the server a
TaskPushNotificationConfig, either in the initialSendMessage/SendStreamingMessagerequest or separately withCreateTaskPushNotificationConfigfor an existing task. It includes aurl(the HTTPS webhook address), an optionaltoken(for client-side validation), and optionalauthenticationdetails (used by the A2A server to authenticate to the webhook, withschemeandcredentials). - Trigger: The A2A server decides when to send a notification, typically on a significant state change (a terminal state,
input-required, orauth-required). - Payload: The HTTP body is a
StreamResponseobject, matching the format used by streaming operations, and contains one oftask,message,statusUpdate, orartifactUpdate. - Client action: After receiving a notification and verifying its authenticity, the client typically calls
GetTaskwith thetaskIdfrom the notification to retrieve the complete, updatedTask, including any new artifacts.
When to use push notifications
- Very long-running tasks that can take minutes, hours, or days.
- Clients that cannot or prefer not to maintain persistent connections, such as mobile apps or serverless functions.
- Scenarios where clients need only significant state-change notifications rather than continuous updates.
Client-side push notification service
The url in TaskPushNotificationConfig points to a client-side push notification service. It receives the HTTP POST from the A2A server, authenticates the incoming notification, validates its relevance, and relays it to the appropriate client application logic.
Security considerations for push notifications
Because push notifications are asynchronous and initiated outbound by the server, security is paramount. Both the A2A server (sender) and the client’s webhook receiver carry critical responsibilities.
A2A server (when sending notifications to the client webhook)
- Webhook URL validation: Servers should not blindly trust and send POST requests to any URL a client provides. Malicious clients could supply URLs pointing to internal services or unrelated third-party systems, leading to Server-Side Request Forgery (SSRF) or acting as DDoS amplifiers. Mitigations include allowlisting trusted domains, ownership verification (for example challenge-response), and network controls (such as egress firewalls).
- Authenticating to the client’s webhook: The A2A server must authenticate itself to the webhook URL using the scheme specified in
TaskPushNotificationConfig.authentication. Common schemes include Bearer tokens (OAuth 2.0), API keys, HMAC signatures, and mutual TLS (mTLS).
Client webhook (when receiving notifications from the A2A server)
- Authenticating the A2A server: The webhook must rigorously verify that notification requests come from the legitimate A2A server and not an imposter. Methods include verifying signatures or tokens (for example, JWT signatures against the server’s trusted public keys, HMAC signatures, or API key validation) and validating
TaskPushNotificationConfig.tokenwhen provided. - Preventing replay attacks: Notifications should include a timestamp, and the webhook should reject notifications that are too old. For critical notifications, consider unique single-use identifiers (such as the JWT
jticlaim or event IDs) to avoid processing duplicates. - Secure key management and rotation: Apply secure key management, including regular rotation of cryptographic keys. Protocols such as JWKS (JSON Web Key Set) make rotating asymmetric keys easier.
Example asymmetric key flow (JWT + JWKS)
- The client creates a
TaskPushNotificationConfigwithauthentication.scheme: "Bearer", and possibly an expectedissueroraudiencefor the JWT. - When sending a notification, the A2A server signs a JWT with its private key, including claims such as
iss,aud,iat,exp,jti, andtaskId. The JWT header names the signing algorithm and key ID (kid), and the server publishes its public keys through a JWKS endpoint. - On receiving the notification, the client webhook extracts the JWT from the Authorization header, reads the
kidfrom the JWT header, fetches the matching public key from the server’s JWKS endpoint (caching keys is recommended), verifies the signature, validates the claims (iss,aud,iat,exp,jti), and checksTaskPushNotificationConfig.tokenif provided.
This layered approach helps ensure that push notifications are authentic, intact, and timely, protecting both the sending A2A server and the receiving client’s webhook infrastructure.
Further reading
- Specification: core operations
- Life of a Task
- Tutorial: interact with the server
- Tutorial: streaming and multi-turn
Choose a delivery path and a recovery path
Choose streaming when incremental output changes the user experience and the client can hold a connection. Choose push when the client needs to disconnect and can operate an authenticated webhook. Polling is a useful fallback when neither condition holds. Do not advertise a capability just because a library exposes its types; exercise the selected path through the deployed proxy and worker.
A stream ending is not enough to decide success. A direct-Message stream may finish normally after one message; a task stream may end because the task completed, needs input, or the connection broke. Retain the task ID and interpret the last status. If its current state is uncertain, query it before submitting the original work again.
For push, treat a validated notification as a signal to reconcile the task, not a command to execute the original business action again. A webhook can receive duplicates, and the protocol does not supply a universal exactly-once delivery guarantee. Keep notification processing separate from task creation; the push receiver guide covers authentication, duplicate handling, and recovery.
Source: Official A2A documentation: Streaming & Asynchronous Operations