generated from amazon-archives/__template_Apache-2.0
- Notifications
You must be signed in to change notification settings - Fork 507
Bidirectional Streaming Agent #1276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mehtarac wants to merge 330 commits into strands-agents:main Choose a base branch from mehtarac:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Co-authored-by: Nick Clegg <nac542@gmail.com>
- Remove adapter from constructor - Implement BidirectionlIO interface - Add adapter the run() method
feat: (Agent): Finalize Bidirectional Agent class
…s unit tests and integ tests
Move test scripts into dedicated directory so tests directory only has unit tests and integ tests
Rename bidirectional components
Fix main branch. Temporarily rename loop to original name
Changes: - Keep main's architecture: BidirectionalConnection + start/stop functions - Apply our event renames: BidiTextInputEvent, BidiAudioInputEvent, etc. - Update agent to use BidiAgent, BidiModel, BidiNovaSonicModel - Update tests to use new class names - Fix imports across codebase Tests status: - ✅ 14/14 type tests passing -⚠️ Integration tests running but failing (models need update to check 'type' field instead of isinstance) Known issue: Models use isinstance() checks which don't work with TypedDict. Need to update models to check content.get('type') field instead.
The agent's send() method was passing plain dicts directly to models, but models expect TypedEvent instances for isinstance() checks to work. Added dict-to-TypedEvent conversion logic that was lost in merge: - Checks event 'type' field in dict - Reconstructs appropriate TypedEvent (BidiTextInputEvent, BidiAudioInputEvent, etc.) - Maintains backward compatibility with WebSocket/dict-based clients Tests: - ✅ 14/14 type tests passing - ✅ 2/2 integration tests passing (nova_sonic, openai)
Updated test imports and usages: - GeminiLiveModel → BidiGeminiLiveModel - NovaSonicModel → BidiNovaSonicModel - OpenAIRealtimeModel → BidiOpenAIRealtimeModel Note: 21 model tests still failing because they call .connect() but models now use .start(). This is a pre-existing issue that needs separate fix - tests need API update.
Updated all test calls from old API to new API: - .connect() → .start() - .close() → .stop() - Updated error message expectations to match actual errors All tests now passing: - ✅ 47/47 bidirectional streaming tests passing - ✅ 14/14 type tests - ✅ 33/33 model tests - ✅ 2/2 integration tests
rename modules
remove scripts directory before merging with sdk-python/main
add bidi to README
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
fix minor linting and integ test failure errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces bidirectional streaming capabilities to Strands SDK, enabling real-time voice and audio conversations with AI models through persistent streaming connections.
Overview
Bidirectional streaming moves beyond traditional request-response patterns by maintaining long-running conversations where users can interrupt, provide continuous input, and receive real-time audio responses. This implementation is marked as experimental as we refine the API based on user feedback and evolving model capabilities.
Key Features:
Implementation Details
Core Components:
BidiAgent- Main agent class with start(), send(), receive(), stop() lifecycle methods_BidiAgentLoop- Event processing engine handling model events and tool execution with connection restart logicBidiModel- Model interface for bidirectional model providersBidiInput/BidiOutput- Pluggable I/O channel abstractionsModel Providers:
BidiNovaSonicModel- AWS Bedrock Nova Sonic with complex event sequencingBidiGeminiLiveModel- Google Gemini Live using official SDKBidiOpenAIRealtimeModel- OpenAI Realtime API via WebSocketI/O Handlers:
BidiAudioIO- PyAudio-based microphone/speaker handling with bufferingBidiTextIO- Terminal-based text input/outputUsage Example
This is a new experimental feature under
strands.experimental.bidi.Related Issues
#217
Documentation PR
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run preparehatch run bidi:prepare: This is done to isolate the bidirectional streaming environment which needs Python 3.12+Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.