Skip to content

Source AgentCore Bidirectional Streaming

Reese Hodge edited this page Oct 9, 2026 · 3 revisions

Source: AgentCore Bidirectional Streaming

AWS documentation for real-time two-way streaming on AgentCore Runtime, read 2026-09-27. Nothing here is a decision yet — this page records what the platform offers and what it would mean for Max Height. Adopting any of it trips the Spec Kit hybrid rule (new AWS resource and a cost-model change), so it wants a spec, not a pull request.

What the platform offers

Two protocols:

Protocol Transport Needs
WebSocket Persistent full-duplex over TCP Nothing extra
WebRTC UDP, low-latency media VPC network mode + a TURN relay

WebSocket, concretely

The runtime exposes an endpoint per agent:

wss://bedrock-agentcore.<region>.amazonaws.com/runtimes/<agentRuntimeArn>/ws

The agent container must serve WebSocket on port 8080 at /ws, and must still implement /ping for health. Any language's WebSocket library works on the client; the server side only has to honor the HTTP protocol contract.

Authentication is SigV4 (signed headers or a presigned URL with the signature in query parameters) or OAuth 2.0. Session routing uses X-Amzn-Bedrock-AgentCore-Runtime-Session-Id, passable as a header or a URL query parameter. Custom headers prefixed X-Amzn-Bedrock-AgentCore-Runtime-Custom- may also travel as query parameters.

Limits and failure modes worth knowing:

  • 32 KB maximum frame size. Larger payloads need chunking; breaching it closes the connection with 1009.
  • Close codes are the standard set — 1000, 1001, 1008 (policy/limit), 1009 (too big), 1011 (server error).
  • Pre-upgrade failures are ordinary HTTP status codes with the exception name in x-amzn-ErrorType. 409 RetryableConflictException means the session is still being provisioned or torn down — transient, retry with short exponential backoff.
  • Default idle session timeout is 15 minutes, and any message activity resets it — including ping/pong frames.
  • A trace covers the whole connection, not each message exchange.

WebRTC, concretely

Aimed at browser and mobile voice agents. Requires VPC network mode on the runtime plus a TURN relay with outbound UDP. TURN options are Kinesis Video Streams managed TURN (via GetIceServerConfig, needs a KVS signaling channel), a third-party provider, or self-hosted coturn on EC2/ECS.

Reference implementations

AWS publishes samples for the bidirectional streaming feature, including a Nova Sonic implementation doing real-time speech-to-speech with voice selection and interruption, and a Strands BidiAgent implementation that wraps the same with automatic session management and tool integration.

Nova Sonic itself was researched separately on 2026-09-29 and has its own page, Source-Nova-Sonic — including why it is not the Polly replacement it first appears to be, and its own 8-minute connection limit, which is a different limit from the idle timer discussed below.

What this would mean for Max Height

Analysis, not fact — flagged separately so the two never blur.

It could delete a whole hop

Contract-WebSocket-API currently specifies API Gateway WebSocket → Lambda → AgentCore Runtime. Native WebSocket support means the browser could talk to the runtime directly, removing API Gateway and the Lambda from the conversational path. That is less infrastructure, one less place for the contract to drift (the handler is already documented as not contract-complete), and less spend against Concept-Budget-Ceiling.

It is not free, though: the Lambda is currently where rate limiting, the 500-character clamp and budget enforcement would naturally live. Removing it means rehoming those, and they are exactly the controls P2 depends on.

Three concrete conflicts with the current contract

  1. Subprotocol. Our contract says Subprotocol: none. Browsers cannot set headers on a WebSocket handshake, so AgentCore's browser OAuth path smuggles the bearer token through Sec-WebSocket-Protocol as base64UrlBearerAuthorization.<base64url-token> plus a sentinel base64UrlBearerAuthorization value. No other subprotocol is supported.
  2. Close codes. We define a custom 4000–4500 range (cap reached, budget hard-stop, rate limited, presigned URL expired). Connecting the browser straight to the platform means the platform owns the close code, and it emits 1008/1009/1011. Our semantics would have to move into application frames rather than close codes.
  3. Heartbeat versus idle timeout. Our contract pings every 30 seconds; the platform resets the 15-minute idle timer on any activity including ping/pong. A 30-second heartbeat therefore keeps a session alive forever while a tab sits open, defeating scale-to-zero. For a project with a $10/month hard cap that is a cost bug, not a detail.

The audio angle

This is the part that connects to Source-Audio-Plan. The current design is pre-rendered greeting MP3s plus Polly for replies. Nova Sonic over a bidirectional socket is a different shape entirely: real-time speech-to-speech with native interruption, which is the feature our interrupt frame currently approximates at the text layer.

Tempting, and genuinely better for the "Max talks back" experience. But it replaces a known, cheap, pre-rendered cost with a live per-second one, and the greeting MP3s are also what hides the V2 cold start (see Decision-AgentCore-Runtime-V2). Both would need re-examining together.

WebRTC looks out of reach on budget. VPC network mode plus a TURN relay — KVS signaling channels, or coturn on EC2/ECS — adds standing infrastructure to a project whose entire ceiling is $10/month. WebSocket needs none of it. If real- time voice is ever pursued, WebSocket is the affordable door.

One platform detail that bites our stack

The SDK shown throughout the docs (bedrock_agentcore, the @app.websocket decorator, AgentCoreRuntimeClient) is Python. packages/agent is TypeScript on Node. The service contract is language-agnostic — serve /ws on 8080, implement /ping — so a Node agent can comply, but none of the convenience wrappers or the Nova Sonic and BidiAgent samples come for free.

That held through GA. Strands' BidiAgent went GA on 2026-10-05 as a Python only API. On 2026-10-09, @strands-agents/sdk 1.20.0 exported nothing equivalent; see Source-Strands-Bidi-Agents.

Also note /ws shares port 8080 with /ping, which is the port the V2 snapshot-safety work already governs: the listener must not accept connections until initialization resolves. Adding /ws widens that requirement rather than changing it.

Agent takeaway

Read this before any change to Contract-WebSocket-API or any plan touching real-time voice. Treat the three contract conflicts as blocking questions, not footnotes. Nothing here has been decided, nothing has been deployed, and adopting it needs a spec first.

See also: Contract-WebSocket-API, Decision-AgentCore-Runtime-V2, Source-Audio-Plan, Concept-Budget-Ceiling, Gotchas, Index.

Clone this wiki locally