Skip to content

Small tweaks for microsoft_agents.hosting.core.http modules - #445

Closed
Rodrigo Brandão (rodrigobr-msft) wants to merge 5 commits into
mainfrom
users/robrandao/general
Closed

Small tweaks for microsoft_agents.hosting.core.http modules#445
Rodrigo Brandão (rodrigobr-msft) wants to merge 5 commits into
mainfrom
users/robrandao/general

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

This pull request updates the ChannelServiceRoutes class in microsoft_agents/hosting/core/http/_channel_service_routes.py to improve type safety and response flexibility. The main changes ensure that handler methods and serialization/deserialization routines are more generic and can handle both single models and lists of models, supporting a wider range of API responses.

Type Safety and Serialization Improvements:

  • Introduced a generic type variable AgentsModelT to make deserialize_from_body and serialize_model methods type-safe for any subclass of AgentsModel. Now, these methods can handle both single models and lists, returning appropriately typed results. [1] [2] [3] [4]
  • Updated all route handler methods (such as send_to_conversation, reply_to_activity, etc.) to return either a single dictionary or a list of dictionaries, reflecting that handlers may return a single object or a collection. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

HTTP Response Consistency:

  • Updated the accepted() static method in HttpResponse to explicitly set content_type=None for 202 responses, ensuring consistent response formatting.

@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) marked this pull request as ready for review July 7, 2026 18:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refines the framework-agnostic HTTP layer in microsoft_agents.hosting.core.http by improving type annotations for channel service route handlers and tweaking how 202 Accepted responses are represented.

Changes:

  • Added a bounded TypeVar to make deserialize_from_body/serialize_model more type-safe for AgentsModel subclasses, and widened handler return types to allow list-shaped JSON payloads.
  • Updated HttpResponseFactory.accepted() to explicitly set content_type=None for 202 responses.
  • Adjusted multiple ChannelServiceRoutes handler method return annotations to reflect that some endpoints may return collections.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/http/_http_response.py Makes 202 Accepted responses explicitly omit a content type in the abstraction.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/http/_channel_service_routes.py Introduces a generic AgentsModelT and broadens route handler return typing to support list responses.

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

Copilot AI review requested due to automatic review settings July 7, 2026 18:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Comments suppressed due to low confidence (1)

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/http/_channel_service_routes.py:149

  • get_conversations calls self.handler.on_get_conversations(request.get_claims_identity(), None), but ChannelApiHandlerProtocol.on_get_conversations currently types conversation_id as str (and the connector client API doesn’t take a conversation_id at all). Passing None here is inconsistent with the protocol and can break handler implementations that expect a string. Consider reconciling the protocol and this route (e.g., make the parameter an Optional continuation_token, or remove/rename it) so the call site is type-correct and unambiguous.
    ) -> dict | list[dict]:
        """Handle GET /."""
        # TODO: continuation token? conversation_id?
        result = await self.handler.on_get_conversations(
            request.get_claims_identity(), None

Copilot AI review requested due to automatic review settings July 8, 2026 19:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Comment on lines +189 to 197
async def delete_conversation_member(self, request: HttpRequestProtocol) -> None:
"""Handle DELETE /v3/conversations/{conversation_id}/members/{member_id}."""
conversation_id = request.get_path_param("conversation_id")
member_id = request.get_path_param("member_id")
result = await self.handler.on_delete_conversation_member(
await self.handler.on_delete_conversation_member(
request.get_claims_identity(),
conversation_id,
member_id,
)
Comment on lines 39 to 49
@@ -47,7 +49,9 @@ async def deserialize_from_body(
return target_model.model_validate(body)
auto-merge was automatically disabled July 8, 2026 19:30

Pull request was closed

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