refactor(io): Refactor BidiIO to BidiInput and BidiOutput #34
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.
Callable IO Refactoring
Overview
Refactored the bidirectional streaming IO system from a protocol-based approach to a callable-based approach, enabling truly non-blocking, concurrent input/output handling with proper backpressure management.
What Changed
Before: Protocol-Based IO
After: Callable-Based IO
Key Benefits
1. True Non-Blocking Operation
2. Automatic Backpressure Handling
3. Better Error Isolation
4. Cleaner API
inputsandoutputsparametersArchitecture
Example Usage
Basic Audio IO
Multiple Inputs and Outputs
Custom IO Implementation
Implementation Details
Input Handling
input_readertaskOutput Handling
output_writertaskBackpressure
put_nowait()to avoid blockingasyncio.QueueFullexception = drop event + log warningShutdown
CancelledErrorhandled gracefullyTesting
Unit tests cover:
Run tests:
hatch test tests/strands/experimental/bidirectional_streaming/agent/test_agent.pyMigration Guide
Old Code
New Code
Performance Characteristics