Skip to content

Fix ChannelServiceAdapter.create_conversation implementation#233

Merged
rodrigobr-msft merged 12 commits intomainfrom
users/robrandao/create-conversation-bug
Nov 14, 2025
Merged

Fix ChannelServiceAdapter.create_conversation implementation#233
rodrigobr-msft merged 12 commits intomainfrom
users/robrandao/create-conversation-bug

Conversation

@rodrigobr-msft
Copy link
Contributor

@rodrigobr-msft rodrigobr-msft commented Nov 10, 2025

This pull request refactors how connector clients are created in the Microsoft Agents Hosting Core, making the process more robust and flexible by allowing a None value for the context parameter and improving error handling. It also adds new and more comprehensive unit tests for the connector client factory logic, and updates test data to support these changes.

Connector Client Creation Refactoring

  • The create_connector_client method in ChannelServiceClientFactoryBase and its implementation in RestChannelServiceClientFactory now accept context: TurnContext | None instead of requiring a non-null context, allowing for greater flexibility in usage. The method also now only requires claims_identity to be non-null, improving error handling. [1] [2]
  • Logic for checking agentic requests in create_connector_client is updated to safely handle cases where context may be None.

Channel Service Adapter Refactoring

  • The flow in ChannelServiceAdapter.create_conversation is refactored to create the connector client before the turn context, and to properly set turn state keys for both the connector client and user token client after the context is created. [1] [2]

Test Improvements

  • New test file test_rest_channel_service_client_factory.py thoroughly tests different scenarios for creating a connector client, including anonymous and normal token flows, with and without scopes, and with/without context.
  • New test scaffold for test_channel_service_adapter.py is introduced for future coverage of the adapter's conversation creation logic.

Test Data Updates

  • DEFAULT_TEST_VALUES is updated to include a service_url field, supporting the new and updated tests.

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 fixes a bug in the conversation creation flow by making the context parameter optional in create_connector_client and adjusting the initialization order in create_conversation. The key change ensures the connector client can be created without a context when starting a new conversation.

  • Made context parameter optional (TurnContext | None) in create_connector_client method
  • Reordered initialization in create_conversation to create the connector client before the turn context
  • Updated validation logic to handle optional context parameter

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
channel_service_client_factory_base.py Updated interface to make context parameter optional
rest_channel_service_client_factory.py Made context optional and updated validation/usage logic
channel_service_adapter.py Reordered conversation creation to build connector client before turn context
default_test_values.py Added service_url test constant
test_rest_channel_service_client_factory.py Added comprehensive tests for the optional context parameter
test_channel_service_adapter.py Added stub test file for channel service adapter

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

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


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

Copilot AI review requested due to automatic review settings November 11, 2025 21:27
@rodrigobr-msft rodrigobr-msft changed the title Users/robrandao/create conversation bug Fix ChannelServiceAdapter.create_conversation implementation Nov 11, 2025
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 6 out of 6 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

tests/hosting_core/test_rest_channel_service_client_factory.py:57

  • This comment appears to contain commented-out code.
    # def activity_agentic_user(self):
    #     return Activity(
    #         type="message",
    #         channel_id="msteams",
    #         from_property=ChannelAccount(id="agentic_user", role=RoleTypes.USER),
    #         recipient=ChannelAccount(id="bot1", role=RoleTypes.BOT),
    #         service_url="https://service.url/",
    #         conversation={"id": "conv1"},
    #         id="activity_agentic1",
    #         text="Hello, World!",
    #         properties={
    #             "agenticRequest": True

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

@rodrigobr-msft rodrigobr-msft marked this pull request as ready for review November 13, 2025 18:11
@rodrigobr-msft rodrigobr-msft requested a review from a team as a code owner November 13, 2025 18:11
Copilot AI review requested due to automatic review settings November 13, 2025 18:11
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 6 out of 6 changed files in this pull request and generated 7 comments.


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

@rodrigobr-msft rodrigobr-msft merged commit c602a1c into main Nov 14, 2025
10 checks passed
@rodrigobr-msft rodrigobr-msft deleted the users/robrandao/create-conversation-bug branch November 14, 2025 18:45
Copilot AI mentioned this pull request Dec 2, 2025
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.

ChannelServiceAdapter create_conversation throws when creating TurnContext

2 participants

Comments