

# Bidirectional streaming
<a name="runtime-bidirectional-streaming"></a>

Amazon Bedrock AgentCore Runtime supports bidirectional streaming, enabling real-time, two-way communication between clients and agents. This is essential for interactive applications such as conversational voice agents where both the client and agent need to send and receive data simultaneously.

AgentCore Runtime supports two protocols for bidirectional streaming:

WebSocket  
A persistent, full-duplex connection over TCP. WebSocket supports text-based streaming, structured message exchange, and audio streaming with no additional infrastructure required. Clients connect to the AgentCore Runtime WebSocket endpoint using SigV4 or OAuth 2.0 authentication.

WebRTC  
A protocol optimized for real-time audio and video with low latency. WebRTC is well-suited for voice agents in browser and mobile applications, using UDP-based transport for real-time media delivery.

**Topics**
+ [

# Bidirectional streaming with WebSocket
](runtime-bidirectional-streaming-websocket.md)
+ [

# Bidirectional streaming with WebRTC
](runtime-webrtc.md)
+ [

# Code examples
](runtime-bidirectional-streaming-examples.md)

# Bidirectional streaming with WebSocket
<a name="runtime-bidirectional-streaming-websocket"></a>

To get started with WebSocket streaming, see [Get started with bidirectional streaming using WebSocket](runtime-get-started-websocket.md).

# Bidirectional streaming with WebRTC
<a name="runtime-webrtc"></a>

With Amazon Bedrock AgentCore Runtime, you can use WebRTC (Web Real-Time Communication) to enable real-time media streaming between clients and agents. WebRTC is useful when building voice agents for browser and mobile applications, where clients use the browser-native WebRTC API or mobile WebRTC SDKs for real-time media. For more information about WebRTC, see [WebRTC API](https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API) in the MDN Web Docs.

**Topics**
+ [

## Using WebRTC on AgentCore Runtime
](#runtime-webrtc-requirements)
+ [

## TURN streaming options
](#runtime-webrtc-turn-options)
+ [

# Tutorial: WebRTC with TURN relaying using Amazon Kinesis Video Streams
](runtime-webrtc-get-started-kvs.md)

## Using WebRTC on AgentCore Runtime
<a name="runtime-webrtc-requirements"></a>

WebRTC on AgentCore Runtime requires:
+  **VPC network mode** – Your AgentCore Runtime must be configured with VPC network mode. For more information, see [Configure Amazon Bedrock AgentCore Runtime and tools for VPC](agentcore-vpc.md).
+  **TURN relay** – TURN relay is required for media traffic between the client and the agent. The VPC must support outbound UDP traffic to your TURN endpoints.

## TURN streaming options
<a name="runtime-webrtc-turn-options"></a>

The following TURN server options are available for WebRTC on AgentCore Runtime:

Amazon Kinesis Video Streams managed TURN Relay  
KVS provides managed TURN servers through the `GetIceServerConfig` API. This option requires no TURN infrastructure management and integrates natively with AWS IAM for authentication. A KVS signaling channel resource is required to obtain TURN credentials. For WebRTC signaling itself (exchanging ICE candidates and session descriptions), you can use either the AgentCore Runtime invoke API or the KVS signaling channel. To get started, see [Tutorial: WebRTC with TURN relaying using Amazon Kinesis Video Streams](runtime-webrtc-get-started-kvs.md).

Third-party managed TURN  
You can use a third-party managed TURN provider.

Self-hosted TURN  
You can host and operate your own TURN infrastructure using open-source software such as coturn on Amazon EC2 or Amazon ECS.

# Tutorial: WebRTC with TURN relaying using Amazon Kinesis Video Streams
<a name="runtime-webrtc-get-started-kvs"></a>

In this tutorial, you build a WebRTC voice connection between a browser client and an agent running on AgentCore Runtime, using Amazon Kinesis Video Streams (KVS) managed TURN for media relaying. The agent processes audio in real-time using an Amazon Bedrock foundation model for speech-to-speech conversation.

When complete, you will have a working WebRTC connection where audio streams bidirectionally between the browser and your agent.

This tutorial requires a VPC with internet egress for connectivity to KVS TURN endpoints. For more information, see [Internet access considerations](agentcore-vpc.md#agentcore-internet-access) . All other prerequisites are handled by the sample application. The sample uses the AgentCore CLI for deployment to AgentCore Runtime.

For the complete sample application, see [WebRTC Voice Agent with KVS TURN](https://github.com/awslabs/amazon-bedrock-agentcore-samples/tree/main/01-tutorials/01-AgentCore-runtime/06-bi-directional-streaming-webrtc) on GitHub.

## Architecture
<a name="runtime-webrtc-kvs-architecture"></a>

![\[Architecture diagram showing WebRTC on AgentCore Runtime with KVS TURN relaying through a VPC.\]](http://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/images/runtime-webrtc-architecture.png)


Browser client  
A web page that captures microphone audio using the browser WebRTC API and plays the agent’s audio response.

AgentCore Runtime  
Hosts the agent and attaches to the user’s VPC via an elastic network interface (ENI) in a private subnet.

Agent  
A Python application deployed to AgentCore Runtime that handles WebRTC signaling and TURN credential management through the `/invocations` endpoint, and streams audio between the client and a foundation model.

User VPC with internet egress  
Provides network connectivity from the agent to the KVS TURN relay server. Traffic routes from the ENI in the private subnet through a NAT gateway and internet gateway to reach the TURN endpoints.

KVS TURN relay server  
Relays media traffic between the browser client and the agent. The agent obtains temporary TURN credentials from KVS using the [GetIceServerConfig](https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/API_signaling_GetIceServerConfig.html) API.

## How it works
<a name="runtime-webrtc-kvs-how-it-works"></a>

1. The client invokes the agent to fetch KVS TURN credentials and ICE server configuration.

1. The client creates a WebRTC offer and sends it to the agent. The agent creates a peer connection configured with KVS TURN servers and returns an answer.

1. The client and agent exchange ICE candidates to establish connectivity through the TURN server.

1. Once connected, the client streams microphone audio to the agent over WebRTC. The agent forwards the audio to an Amazon Bedrock foundation model and streams the model’s spoken response back to the client.

# Code examples
<a name="runtime-bidirectional-streaming-examples"></a>

The following sample applications demonstrate bidirectional streaming on Amazon Bedrock AgentCore Runtime.

## WebSocket examples
<a name="runtime-streaming-examples-websocket"></a>

Bidirectional WebSocket samples (Sonic, Strands, Echo)  
Three WebSocket examples for AgentCore Runtime: a native Amazon Nova Sonic implementation with direct event handling and a web client, a Strands Agents SDK voice agent using the Strands WebSocket transport, and a minimal echo server for testing bidirectional streaming. See [Bidirectional WebSocket samples](https://github.com/awslabs/amazon-bedrock-agentcore-samples/tree/main/01-tutorials/01-AgentCore-runtime/06-bi-directional-streaming) on GitHub.

Pipecat voice agent with WebSocket  
Deploys a Pipecat voice agent to AgentCore Runtime using WebSocket for bidirectional audio streaming. The pipeline orchestrates Deepgram (speech-to-text), Amazon Nova (LLM), and Cartesia (text-to-speech). See [Pipecat on AgentCore with WebSocket](https://github.com/pipecat-ai/pipecat-examples/tree/main/deployment/aws-agentcore-websocket) on GitHub.

Serverless telephony with Vonage and Amazon Nova Sonic  
A serverless contact center agent that handles phone calls through the Vonage Voice API, processing audio in real-time with Amazon Nova Sonic over AgentCore Runtime WebSocket connections. Uses a Lambda function to generate presigned WebSocket URLs for Vonage. See [Serverless telephony with Sonic and AgentCore Runtime](https://github.com/aws-samples/sample-vonage-serverless-sonic) on GitHub.

## WebRTC examples
<a name="runtime-streaming-examples-webrtc"></a>

WebRTC voice agent with KVS TURN  
A minimal WebRTC voice agent using Amazon Kinesis Video Streams for TURN relaying and an Amazon Bedrock foundation model for speech-to-speech conversation. See [WebRTC voice agent with KVS TURN](https://github.com/awslabs/amazon-bedrock-agentcore-samples/tree/main/01-tutorials/01-AgentCore-runtime/06-bi-directional-streaming-webrtc) on GitHub.

Pipecat voice agent with WebRTC  
Deploys a Pipecat voice agent to AgentCore Runtime using SmallWebRTC as a lightweight WebRTC transport. The pipeline orchestrates Deepgram (speech-to-text), Amazon Nova (LLM), and Cartesia (text-to-speech). See [Pipecat on AgentCore with WebRTC](https://github.com/pipecat-ai/pipecat-examples/tree/main/deployment/aws-agentcore-webrtc) on GitHub.

Pipecat voice agent with Daily  
Deploys a Pipecat voice agent to AgentCore Runtime using Daily as the WebRTC transport. Users join by visiting a Daily room URL in their browser. The pipeline orchestrates Deepgram (speech-to-text), Amazon Nova (LLM), and Cartesia (text-to-speech). See [Pipecat on AgentCore with Daily](https://github.com/pipecat-ai/pipecat-examples/tree/main/deployment/aws-agentcore-daily) on GitHub.

LiveKit voice agent on AgentCore Runtime  
Deploys a LiveKit voice agent to AgentCore Runtime with KVS managed TURN or third-party TURN for WebRTC NAT traversal. See [LiveKit on AgentCore Runtime](https://github.com/livekit-examples/agent-deployment/tree/main/bedrock-agentcore) on GitHub.