Repository navigation
feat: A2A streaming over Server-Sent Events (message/stream, tasks/resubscribe) - #17
Open
brainsparker wants to merge 1 commit into
Open
brainsparker wants to merge 1 commit into
brainsparker wants to merge 1 commit into
Conversation
…subscribe) Cards that declare capabilities.streaming now get message/stream and tasks/resubscribe (1.0 aliases SendStreamingMessage, SubscribeToTask) served as text/event-stream. The Task is the first event, then status-update and artifact-update events until a final: true status update closes the stream. Adds openTask and addArtifact for embedders driving long-running tasks, heartbeats for proxy idle timeouts, client async iterators, an SSE codec, and 24 tests. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
A2A clients can now stream task progress from a youagent agent instead of polling. When the card declares
capabilities.streaming, the server answersmessage/streamandtasks/resubscribe(A2A 1.0 namesSendStreamingMessageandSubscribeToTask) with atext/event-streamresponse. The first event is theTask;status-updateandartifact-updateevents follow until afinal: truestatus update closes the stream. Cards that do not declare streaming keep today's behavior (UnsupportedOperationError, -32004).Use it
Server side, opt in on the card and leave long-running tasks open:
The existing social handlers stream without changes because
message/streamreuses the registeredmessage/sendhandler.Client side:
Or from a shell against
examples/a2a-server.ts:Why this, why today
Streaming is the lead interop path in the A2A 1.0 SDKs, and youagent was the only part of its own A2A surface that still said no.
SendStreamingMessageandSubscribeToTask, and the a2a-js SDK reached 1.0 GA on July 22, 2026 with streaming as the documented default call path. Independent servers that declarestreaming: falseare treated as second-class by those clients. Sources: https://llm4agents.com/blog/a2a-v1-audit-breaking-changes and https://aaif.io/blog/a2a-v1-0-a-builder-s-guide-part-2-migration-security-and-productionto_a2a()servesstreaming: trueby default, so youagent agents were the odd ones out in mixed fleets. Source: https://lucaberton.com/blog/google-adk-sre-agent-mcp-a2a/Task. This PR addresses all three (X-Accel-Buffering: no, keep-alive comments every 15 seconds by default, Task always first). Sources: https://www.akarnik.com/blog/how-to-use-a2a-protocol and https://emissar.ai/learn/a2a-streaming-push-notificationsOther candidates considered today and passed on:
Implementation notes
src/a2a/sse.ts(new): spec-conformant SSE encoder (formatSseEvent,formatSseComment) and incremental parser (SseParser,parseSseStream) that handles chunk boundaries, CRLF, comments and the persisting last-event-id. Exported from the package.src/a2a/a2a-server.ts: streaming methods are routed before the handler map. Validation errors (missing params, unknown task, nomessage/sendhandler) still return plain JSON-RPC errors, so a stream is only opened once there is a Task to send. Per-task subscriber sets fan outsetTaskStatus, the newaddArtifactand follow-upmessage/sendcalls; terminal states emitfinal: trueand close every stream on the task. Disconnected clients are dropped onclose.stop()ends open streams so shutdown no longer hangs on idle keep-alive connections. New public API:openTask,addArtifact,streamingEnabled,openStreamCount, and thestreamingconfig option (enabled,heartbeatMs).src/a2a/a2a-client.ts:sendStreamingMessage,streamText,subscribeToTaskas async generators withAbortSignalsupport; a non-SSE response is unwrapped and thrown as the agent's JSON-RPC error. Streamed tasks, messages and artifacts go through the existingcompatnormalizers so legacytypeparts are rewritten tokind.src/a2a/types.ts:TaskStatusUpdateEvent,TaskArtifactUpdateEvent,StreamEvent,TaskResubscribeParams.src/schema/agent-card.schema.ts:createAgentCardacceptscapabilities.streaming(default staysfalse).kind: 'status-update', lowercase states), matching the existing README note that the v1.0 wire migration lands together with the For You network.Tests
npm run typecheck,npm test,npm run build,npm publish --dry-runall clean).src/a2a/sse.test.ts: encoder and parser round trips, split chunks, CRLF, comments, trailing flush.src/a2a/a2a-server.stream.test.ts: SSE headers and event order formessage/streamand the 1.0 alias; JSON errors before stream open; long-running task with artifact append and lastChunk;tasks/resubscribeon running and terminal tasks; fan-out to three subscribers with one disconnecting; follow-upmessage/sendrelayed to the stream; heartbeats;stop()ending streams; disabled-card behavior and thestreaming.enabledoverride; client iterators including abort and the not-supported error path.dist/output.🤖 Generated with Claude Code