Consolidating StreamingResponse definitions and tweaking streaming entities' serialization#327
Consolidating StreamingResponse definitions and tweaking streaming entities' serialization#327rodrigobr-msft wants to merge 29 commits intomainfrom
Conversation
There was a problem hiding this comment.
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 frommicrosoft-agents-hosting-fastapiandmicrosoft-agents-hosting-aiohttp. - Updated
TurnContext.streaming_responseto construct a coreStreamingResponse. - Updated core
StreamingResponsedefaults/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.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/turn_context.py
Show resolved
Hide resolved
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/turn_context.py
Outdated
Show resolved
Hide resolved
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/turn_context.py
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Show resolved
Hide resolved
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Outdated
Show resolved
Hide resolved
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Outdated
Show resolved
Hide resolved
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/_schema_mixin.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/ai_entity.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/ai_entity.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/ai_entity.py
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/ai_entity.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/ai_entity.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/ai_entity.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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. Withmodel_dump(exclude_unset=True)(used elsewhere in the codebase), Pydantic can omit default-only fields liketype, which would produce an entity missing its required top-leveltype(e.g.,https://schema.org/Message). Mandatory: ensuretypeis always serialized for AIEntity—either by explicitly settingtypehere, or (preferably) adding an AIEntity-level serializer similar to Entity’sserialize_with_type, or making AIEntity inheritEntityagain.
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/ortype == \"https://schema.org/Message\"), so filtering onschema_typewill always produce an empty list and can mask regressions. Mandatory: update the predicate to match the new entity representation (e.g., checkentity.type == \"https://schema.org/Message\"orgetattr(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: setresponse._interval = 0and useawait 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.
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/stream_info.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…tps://github.com/microsoft/Agents-for-python into users/robrandao/streaming-response-consolidation
There was a problem hiding this comment.
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
AIEntitywithat_type/@type, andschema_typeis 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 byentity.type == \"https://schema.org/Message\"(orgetattr(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.sleeptiming 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., setresponse._interval = 0) and/or useawait 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.
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/ai_entity.py
Outdated
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/ai_entity.py
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/entity.py
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/entity.py
Show resolved
Hide resolved
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/entity.py
Show resolved
Hide resolved
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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 useat_type/@type(andAIEntityno longer definesschema_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/orgetattr(entity, \"at_type\", None) == \"Message\").
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py:388 - When
generated_by_ai_labelis disabled, the code still appends anAIEntity.AIEntitydefaultsadditional_typeto includeAIGeneratedContent, 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 overridingadditional_typeto 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.
This pull request introduces and tests a new
StreamInfoentity 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 theStreamInfomodel for tracking streaming state in activities, improvements to entity serialization and schema handling, and comprehensive tests for streaming behavior.Streaming response enhancements:
StreamInfoentity (streaminfo) for tracking streaming response state in activities, including fields likestream_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))StreamInfoentity, 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:
_SchemaMixinto standardize and improve serialization of entities using@typeand@contextfields, 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))AgentsModelandEntityconfiguration 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:
[[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:
EntityTypesto 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))ProductInfoand 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.