Skip to content

Consolidating StreamingResponse definitions and tweaking streaming entities' serialization#327

Closed
rodrigobr-msft wants to merge 29 commits intomainfrom
users/robrandao/streaming-response-consolidation
Closed

Consolidating StreamingResponse definitions and tweaking streaming entities' serialization#327
rodrigobr-msft wants to merge 29 commits intomainfrom
users/robrandao/streaming-response-consolidation

Conversation

@rodrigobr-msft
Copy link
Contributor

@rodrigobr-msft rodrigobr-msft commented Feb 19, 2026

This pull request introduces and tests a new StreamInfo entity for streaming responses, refactors entity serialization to improve schema compliance, and removes some legacy citation utilities from the hosting layer. The most significant changes are the addition of the StreamInfo model for tracking streaming state in activities, improvements to entity serialization and schema handling, and comprehensive tests for streaming behavior.

Streaming response enhancements:

  • Added the new StreamInfo entity (streaminfo) for tracking streaming response state in activities, including fields like stream_type, stream_sequence, and feedback loop support. ([[1]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-95569af9f3e8e01959838120d46dcc6fe53336c3d236c5b1780959b1937121a0R1-R20), [[2]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-c7c7dbca61cbea5cc83fa60accf177b402f886ec5b5a2cf554a3371068346f81R15), [[3]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-287a37a1619db573840fbc3f6b88a90bbe84d8623523a3e7225e05e7c03a5e7eR19), [[4]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-287a37a1619db573840fbc3f6b88a90bbe84d8623523a3e7225e05e7c03a5e7eR33), [[5]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-31cb72ea23ff32a2ccb5b68267163cf524218b1630beaa35e920da3b11b69eaaR47), [[6]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-31cb72ea23ff32a2ccb5b68267163cf524218b1630beaa35e920da3b11b69eaaR159))
  • Updated the streaming response logic and tests to utilize the new StreamInfo entity, with thorough tests for both streaming and non-streaming channels. ([dev/tests/sdk/test_streaming_response.pyR1-R122](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-13cb0d27c7ad432613f8aa33b4a632d43b2da419e6d605569ae0ad85f95a2a4aR1-R122))

Entity model and serialization improvements:

  • Introduced a _SchemaMixin to standardize and improve serialization of entities using @type and @context fields, and updated several AI-related entity classes (AIEntity, ClientCitation, ClientCitationAppearance, SensitivityUsageInfo, SensitivityPattern) to use this mixin and new serialization logic. ([[1]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-14b332fb65711770caf52d2645c1184b978f93d1248e85ce56d2c75355994c1aR1-R20), [[2]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-93896609025845dd511a2896088bf071689adf37d499090c6d5e689ec332c901L5-R9), [[3]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-93896609025845dd511a2896088bf071689adf37d499090c6d5e689ec332c901L45-R75), [[4]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-93896609025845dd511a2896088bf071689adf37d499090c6d5e689ec332c901L82-R94), [[5]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-93896609025845dd511a2896088bf071689adf37d499090c6d5e689ec332c901L98-L111), [[6]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-3762756c59905ea906e8e1cd5a022698d7635e5577cd5905777ebe1dda8b831eL6-R10), [[7]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-3762756c59905ea906e8e1cd5a022698d7635e5577cd5905777ebe1dda8b831eL19-R25), [[8]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-3762756c59905ea906e8e1cd5a022698d7635e5577cd5905777ebe1dda8b831eL28-R41))
  • Updated AgentsModel and Entity configuration to improve alias and validation handling, ensuring better compatibility with Pydantic v2 and schema standards. ([[1]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-d93acfcec8f98f3d9e2be55d1bc902f9c9d566f422a3cf560a1d4991ca5deb4aL11-R13), [[2]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-3762756c59905ea906e8e1cd5a022698d7635e5577cd5905777ebe1dda8b831eL19-R25))

Cleanup and legacy code removal:

  • Removed legacy citation and citation utility modules from the hosting layer, as citation handling is now managed by the activity models and core logic. ([[1]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-1d17672ed72428ef555add002149617dcec51f209c508c3e3dc11df75575e69aL1-L14), [[2]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-ecbbe00bcc36cf94f9fadb9296cce862b026ff1599538d4f836b426511f1c5f5L1-L12), [[3]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-81c34464ad26c732f0634a267e462489d292302326934dab5eda50808fd29127L1-L22), [[4]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-853458eaad9d1976df61be3554be7bb90b31b764c912a565685fe5f233d0d013L1-L85))

Other improvements:

  • Added EntityTypes to the public API for easier referencing of entity types. ([libraries/microsoft-agents-activity/microsoft_agents/activity/__init__.pyR137](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-31cb72ea23ff32a2ccb5b68267163cf524218b1630beaa35e920da3b11b69eaaR137))
  • Fixed minor schema and type consistency issues in ProductInfo and related models. ([[1]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-8a8c46cdb0cb99d41020f6a281cc0d2abd646c08641f48bb76819f67d2cd396eL19-R19), [[2]](https://github.com/microsoft/Agents-for-python/pull/327/files#diff-80288d3976c877f3a86d972b6d61bc36674e58550349c3ead0a4d45a2ba7463eL757-L759))

These changes collectively improve the streaming response infrastructure, ensure more robust and standards-compliant serialization for activities and entities, and clean up deprecated code paths.

Copilot AI review requested due to automatic review settings February 19, 2026 19:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR consolidates duplicated streaming-response helpers (StreamingResponse, Citation, CitationUtil) by removing the framework-specific copies (FastAPI + aiohttp) and centralizing the implementation under hosting-core, with minor behavioral tweaks to the core implementation.

Changes:

  • Removed duplicate streaming/ implementations from microsoft-agents-hosting-fastapi and microsoft-agents-hosting-aiohttp.
  • Updated TurnContext.streaming_response to construct a core StreamingResponse.
  • Updated core StreamingResponse defaults/behavior (e.g., channel detection and stream-id initialization for some channels).

Reviewed changes

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

Show a summary per file
File Description
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/streaming/streaming_response.py Removed duplicate StreamingResponse implementation (consolidation).
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/streaming/citation_util.py Removed duplicate citation utilities (consolidation).
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/streaming/citation.py Removed duplicate Citation model (consolidation).
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/streaming/init.py Removed streaming re-export package (consolidation).
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/init.py Removed app package re-exports (consolidation).
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/turn_context.py Switched TurnContext streaming_response wiring to core StreamingResponse (currently broken).
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py Centralized StreamingResponse implementation and adjusted defaults/IDs (currently introduces circular import).
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/streaming/streaming_response.py Removed duplicate StreamingResponse implementation (consolidation).
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/streaming/citation_util.py Removed duplicate citation utilities (consolidation).
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/streaming/citation.py Removed duplicate Citation model (consolidation).
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/streaming/init.py Removed streaming re-export package (consolidation).
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/init.py Removed app package re-exports (consolidation).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings February 25, 2026 17:18
Copy link
Contributor

Copilot AI left a comment

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 13 out of 14 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings February 27, 2026 01:06
Copy link
Contributor

Copilot AI left a comment

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 15 out of 18 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rodrigobr-msft rodrigobr-msft marked this pull request as ready for review February 27, 2026 18:29
@rodrigobr-msft rodrigobr-msft requested a review from a team as a code owner February 27, 2026 18:29
Copilot AI review requested due to automatic review settings February 27, 2026 18:29
Copy link
Contributor

Copilot AI left a comment

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 15 out of 18 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 3, 2026 16:36
Copy link
Contributor

Copilot AI left a comment

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 17 out of 21 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rodrigobr-msft rodrigobr-msft changed the title Consolidating StreamingResponse definitions and slight fixes Consolidating StreamingResponse definitions and correcting streaming entities' serialization Mar 18, 2026
Copy link
Contributor

Copilot AI left a comment

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 27 out of 32 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copilot AI review requested due to automatic review settings March 18, 2026 22:20
Copy link
Contributor

Copilot AI left a comment

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 29 out of 34 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

rodrigobr-msft and others added 2 commits March 19, 2026 10:31
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 19, 2026 17:44
Copy link
Contributor

Copilot AI left a comment

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 29 out of 34 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (3)

libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py:761

  • AIEntity no longer inherits from Entity, and this constructor call no longer explicitly sets type. With model_dump(exclude_unset=True) (used elsewhere in the codebase), Pydantic can omit default-only fields like type, which would produce an entity missing its required top-level type (e.g., https://schema.org/Message). Mandatory: ensure type is always serialized for AIEntity—either by explicitly setting type here, or (preferably) adding an AIEntity-level serializer similar to Entity’s serialize_with_type, or making AIEntity inherit Entity again.
        if citations:
            ai_entity = AIEntity(
                id="",
                additional_type=["AIGeneratedContent"],
                citation=citations,
                usage_info=usage_info,
            )

tests/hosting_core/app/streaming/test_streaming_response.py:1

  • This assertion is no longer checking the right shape after the schema refactor: the schema.org message entity now uses at_type/@type (and/or type == \"https://schema.org/Message\"), so filtering on schema_type will always produce an empty list and can mask regressions. Mandatory: update the predicate to match the new entity representation (e.g., check entity.type == \"https://schema.org/Message\" or getattr(entity, \"at_type\", None) == \"Message\").
    tests/hosting_core/app/streaming/test_streaming_response.py:1
  • These tests rely on asyncio.sleep(...) timing to allow the internal queue to drain, which can be flaky under CI load. Optional but recommended: set response._interval = 0 and use await response.wait_for_queue() at deterministic points (as other tests already do) instead of fixed sleeps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 19, 2026 17:54
@rodrigobr-msft rodrigobr-msft changed the title Consolidating StreamingResponse definitions and correcting streaming entities' serialization Consolidating StreamingResponse definitions and tweaking streaming entities' serialization Mar 19, 2026
Copy link
Contributor

Copilot AI left a comment

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 28 out of 33 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (2)

tests/hosting_core/app/streaming/test_streaming_response.py:1

  • This assertion is likely ineffective after the serialization refactor: the schema.org entity path now uses AIEntity with at_type/@type, and schema_type is no longer present. As written, this test will pass even if a schema.org/AI entity is incorrectly included on the final activity. To actually validate the behavior, filter by entity.type == \"https://schema.org/Message\" (or getattr(entity, \"at_type\", None) == \"Message\") and assert the list is empty.
    tests/hosting_core/app/streaming/test_streaming_response.py:1
  • These tests rely on real asyncio.sleep timing to allow the queue to drain. This can make CI flaky and increases runtime (especially as more scenarios get added). Prefer making the interval deterministic in tests (e.g., set response._interval = 0) and/or use await response.wait_for_queue() to synchronize on completion instead of sleeping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 19, 2026 18:04
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

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 28 out of 33 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (3)

tests/hosting_core/app/streaming/test_streaming_response.py:1

  • This test filters on schema_type == \"Message\", but the updated schema entities use at_type/@type (and AIEntity no longer defines schema_type). As written, the filter will never match and the assertion can pass even if a schema.org Message entity is present. Update the predicate to check the new representation (e.g., entity.type == \"https://schema.org/Message\" and/or getattr(entity, \"at_type\", None) == \"Message\").
    libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py:388
  • When generated_by_ai_label is disabled, the code still appends an AIEntity. AIEntity defaults additional_type to include AIGeneratedContent, which effectively marks content as AI-generated even when the feature flag is off. If the intent here is to attach citations without enabling the AI-generated label, consider using a citation-only schema entity (or explicitly overriding additional_type to an empty list / making it optional) so the flag semantics remain consistent.
        if (
            self._citations
            and not self._ended
            and not self._enable_generated_by_ai_label
        ):
            # Filter out the citations unused in content.
            curr_citations = CitationUtil.get_used_citations(
                self._message, self._citations
            )
            if curr_citations:
                activity.entities.append(
                    AIEntity(
                        type="https://schema.org/Message",
                        id="",
                        citation=curr_citations,
                    )
                )

tests/activity/test_activity.py:1

  • Remove the extra blank line to keep test formatting consistent with the surrounding style.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants