Skip to content

Add add_attachment and reset to StreamingResponse - #426

Merged
MattB (MattB-msft) merged 6 commits into
mainfrom
copilot/add-addattachment-to-streamingresponse
Jul 7, 2026
Merged

Add add_attachment and reset to StreamingResponse#426
MattB (MattB-msft) merged 6 commits into
mainfrom
copilot/add-addattachment-to-streamingresponse

Conversation

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

StreamingResponse only supported bulk-replacing attachments via set_attachments(). This adds an incremental add_attachment() method and a reset() method, matching the C# SDK (Agents-for-net#878).

Changes

StreamingResponse (streaming_response.py)

  • add_attachment(attachment) — appends a single Attachment to the final message; raises ValueError on None; lazy-initializes the list; composable with set_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__ and reset() to keep them in sync

Tests (test_streaming_response.py)

Four new tests: attachment included in final activity, ValueError on None, attachments cleared after reset(), multiple calls accumulate correctly.

Usage

card = Attachment(
    content_type="application/vnd.microsoft.card.adaptive",
    content=my_adaptive_card_payload,
)
context.streaming_response.add_attachment(card)
context.streaming_response.queue_text_chunk("Here is the information you requested:")
await context.streaming_response.end_stream()

Copilot AI requested review from Copilot and removed request for Copilot June 18, 2026 21:52
Copilot AI changed the title [WIP] Add add_attachment method to StreamingResponse class Add add_attachment and reset to StreamingResponse Jun 18, 2026
Copilot AI requested a review from MattB (MattB-msft) June 18, 2026 21:52
@MattB-msft
MattB (MattB-msft) marked this pull request as ready for review June 18, 2026 23:14
@MattB-msft
MattB (MattB-msft) requested a review from a team as a code owner June 18, 2026 23:15
Copilot AI review requested due to automatic review settings June 18, 2026 23:15
@MattB-msft
MattB (MattB-msft) enabled auto-merge (squash) June 18, 2026 23:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 single Attachment to 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 AI review requested due to automatic review settings June 25, 2026 23:52
@MattB-msft MattB (MattB-msft) linked an issue Jun 25, 2026 that may be closed by this pull request
@MattB-msft

Copy link
Copy Markdown
Member

Copilot Please run python black on the changes you have made

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Copilot Please run python black on the changes you have made

Done — ran black on streaming_response.py in commit Apply Black formatting and fix _initialize_state to include _is_streaming_channel and _interval. This also fixed the missing blank line after reset() that the reviewer flagged, and I moved _is_streaming_channel and _interval into _initialize_state() so reset() fully restores those fields to baseline defaults before _set_defaults() re-applies channel-specific values.

Copilot AI review requested due to automatic review settings June 27, 2026 00:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@MattB-msft
MattB (MattB-msft) merged commit 30fbac7 into main Jul 7, 2026
11 checks passed
@MattB-msft
MattB (MattB-msft) deleted the copilot/add-addattachment-to-streamingresponse branch July 7, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "AddAttachment" to StreamingResponse Class

4 participants