Skip to content

Consolidating StreamingResponse definitions and slight fixes#327

Draft
rodrigobr-msft wants to merge 3 commits intomainfrom
users/robrandao/streaming-response-consolidation
Draft

Consolidating StreamingResponse definitions and slight fixes#327
rodrigobr-msft wants to merge 3 commits intomainfrom
users/robrandao/streaming-response-consolidation

Conversation

@rodrigobr-msft
Copy link
Contributor

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

This pull request refactors the streaming response logic to improve channel handling and error reporting, and ensures that citation utilities are only used from the core library going forward.

Citation code removal and consolidation:

  • Removed citation-related modules (citation.py, citation_util.py, and streaming_response.py) and their exports from aiohttp and fastapi hosting libraries, including their __init__.py files. All citation handling is now centralized in the core library. [1] [2] [3] [4]

Streaming response refactor and improvements:

  • Refactored StreamingResponse in the core library to improve channel detection, set streaming defaults based on channel, and generate stream IDs for webchat and direct line channels. [1] [2]
  • Improved error handling and reporting in streaming methods by raising errors with resource strings and logging exception types instead of full messages. [1] [2] [3] [4]
  • Updated citation filtering in streaming responses to only filter when citations are present and the stream hasn't ended.
  • Changed queue and activity handling to support None values and improved chunk queuing logic. [1] [2] [3]

Core library integration:

  • Updated TurnContext to import StreamingResponse from the core library instead of the hosting libraries, ensuring citation utilities are only used from the core.

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.

Comment on lines 331 to 337
self._cancelled = True
else:
logger.error(
f"Error occurred when sending activity while streaming: {err}"
f"Error occurred when sending activity while streaming: {type(err).__name__}"
)
raise
finally:
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The comparison on line 328 self._context.activity.channel_id == Channels.ms_teams should be changed to compare the channel property instead: self._context.activity.channel_id.channel == Channels.ms_teams (assuming channel_id is not None). This is inconsistent with the pattern used in _set_defaults (lines 234-238) where the channel property is extracted first. While the current comparison may work because ChannelId inherits from str, it's comparing the full channel ID string rather than just the channel part, which could lead to false negatives if a sub-channel is present.

Copilot uses AI. Check for mistakes.
import uuid
import asyncio
import logging
from typing import List, Optional, Callable, Literal, TYPE_CHECKING
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The TYPE_CHECKING import on line 7 is imported but never used. The TurnContext type is only used in string form as a forward reference ("TurnContext" on lines 40 and 232), which doesn't require the TYPE_CHECKING guard. Either remove the unused import or add a proper TYPE_CHECKING guard block if you want to import TurnContext for type checking purposes.

Suggested change
from typing import List, Optional, Callable, Literal, TYPE_CHECKING
from typing import List, Optional, Callable, Literal

Copilot uses AI. Check for mistakes.
import asyncio
import logging
from typing import List, Optional, Callable, Literal, TYPE_CHECKING
from dataclasses import dataclass
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The dataclass import on line 8 is imported but never used in this file. Consider removing this unused import.

Suggested change
from dataclasses import dataclass

Copilot uses AI. Check for mistakes.
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.

2 participants