Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ For detailed guidance & examples, explore our documentation:
- [Strands Harness Guide](https://strandsagents.com/docs/user-guide/harness/) ([quickstart](https://strandsagents.com/docs/user-guide/harness/quickstart/) · [configuration reference](https://strandsagents.com/docs/user-guide/harness/reference/configuration/))
- [Quick Start Guide](https://strandsagents.com/docs/user-guide/quickstart/overview/)
- [Agent Loop](https://strandsagents.com/docs/user-guide/concepts/agents/agent-loop/)
- [Bidirectional Streaming](https://strandsagents.com/docs/user-guide/sdk/bidi/) (Python)
- [Examples](https://strandsagents.com/docs/examples/)
- API Reference: [Python](https://strandsagents.com/docs/api/python/strands.agent.agent/) · [TypeScript](https://strandsagents.com/docs/api/typescript/)
- [Production & Deployment Guide](https://strandsagents.com/docs/user-guide/deploy/operating-agents-in-production/)
Expand Down
84 changes: 16 additions & 68 deletions strands-py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,96 +204,44 @@ It's also available on GitHub via [strands-agents/tools](https://github.com/stra

### Bidirectional Streaming

> **⚠️ Experimental Feature**: Bidirectional streaming is currently in experimental status. APIs may change in future releases as we refine the feature based on user feedback and evolving model capabilities.
Build voice agents that talk with users in real time. A `BidiAgent` holds a persistent connection to a speech model, streams audio both ways, runs tools mid-conversation, and stops speaking when the user interrupts.

Build real-time voice and audio conversations with persistent streaming connections. Unlike traditional request-response patterns, bidirectional streaming maintains long-running conversations where users can interrupt, provide continuous input, and receive real-time audio responses. Get started with your first BidiAgent by following the [Quickstart](https://strandsagents.com/docs/user-guide/sdk/bidi/quickstart/) guide.

**Supported Model Providers:**
- Amazon Bedrock Nova Sonic
- Google Gemini Live
- OpenAI Realtime API

**Installation:**
Install the extra for your provider. Local audio also needs the PortAudio system library:

```bash
# Server-side only (no audio I/O dependencies)
pip install strands-agents[bidi]
# Amazon Bedrock Nova Sonic (Python 3.12+)
pip install "strands-agents[bidi,bidi-io,bidi-pyaudio]"

# With all portable Bidi providers, terminal I/O, and audio processing (no local audio devices)
pip install strands-agents[bidi-all]
# Google Gemini Live
pip install "strands-agents[bidi-google,bidi-io,bidi-pyaudio]"

# For local microphone/speaker access, install PortAudio for your OS first, then:
pip install strands-agents[bidi,bidi-io,bidi-pyaudio]
# OpenAI Realtime API
pip install "strands-agents[bidi-openai,bidi-io,bidi-pyaudio]"
```

> **Note**: Bedrock Nova Sonic requires Python 3.12+ due to its experimental AWS SDK dependency.

**Quick Example:**
This agent listens on your microphone, answers through your speakers, and prints transcripts to the terminal:

```python
import asyncio

from strands.bidi.agent import BidiAgent
from strands.bidi.models import BedrockNovaSonicModel
from strands.bidi.io import AudioIO
from strands_tools import calculator, stop
from strands.bidi.models import BedrockNovaSonicModel


async def main():
# Create bidirectional agent with Nova Sonic v2
model = BedrockNovaSonicModel(model_id="amazon.nova-2-sonic-v1:0")
agent = BidiAgent(model=model, tools=[calculator, stop])

# Setup audio I/O (local audio requires the bidi-pyaudio extra)
agent = BidiAgent(model=model)
audio_io = AudioIO()

# Run with real-time audio streaming and terminal transcripts
# stop tool allows user to verbally stop agent execution
await agent.run(
inputs=[audio_io.input()],
outputs=[audio_io.output()]
)
await agent.run(inputs=[audio_io.input()], outputs=[audio_io.output()])


if __name__ == "__main__":
asyncio.run(main())
```

> **Note**: `ConsoleIO` is included with the `bidi-io` extra. `AudioIO` requires
> the `bidi-io` and `bidi-pyaudio` extras plus the PortAudio system library. For
> server-side deployments where audio I/O is handled by clients (browsers,
> mobile apps), install only `strands-agents[bidi]` and implement custom
> input/output streams using the `InputStream` and `OutputStream` protocols.

**Configuration Options:**

```python
from strands.bidi.models import BedrockNovaSonicModel

# Configure audio streams and Nova Sonic session parameters.
model = BedrockNovaSonicModel(
model_id="amazon.nova-2-sonic-v1:0",
audio={
"input": {"sample_rate": 16000},
"output": {"sample_rate": 16000},
},
voice="matthew",
params={
"turnDetectionConfiguration": {
"endpointingSensitivity": "MEDIUM"
},
"inferenceConfiguration": {
"maxTokens": 2048,
"temperature": 0.7
},
},
)

# Configure I/O devices
audio_io = AudioIO(
input_device_index=0, # Specific microphone
output_device_index=1, # Specific speaker
input_buffer_size=10,
output_buffer_size=10
)
```
`run()` keeps the conversation open until you press Ctrl+C or a tool calls `agent.cancel()`. See the [bidirectional streaming quickstart](https://strandsagents.com/docs/user-guide/sdk/bidi/quickstart/) for model configuration, custom I/O, and more.

## Documentation

Expand Down
Loading