sdk-python
sdk-python copied to clipboard
Add parallel reading support to S3SessionManager.list_messages()
Description
This PR adds parallel reading support to S3SessionManager.list_messages() to improve performance when retrieving multiple messages from S3. The implementation uses ThreadPoolExecutor to fetch messages concurrently, significantly reducing latency for sessions with many messages.
Key Changes:
- Added
max_parallel_readsparameter toS3SessionManager.__init__()(defaults to 1 for backward compatibility) - Implemented parallel S3 reads using
ThreadPoolExecutorinlist_messages() - Support for both instance-level and per-call
max_parallel_readsconfiguration - Maintains message order regardless of completion order
- Handles individual message read failures gracefully without stopping the entire operation
- Added comprehensive test coverage including edge cases and mock-based verification
Backward Compatibility:
- Default
max_parallel_reads=1ensures sequential behavior (backward compatible) - Existing code continues to work without modification
- No breaking changes to the API
Related Issues
https://github.com/strands-agents/sdk-python/issues/1164
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
- [x] I ran
hatch run prepare
Testing Details:
- Added 9 new test cases covering:
- Default behavior (sequential reads)
- Instance-level configuration
- Per-call override functionality
- Edge cases (few messages, many messages, pagination)
- Mock-based verification of ThreadPoolExecutor configuration
- All existing tests continue to pass (1520 passed, 4 skipped)
- Verified message ordering is preserved
- Tested error handling for individual message read failures
- No new warnings introduced (existing warnings are pre-existing deprecation warnings)
Checklist
- [x] I have read the CONTRIBUTING document
- [x] I have added any necessary tests that prove my fix is effective or my feature works
- [x] I have updated the documentation accordingly
- [x] I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
- [x] My changes generate no new warnings
- [x] Any dependent changes have been merged and published
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.