fix(models): Add non-streaming support to OpenAIModel
Description
This pull request adds support for non-streaming responses to the OpenAIModel. Users can now set streaming=False during model initialization to receive a single, complete response object instead of an event stream.Key Changes
src/strands/models/openai.py:
-
Added optional streaming: Optional[bool] config key.
-
format_request now respects streaming (defaults to True to preserve existing behavior).
-
Stream method supports both streaming and non-streaming flows (converts non-streaming provider response into streaming-style events).
-
Small helper _convert_non_streaming_to_streaming added to normalize non-streaming responses into the same event format.
src/strands/models/litellm.py:
- Updated to include a streaming option in its config and to preserve compatibility with OpenAIModel.
tests/strands/models/test_openai.py:
- Updated/added tests to cover non-streaming behavior.
Related Issues
Closes #778Documentation PR
N/AType of Change
Bug fix
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
- [ ] I ran
hatch run prepare - [x] I ran hatch fmt --formatter locally.
- [x] I ran hatch fmt --linter and pre-commit run --all-files.
- [x] I ran unit tests locally:
- tests/strands/models/test_openai.py::test_stream → Passed
- tests/strands/models/test_openai.py::test_stream_respects_streaming_flag → Passed
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
- [ ] I have updated the documentation accordingly
- [ ] 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.