Add experimental Amazon Nova Sonic realtime support (`BedrockRealtimeModel`)

Draft
DO
2mo ago
+35108-331

Relates to #1447 (which lists "AWS Nova Sonic" as one of the realtime equivalents people asked for). The base realtime PR #6324 already closes #1447; this is an additive provider on top of it.

Status: draft / exploratory — do not merge yet

This is a feasibility spike, opened so the work isn't lost and so we can decide whether we want it at all before investing in finishing it. It targets the realtime PR's branch (realtime-v1), not main, so it rides along with that work rather than blocking it.

The good news: Amazon Nova Sonic maps cleanly onto the RealtimeModel / RealtimeConnection abstractions introduced in #6324, even though its transport is completely different — Bedrock's InvokeModelWithBidirectionalStream, an HTTP/2 bidirectional JSON-event stream, not WebSockets. The connection ABC turned out to be transport-agnostic enough that it slots in, and the wire events map almost one-to-one onto our codec (audioOutput→AudioDelta, USER/ASSISTANT textOutput→InputTranscript/Transcript, toolUse→ToolCall, usageEvent→SessionUsageEvent, completionEnd→TurnCompleteEvent). So this doubles as evidence the abstraction generalises past WebSocket providers.

The decision that gates everything: the experimental Smithy SDK

Nova Sonic's bidirectional API has no boto3 support. The only Python path is the experimental aws-sdk-bedrock-runtime (a new Smithy-generated async SDK), pinned here to 0.4.0. Before anything else, we need a maintainer call on whether we're willing to take that dependency:

  • It's a separate SDK stack from the boto3 one our existing BedrockConverseModel uses — different client, config, and auth machinery. There's no reusing BedrockProvider (it owns a boto3 client whose transport can't invoke the bidirectional operation).
  • It's 0.x and explicitly experimental, with a churny public surface.
  • It requires Python 3.12+, so the realtime-bedrock extra is marker-empty on 3.10/3.11 — a user there can pip install it but not import the module.

If the answer is "not worth it," this PR should close and we note in #1447 that Nova Sonic is blocked on upstream SDK maturity. Everything below only matters if we say yes.

Blockers before this could go non-draft

  1. Auth is unverified live. The environment I tested in has a Bedrock bearer token (AWS_BEARER_TOKEN_BEDROCK), but aws-sdk-bedrock-runtime only exposes SigV4 through its public config — no bearer auth scheme. The live smoke reached the real SDK invocation and then timed out with no events and no auth error, so no live transcript/audio behaviour has actually been verified. We need to confirm the bidirectional endpoint accepts Bedrock API keys (and get the SDK to expose a bearer scheme) or test with real SigV4 credentials before trusting any of this end to end.
  2. No transparent reconnect / session continuation. Nova has an ~8-minute connection limit; AWS documents continuing by opening a new stream and re-seeding prior turns as text. reconnect is currently a stub — a drop surfaces as a non-recoverable SessionErrorEvent. Real support means snapshotting normalised text history, re-dialling before the limit, resending the handshake + history, and emitting ReconnectedEvent only after a successful reseed.
  3. No cassette transport → thin, non-recorded tests. The WS cassette engine (ws_cassettes.py) patches websockets and doesn't apply to HTTP/2 Smithy streams. Tests here run against a fake bidirectional stream and cover the handshake, settings merge, and speculative-vs-final transcript selection — but tool round-trips, interruption, stream exceptions, history seeding, and the unsupported-input guards still need coverage, and none of it is backed by a real recording. RealtimeCassette's JSON-frame format could gain a Smithy adapter (patching invoke_model_with_bidirectional_stream, recording input send()s and replaying await_output() receivers) — sketched, not built.
  4. The bedrock: inference test can't join the shared suite yet. Because the SDK is 3.12+, unconditionally constructing a BedrockRealtimeModel in test_inference.py would break CI on 3.10/3.11. Needs a skip/guard story before it's safe in the common path.
  5. BedrockProvider reconciliation is unresolved. To avoid a second public provider class, BedrockRealtimeModel(provider=...) currently accepts a structurally-typed Smithy client and otherwise builds the default. A future shared Bedrock auth-config object could reconcile the boto3 and Smithy stacks without pretending the client types are interchangeable — but that's undesigned.

What's implemented

  • BedrockRealtimeModel + BedrockRealtimeConnection over the Smithy duplex stream: session/prompt/content handshake, 16 kHz LPCM audio in / 24 kHz out, text turns, tools + tool results, USER/ASSISTANT transcripts, usage, provider errors, and text/transcript history seeding.
  • BedrockRealtimeModelSettings following the migrated settings pattern (voice, max_tokens, temperature, top_p, and Nova 2's bedrock_endpointing_sensitivity), merged model-level + per-connect.
  • bedrock: prefix in infer_realtime_model / KnownRealtimeModelName for both amazon.nova-2-sonic-v1:0 (default) and amazon.nova-sonic-v1:0.
  • Speculative/final handling: only FINAL assistant text becomes a Transcript (speculative text describes planned, not-yet-spoken audio; forwarding it would duplicate or retain unspoken text). Automatic server-side barge-in is still supported even though explicit client interrupt() is not.
  • A dedicated realtime-bedrock optional extra, docs in docs/realtime.md + docs/api/realtime.md, and a live_bedrock_smoke.py (no test_ prefix, never runs in CI).

Review note

I reviewed the generated code line-by-line and fixed one real bug before opening this: the usage adapter forwarded usageEvent.details.total (cumulative), but the session does usage.incr() per SessionUsageEvent, so a multi-turn session would have re-added the whole running total every turn. It now forwards details.delta (the per-turn increment), with the test fixture carrying both keys to prove total is ignored.

Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • PR title is fit for the release changelog.