-
Notifications
You must be signed in to change notification settings - Fork 86
TurnContext.services with generic type-based keying and retrieval
#491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Rodrigo Brandão (rodrigobr-msft)
merged 26 commits into
main
from
users/robrandao/tc-services
Jul 24, 2026
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
bb78cfb
TurnContext.services refactor
rodrigobr-msft f732b40
another commit
rodrigobr-msft 4664b3b
another commit
rodrigobr-msft ebdc3ea
Potential fix for pull request finding
rodrigobr-msft 0cba44e
Potential fix for pull request finding
rodrigobr-msft 0846d05
Potential fix for pull request finding
rodrigobr-msft 14d775e
Formatting with black
rodrigobr-msft 5451499
Merge branch 'users/robrandao/tc-services' of https://github.com/micr…
rodrigobr-msft b09c847
Formatting with black
rodrigobr-msft f1ec07a
Back compat fixes
rodrigobr-msft 025f19b
Another commit
rodrigobr-msft 74c899d
Resolving merge conflicts
rodrigobr-msft f29f3b6
Addressing PR feedback
rodrigobr-msft d5b7845
Potential fix for pull request finding
rodrigobr-msft 10461d5
Potential fix for pull request finding
rodrigobr-msft f5f4140
Fixing issue in test
rodrigobr-msft 9108cd4
Fixing integration test issue
rodrigobr-msft 38187b7
Fixing test mock object
rodrigobr-msft 043d34a
More test fixes
rodrigobr-msft 838d058
Adding missing __init__ doscstring
rodrigobr-msft d85dd34
Addressing merge conflicts
rodrigobr-msft d43c7c1
Completing unfinished Protocol definition
rodrigobr-msft 6133106
Completing unfinished Protocol definition
rodrigobr-msft f1ba3d3
Addressing PR feedback
rodrigobr-msft aaf61ad
Fixing merge conflict
rodrigobr-msft 18b0391
Merge branch 'main' into users/robrandao/tc-services
rodrigobr-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
6 changes: 6 additions & 0 deletions
6
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/_utils/__init__.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from ._service_set import _ServiceSet | ||
|
|
||
| __all__ = ["_ServiceSet"] |
55 changes: 55 additions & 0 deletions
55
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/_utils/_service_set.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TypeVar, cast, Any | ||
|
|
||
| T = TypeVar("T") | ||
|
|
||
|
|
||
| class _ServiceSet: | ||
| """ | ||
| A class that represents a collection of services, allowing for the storage and retrieval of service instances by their type. | ||
| """ | ||
|
|
||
| def __init__(self, service_set: _ServiceSet | None = None) -> None: | ||
| """ | ||
| Initializes a new instance of the _ServiceSet class. | ||
|
|
||
| :param service_set: An optional _ServiceSet instance to copy the state from. | ||
| """ | ||
| self._state: dict[type, Any] = {} | ||
| if service_set is not None: | ||
| self._state.update(service_set._state) | ||
|
|
||
| def get(self, key: type[T]) -> T | None: | ||
| """ | ||
| Gets a value from the state collection. | ||
| :param key: | ||
| :return: | ||
| """ | ||
| val = self._state.get(key) | ||
| if val is not None: | ||
| if not isinstance(val, key): | ||
| raise TypeError( | ||
| f"Value for key '{key.__name__}' is not of type {key.__name__} (got {type(val).__name__})" | ||
| ) | ||
| return cast(T, val) | ||
|
rodrigobr-msft marked this conversation as resolved.
|
||
| return None | ||
|
Copilot marked this conversation as resolved.
rodrigobr-msft marked this conversation as resolved.
|
||
|
|
||
| def has(self, key: type) -> bool: | ||
| """ | ||
| Checks if a value exists in the state collection. | ||
| :param key: Type of the value to check for. | ||
| :return: True if the value exists, False otherwise. | ||
| """ | ||
| return key in self._state | ||
|
|
||
| def set(self, key: type[T], value: T) -> None: | ||
| """ | ||
| Sets a value in the state collection. | ||
| :param key: Type of the value to set. | ||
| :param value: The value to set. | ||
| """ | ||
| self._state[key] = value | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.