Skip to content

feat: A2A streaming over Server-Sent Events (message/stream, tasks/resubscribe) - #17

Open
brainsparker wants to merge 1 commit into
mainfrom
feature/2026-10-16-a2a-sse-streaming
Open

brainsparker wants to merge 1 commit into
mainfrom
feature/2026-10-16-a2a-sse-streaming

Conversation

@brainsparker

Copy link
Copy Markdown
Owner

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 answers message/stream and tasks/resubscribe (A2A 1.0 names SendStreamingMessage and SubscribeToTask) with a text/event-stream response. The first event is the Task; status-update and artifact-update events follow until a final: true status 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:

const card = createAgentCard({ handle: 'climate-watch', interests: [{ topic: 'carbon capture' }], cadence: '6h', capabilities: { streaming: true } });
const server = new A2AServer({ agentCard: card, streaming: { heartbeatMs: 15000 } });

server.onMethod('message/send', async (params) => {
  const task = server.openTask(params.message, 'working');
  runInBackground(task.id).then((answer) => {
    server.addArtifact(task.id, { name: 'answer', parts: [{ kind: 'text', text: answer }] });
    server.setTaskStatus(task.id, 'completed');
  });
  return task;
});

The existing social handlers stream without changes because message/stream reuses the registered message/send handler.

Client side:

for await (const event of client.streamText(agentUrl, 'What changed this week?')) {
  if (event.kind === 'artifact-update') render(event.artifact);
  if (event.kind === 'status-update' && event.final) break;
}
for await (const event of client.subscribeToTask(agentUrl, taskId, { signal })) { ... }

Or from a shell against examples/a2a-server.ts:

curl -N -X POST http://localhost:3141/ -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"message/stream","params":{"message":{"role":"user","messageId":"m1","parts":[{"kind":"text","text":"hello"}]}}}'

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.

Other candidates considered today and passed on:

  1. PromptLens: judge stability (run the LLM judge N times with a shuffled rubric order and report per-item variance). Strong evidence from an October 2026 audit that 7 to 17 percent of judge verdicts flip across identical reruns (https://arxiv.org/html/2610.12083), but PromptLens received the last feature from this rotation more recently in spirit (the compare command in August), and this one is a better fit for a day when youagent is not the obvious pick.
  2. you.md: per-target size budget lint for exported instruction blocks (Codex 32 KiB, Antigravity 12k characters, Devin 6k). Real complaint, but every cap came from secondary blog posts rather than vendor docs, and shipping hard numbers that could be wrong is worse than waiting.
  3. youagent: JWS signed agent cards. Optional in the spec, and the reference SDKs currently have open verification bugs (a2a-python #1278, A2A #2249), so there is nothing reliable to interoperate with yet.

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, no message/send handler) still return plain JSON-RPC errors, so a stream is only opened once there is a Task to send. Per-task subscriber sets fan out setTaskStatus, the new addArtifact and follow-up message/send calls; terminal states emit final: true and close every stream on the task. Disconnected clients are dropped on close. stop() ends open streams so shutdown no longer hangs on idle keep-alive connections. New public API: openTask, addArtifact, streamingEnabled, openStreamCount, and the streaming config option (enabled, heartbeatMs).
  • src/a2a/a2a-client.ts: sendStreamingMessage, streamText, subscribeToTask as async generators with AbortSignal support; a non-SSE response is unwrapped and thrown as the agent's JSON-RPC error. Streamed tasks, messages and artifacts go through the existing compat normalizers so legacy type parts are rewritten to kind.
  • src/a2a/types.ts: TaskStatusUpdateEvent, TaskArtifactUpdateEvent, StreamEvent, TaskResubscribeParams.
  • src/schema/agent-card.schema.ts: createAgentCard accepts capabilities.streaming (default stays false).
  • Wire shape stays on the 0.3 dialect the rest of the binding speaks (kind: 'status-update', lowercase states), matching the existing README note that the v1.0 wire migration lands together with the For You network.
  • No new dependencies. No change for cards that do not opt in.

Tests

  • 24 new tests, 165 total, all passing locally on Node 24 (npm run typecheck, npm test, npm run build, npm publish --dry-run all 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 for message/stream and the 1.0 alias; JSON errors before stream open; long-running task with artifact append and lastChunk; tasks/resubscribe on running and terminal tasks; fan-out to three subscribers with one disconnecting; follow-up message/send relayed to the stream; heartbeats; stop() ending streams; disabled-card behavior and the streaming.enabled override; client iterators including abort and the not-supported error path.
  • Also verified end to end with curl against the built dist/ output.

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant