Add add_attachment and reset to StreamingResponse - #426
Conversation
add_attachment and reset to StreamingResponse
There was a problem hiding this comment.
Pull request overview
Adds incremental attachment support and a reusable reset mechanism to StreamingResponse, aligning the Python SDK’s streaming API with the .NET/C# SDK behavior for attachments and stream lifecycle reuse.
Changes:
- Introduces
StreamingResponse.add_attachment()to append a singleAttachmentto the final streamed activity. - Introduces
StreamingResponse.reset()and extracts_initialize_state()to share initialization/reset logic. - Adds tests validating attachment inclusion, accumulation, validation, and reset behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py |
Adds add_attachment() and reset(); refactors state initialization into _initialize_state() to support reuse. |
tests/hosting_core/app/streaming/test_streaming_response.py |
Adds new unit tests covering attachment behavior and reset semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Copilot Please run python black on the changes you have made |
…ming_channel and _interval
Done — ran |
StreamingResponseonly supported bulk-replacing attachments viaset_attachments(). This adds an incrementaladd_attachment()method and areset()method, matching the C# SDK (Agents-for-net#878).Changes
StreamingResponse(streaming_response.py)add_attachment(attachment)— appends a singleAttachmentto the final message; raisesValueErroronNone; lazy-initializes the list; composable withset_attachments()reset()— waits for the queue to drain, then restores all state to initial values (including clearing_attachments)_initialize_state()— private helper extracted to hold all default field assignments; called by both__init__andreset()to keep them in syncTests (
test_streaming_response.py)Four new tests: attachment included in final activity,
ValueErroronNone, attachments cleared afterreset(), multiple calls accumulate correctly.Usage