Skip to content

Improving streaming entity serialization#339

Merged
rodrigobr-msft merged 32 commits intomainfrom
users/robrandao/streaming-entities
Mar 23, 2026
Merged

Improving streaming entity serialization#339
rodrigobr-msft merged 32 commits intomainfrom
users/robrandao/streaming-entities

Conversation

@rodrigobr-msft
Copy link
Contributor

This pull request introduces a new StreamInfo entity to the activity model, enhances schema-based serialization and validation for entities (especially those with @type, @context, and @id fields), and adds comprehensive tests for streaming responses. It also removes unused citation-related code from the aiohttp hosting package. The changes improve standards compliance, robustness, and test coverage for streaming activities.

Entity and Serialization Improvements

  • Added a new StreamInfo entity (streaminfo) to represent streaming metadata, with fields for stream type, sequence, and feedback loop. Updated all relevant imports and exports to include StreamInfo. [1] [2] [3] [4] [5] [6]
  • Introduced a _SchemaMixin and related helpers to support proper serialization and validation of @type, @context, and @id properties in entities, ensuring compliance with schema.org and similar standards. Applied this mixin to relevant AI and citation-related entities. [1] [2] [3]
  • Refactored the core Entity class to use new serialization/validation logic, handle both camelCase and snake_case keys, and always include the type field in output. [1] [2] [3]
  • Updated ProductInfo and other entities to use .value from EntityTypes enum for type consistency.

Testing Enhancements

  • Added a new async test suite for streaming responses (test_streaming_response.py), covering both streaming and non-streaming channels, and validating correct activity sequencing and content.

Code Cleanup

  • Removed unused citation-related classes and exports (Citation, CitationUtil, StreamingResponse) from the aiohttp hosting package, as these are now handled differently. [1] [2] [3]

Configuration and Minor Fixes

  • Updated AgentsModel config to enable both alias and name-based validation for improved compatibility.
  • Added EntityTypes to the public API.
  • Minor fix to add_ai_metadata to remove unused schema fields.

rodrigobr-msft and others added 30 commits February 19, 2026 11:31
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>
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 streaming-response support into hosting-core, introduces a dedicated StreamInfo entity, and enhances entity serialization/validation for schema-style fields (@type, @context, @id) with added tests and cleanup of redundant hosting-package implementations.

Changes:

  • Add StreamInfo (streaminfo) to the activity entity model and update streaming responses to emit it.
  • Introduce _SchemaMixin helpers and refactor Entity/AI-related entities for schema-oriented serialization/validation.
  • Add/expand streaming and serialization tests; remove duplicated streaming/citation implementations from aiohttp/fastapi hosting packages.

Reviewed changes

Copilot reviewed 29 out of 34 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/hosting_core/app/streaming/test_streaming_response.py New unit tests covering streaming/non-streaming behavior, sequencing, cancellations, and metadata entities
tests/hosting_core/app/streaming/init.py Test package init (context only)
tests/activity/test_activity.py Minor formatting change in tests
tests/activity/pydantic/test_activity_io.py Remove unused imports in activity IO tests
tests/activity/entity/test_serialization.py New tests for schema-field serialization on entities
tests/activity/entity/init.py Test package init (context only)
test_samples/app_style/empty_agent.py New sample agent app scaffold
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/streaming/streaming_response.py Removed fastapi-local streaming implementation (now provided by hosting-core)
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/streaming/citation_util.py Removed fastapi-local citation utility (now provided by hosting-core)
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/streaming/citation.py Removed fastapi-local citation model (now provided by hosting-core)
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/streaming/init.py Removed fastapi streaming exports
libraries/microsoft-agents-hosting-fastapi/microsoft_agents/hosting/fastapi/app/init.py Removed fastapi app-level re-exports for streaming utilities
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/turn_context.py TurnContext.streaming_response now uses hosting-core streaming implementation
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py Minor serialization call ordering adjustment
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py Updated streaming response logic to use StreamInfo and improved metadata handling
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/streaming/streaming_response.py Removed aiohttp-local streaming implementation (now provided by hosting-core)
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/streaming/citation_util.py Removed aiohttp-local citation utility (now provided by hosting-core)
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/streaming/citation.py Removed aiohttp-local citation model (now provided by hosting-core)
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/streaming/init.py Removed aiohttp streaming exports
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/app/init.py Removed aiohttp app-level re-exports for streaming utilities
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/stream_info.py New StreamInfo entity model
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/product_info.py Align type with EntityTypes.*.value
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/entity_types.py Add STREAM_INFO to entity types
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/entity.py Refactor entity validation/serialization to support schema fields and aliases
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/ai_entity.py Apply schema mixin to AI/citation entities and adjust defaults
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/_schema_mixin.py New helpers/mixin for @type/@context/@id handling
libraries/microsoft-agents-activity/microsoft_agents/activity/entity/init.py Export StreamInfo from entity package
libraries/microsoft-agents-activity/microsoft_agents/activity/agents_model.py Update model config to validate by name and alias
libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py Simplify AI metadata entity construction (relies on schema mixin/defaults)
libraries/microsoft-agents-activity/microsoft_agents/activity/init.py Export StreamInfo and EntityTypes from the public API
dev/tests/sdk/test_streaming_response.py New SDK-level agent test scenario for streaming responses
dev/microsoft-agents-testing/microsoft_agents/testing/utils.py Minor formatting-only change
dev/microsoft-agents-testing/microsoft_agents/testing/core/utils.py Minor formatting-only change
dev/microsoft-agents-testing/microsoft_agents/testing/core/fluent/activity.py Removed unused/commented-out fluent activity utilities
Comments suppressed due to low confidence (2)

tests/activity/entity/test_serialization.py:60

  • Similar to the earlier test: when by_alias=True, at_context may serialize as "atContext" (not "at_context"). Consider asserting that "atContext" is not present in the dumped data to ensure only "@context" is emitted.
    data = ai_entity.model_dump(exclude_unset=True, by_alias=True)

    assert data["@type"] == "Message"
    assert data["@context"] == "https://schema.org"

    assert "at_type" not in data
    assert "at_context" not in data

dev/tests/sdk/test_streaming_response.py:31

  • This helper converts a dict streaminfo entity to the generic Entity model. Since the PR introduces a dedicated StreamInfo entity model, consider validating into StreamInfo instead so the test asserts the streaming schema more strictly (and avoids silently accepting missing/extra fields).
def get_streaminfo(activity: Activity) -> Entity:
    for entity in activity.entities:
        if isinstance(entity, dict) and entity.get("type") == "streaminfo":
            return Entity.model_validate(entity)
        elif isinstance(entity, Entity) and entity.type == "streaminfo":
            return entity
    raise ValueError("No streaminfo entity found")

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

@rodrigobr-msft rodrigobr-msft merged commit c7cb62f into main Mar 23, 2026
10 checks passed
@rodrigobr-msft rodrigobr-msft deleted the users/robrandao/streaming-entities branch March 23, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants