ChannelServiceRoutes improved treatment of handler results#462
Open
rodrigobr-msft wants to merge 9 commits into
Open
ChannelServiceRoutes improved treatment of handler results#462rodrigobr-msft wants to merge 9 commits into
ChannelServiceRoutes improved treatment of handler results#462rodrigobr-msft wants to merge 9 commits into
Conversation
ChannelServiceRoutes improved processing of handler resultsChannelServiceRoutes improved treatment of handler results
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines the hosting HTTP channel service pipeline by making handler result serialization more type-safe and aligning route handler return shapes with what the HTTP layers can reliably serialize, while also tightening adapter initialization requirements.
Changes:
- Added generic/overloaded serialization + generic deserialization to improve type safety in
ChannelServiceRoutes. - Adjusted member endpoints to return
list[dict]and delete endpoints to return empty payloads where appropriate. - Hardened
HttpAdapterBaseinitialization and tweakedHttpResponseFactory.accepted()to avoid content-type issues on empty responses.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/http/_http_response.py | Adjusts 202 Accepted response metadata for empty responses. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/http/_http_adapter_base.py | Makes adapter initialization stricter by requiring a client factory or connection manager. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/http/_channel_service_routes.py | Improves typing/serialization and updates endpoint handler return shapes. |
| libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/channel_service_route_table.py | Updates aiohttp JSON response helper typing to support list payloads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was
linked to
issues
Jul 13, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ub.com/microsoft/Agents-for-python into users/robrandao/channel-service-routes
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
95
to
+99
| from microsoft_agents.hosting.fastapi import start_agent_process, CloudAdapter | ||
| from microsoft_agents.hosting.core.app import AgentApplication | ||
|
|
||
| app = FastAPI() | ||
| adapter = CloudAdapter() | ||
| connection_manager = MsalConnectionManager(**agents_sdk_config) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements and type-safety enhancements to the channel service HTTP route handling, especially around serialization, deserialization, and response typing. The changes ensure better type consistency, clearer error handling, and improved compatibility with different model types.
Type and Serialization Improvements:
AgentsModelTto theChannelServiceRoutesclass and updated thedeserialize_from_bodyandserialize_modelmethods to use this generic type, allowing for more precise type checking and flexibility when working with different agent models. Overloads were added toserialize_modelfor single models and lists of models. [1] [2] [3] [4]Response Typing and Consistency:
get_activity_membersandget_conversation_membersmethods to returnlist[dict]instead ofdict, reflecting the actual data returned and improving type safety. [1] [2]json_responsehelper in the aiohttp integration to accept bothdictandlist[dict], ensuring compatibility with updated route handler return types.Error Handling and Robustness:
delete_conversation_memberto return an empty dictionary if no result is found, preventing serialization errors and ensuring consistent response shapes.HttpAdapterBaseto require either achannel_service_client_factoryor aconnection_manager, raising a clear error if neither is provided. This ensures proper configuration and prevents runtime issues.Minor Response Fix:
content_type=Nonein theaccepted()static method ofHttpResponseto clarify the response type for 202 responses.