Skip to content

[FEATURE] Server-side transport helpers for SSE streaming (pipeTextStreamToResponse) #1031

@ErikCH

Description

@ErikCH

Problem Statement

The SDK provides agent.stream() (async iterator) and event.toJSON() (serialization), but no server-side transport helpers.

Every developer building a chat UI writes the same ~20 lines of SSE boilerplate:

  • Set response headers (Content-Type: text/event-stream, Cache-Control: no-cache)
  • Iterate agent.stream() events
  • Check 3 levels of nesting to extract text deltas
  • Format as data: {...}\n\n lines
  • Handle errors gracefully
  • Call res.end()

This is the most common integration pattern for TypeScript agents, and every consumer reinvents it.

Proposed Solution

Server-side transport helpers, similar to what the Vercel AI SDK provides:

  • result.pipeTextStreamToResponse(res) — pipes text directly to an Express response
  • result.pipeUIMessageStreamToResponse(res) — pipes structured events (text deltas, tool calls, reasoning) with a defined SSE protocol
  • result.toDataStreamResponse() — returns a Web Response for edge/serverless runtimes

They also define a "Data Stream Protocol" — a standard SSE format with typed events (text-delta, tool-call, tool-result, reasoning-start, etc.) so frontends know exactly what to expect.

Vercel AI SDK docs for reference:

For Strands, even a minimal helper would eliminate the most common boilerplate:

// Minimal — just pipe text deltas as SSE
pipeTextStreamToResponse(agent, message, res)

// Richer — structured events with a defined protocol
pipeEventStreamToResponse(agent, message, res)
// Emits: { type: 'text-delta', content: '...' }
//        { type: 'tool-start', tool: '...' }
//        { type: 'tool-end', tool: '...' }
//        { type: 'done', metrics: {...} }

Use Case

Building an Express.js SSE endpoint for a chat UI where you need to:

  • Stream text deltas token-by-token to the frontend
  • Show tool call start/end indicators
  • Capture metrics from the final result event
  • Handle errors without crashing the stream

Currently requires ~20 lines of boilerplate per endpoint, including the 3-level event nesting check from #1030.

Alternatives Solutions

  • AG-UI ([FEATURE] AG-UI for Strands Agents SDK (Typescript) #347) may eventually provide a standard protocol, but a simple utility would help today
  • The A2A Express server (@strands-agents/sdk/a2a/express) exists but only serves the A2A protocol, not general SSE streaming to frontends

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions