-
Notifications
You must be signed in to change notification settings - Fork 56
Extension support and starter sample #141
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
Merged
Changes from all commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
ca07a83
Drafting extension starter sample
rodrigobr-msft 1f85836
Completed basic outline
rodrigobr-msft 00839d3
doc_samples directory created
rodrigobr-msft 37e7f70
Enhancing app routing
rodrigobr-msft 14de9d5
Cleaned up new route logic and its usage in the extension-starter sample
rodrigobr-msft ba30c82
Implement asynchronous token retrieval methods in AgenticMsalAuth class
rodrigobr-msft 755e973
get_agentic_user_token implementation
rodrigobr-msft c79d56b
get_agentic_user_token simplified implementation with ConfidentialCli…
rodrigobr-msft c671841
Enhance AgenticMsalAuth: update get_agentic_instance_token to return …
rodrigobr-msft 1fed41f
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft c4a8381
Adding improved route handling tests
rodrigobr-msft 5568b6e
Adding RouteList tests
rodrigobr-msft b57b7bf
Adding __iter__ to RouteList and fixing AgentApplication usage of Rou…
rodrigobr-msft b06af40
Supporting authorization variants
rodrigobr-msft 4ce735e
Continued auth refactor
rodrigobr-msft ac48fbc
Addressing continuation activity
rodrigobr-msft a078bd6
Adding authorization tests
rodrigobr-msft 860fade
Passing Authorization tests
rodrigobr-msft 56d46b8
Basic AgenticAuthorization tests
rodrigobr-msft e514ea8
Added AgenticAuthorization tests
rodrigobr-msft 83c6688
Finalized fundamental unit tests for agentic auth scenarios
rodrigobr-msft 23efb16
Extension starter sample
rodrigobr-msft 193508d
agentic_selector decorator
rodrigobr-msft 537b5c8
Route helpers
rodrigobr-msft 2656435
Formatting
rodrigobr-msft ef01438
Formatting
rodrigobr-msft 185acfc
Address review comments and more breaking changes
rodrigobr-msft 770cf69
Shifting around exchange token logic
rodrigobr-msft 389b6cd
Adding dynamic loading of connection and related tests
rodrigobr-msft 8a41020
Aligning authorization handlers with how .NET does it
rodrigobr-msft a0df177
get_token_provider implemented and tested
rodrigobr-msft ea54c51
Tested UserAuthorization and AgenticUserAuthorization classes
rodrigobr-msft 84edf3a
Finalized refactor tests
rodrigobr-msft 82e4ae5
Sample compat
rodrigobr-msft 6611ed8
Compat changes
rodrigobr-msft 98436a8
Passing all tests again
rodrigobr-msft c3c3db3
Repurposing SignInState
rodrigobr-msft 3d7a962
Completed tests for auth fix
rodrigobr-msft a34cdfb
Changes to avoid auth on typing
rodrigobr-msft 3100fc0
Changes to avoid auth on typing
rodrigobr-msft 04eaf7e
Enable passing TurnContext into create_connector_client
rodrigobr-msft 86dfac2
Tweaks to work almost end-to-end / fixing connector client construction
rodrigobr-msft b564193
Moving agentic static methods to be instance methods of Activity and …
rodrigobr-msft f791827
Addressing PR review comments
rodrigobr-msft a82c1f7
Reformatting files with black
rodrigobr-msft 511b9a8
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft fe197cb
Fixing test case
rodrigobr-msft 1f2ce31
Removing unneeded subchannel constants
rodrigobr-msft 5f98c7b
Fixed merge conflict
rodrigobr-msft 68db989
Tweaks to imports
rodrigobr-msft d8ebb19
Fixing test import
rodrigobr-msft cf1ac30
Fixed new merge conflicts
rodrigobr-msft fb4e583
Fixed improved route handling tests
rodrigobr-msft fe900ae
Adding to extension starter sample
rodrigobr-msft 76d795e
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft 3b3ca1c
Reorganizing sample code
rodrigobr-msft 02e173c
Change to add_route for RouteList
rodrigobr-msft c5ad7f8
Adding add_route docstring
rodrigobr-msft 6162523
Fixing RouteList definition and iteration
rodrigobr-msft c75d904
Formatting src
rodrigobr-msft 30bca99
Redoing sample decorator definitions to take in arguments
rodrigobr-msft c4a2989
Finalized extension sample
rodrigobr-msft c84871d
Fixed RouteList usage in AgentApplication
rodrigobr-msft 2df8da9
Docstrings to code
rodrigobr-msft 5b1de27
Added argument validation to add_route
rodrigobr-msft be72c69
Fixing RouteRank bounds, tests, and typos
rodrigobr-msft 9e7fdfa
Adding copyright comment
rodrigobr-msft b6e5e9c
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft 5cdc2b7
Adding copyright header to hosting.core modules
rodrigobr-msft 8892222
Removing strenum dependency
rodrigobr-msft abfb229
Removed debug printing
rodrigobr-msft 62aca17
Removed todos
rodrigobr-msft b1d0383
Changing whitespace
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
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
libraries/microsoft-agents-activity/microsoft_agents/activity/_type_aliases.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 |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| from typing import Annotated | ||
| from pydantic import StringConstraints | ||
|
|
||
|
|
||
| NonEmptyString = Annotated[str, StringConstraints(min_length=1)] |
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
3 changes: 3 additions & 0 deletions
3
...es/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.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
3 changes: 3 additions & 0 deletions
3
...gents-authentication-msal/microsoft_agents/authentication/msal/msal_connection_manager.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
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
3 changes: 3 additions & 0 deletions
3
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/_oauth/__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
1 change: 1 addition & 0 deletions
1
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/activity_handler.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
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
13 changes: 13 additions & 0 deletions
13
...aries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/_routes/__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,13 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from ._route_list import _RouteList | ||
| from ._route import _Route, _agentic_selector | ||
| from .route_rank import RouteRank | ||
|
|
||
| __all__ = [ | ||
| "_RouteList", | ||
| "_Route", | ||
| "RouteRank", | ||
| "_agentic_selector", | ||
| ] | ||
89 changes: 89 additions & 0 deletions
89
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/_routes/_route.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,89 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Generic, Optional, TypeVar | ||
|
|
||
| from ...turn_context import TurnContext | ||
| from .._type_defs import RouteHandler, RouteSelector | ||
| from ..state.turn_state import TurnState | ||
| from .route_rank import RouteRank | ||
|
|
||
|
|
||
| def _agentic_selector(selector: RouteSelector) -> RouteSelector: | ||
| def wrapped_selector(context: TurnContext) -> bool: | ||
| return context.activity.is_agentic_request() and selector(context) | ||
|
|
||
| return wrapped_selector | ||
|
|
||
|
|
||
| StateT = TypeVar("StateT", bound=TurnState) | ||
|
|
||
|
|
||
| class _Route(Generic[StateT]): | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| selector: RouteSelector | ||
| handler: RouteHandler[StateT] | ||
| _is_invoke: bool | ||
| _rank: int | ||
| auth_handlers: list[str] | ||
| _is_agentic: bool | ||
|
|
||
| def __init__( | ||
| self, | ||
| selector: RouteSelector, | ||
| handler: RouteHandler[StateT], | ||
| is_invoke: bool = False, | ||
| rank: int = RouteRank.DEFAULT, | ||
| auth_handlers: Optional[list[str]] = None, | ||
| is_agentic: bool = False, | ||
| **kwargs, | ||
| ) -> None: | ||
|
|
||
| if rank < 0 or rank > RouteRank.LAST: | ||
| raise ValueError( | ||
| "Route rank must be between 0 and RouteRank.LAST (inclusive)" | ||
| ) | ||
|
|
||
| self.selector = selector | ||
| self.handler = handler | ||
| self._is_invoke = is_invoke | ||
| self._rank = int(rank) # conversion from RouteRank IntEnum if necessary | ||
| self._is_agentic = is_agentic | ||
| self.auth_handlers = auth_handlers or [] | ||
|
|
||
| @property | ||
| def is_invoke(self) -> bool: | ||
| return self._is_invoke | ||
|
|
||
| @property | ||
| def rank(self) -> int: | ||
| return self._rank | ||
|
|
||
| @property | ||
| def is_agentic(self) -> bool: | ||
| return self._is_agentic | ||
|
|
||
| @property | ||
| def priority(self) -> list[int]: | ||
| """Lower "values" indicate higher priority. | ||
|
|
||
| Priority is determined by: | ||
| 1. Whether the route is for an invoke activity (0) or not (1). | ||
| 2. Whether the route is agentic (0) or not (1). | ||
| 3. The rank of the route (lower numbers indicate higher priority). | ||
|
|
||
| In that order. If both are invokes, the agentic one has higher priority. | ||
| If both are agentic and invokes, then the rank determines priority. | ||
|
|
||
| priority is represented as a list of three integers for easy lexicographic comparison. | ||
| """ | ||
| return [ | ||
| 0 if self._is_invoke else 1, | ||
| 0 if self._is_agentic else 1, | ||
| self._rank, | ||
| ] | ||
|
|
||
| def __lt__(self, other: _Route) -> bool: | ||
| # built-in list ordering is a lexicographic comparison in Python | ||
| return self.priority < other.priority | ||
32 changes: 32 additions & 0 deletions
32
...es/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/_routes/_route_list.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,32 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import heapq | ||
| from typing import Generic, TypeVar | ||
|
|
||
| from ..state.turn_state import TurnState | ||
| from ._route import _Route | ||
|
|
||
| StateT = TypeVar("StateT", bound=TurnState) | ||
|
|
||
|
|
||
| class _RouteList(Generic[StateT]): | ||
| _routes: list[_Route[StateT]] | ||
|
|
||
| def __init__( | ||
| self, | ||
| ) -> None: | ||
| # a min-heap where lower "values" indicate higher priority | ||
| self._routes = [] | ||
|
|
||
| def add_route(self, route: _Route[StateT]) -> None: | ||
| """Adds a route to the list.""" | ||
| heapq.heappush(self._routes, route) | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def __iter__(self): | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # sorted will return a new list, leaving the heap intact | ||
| # returning an iterator over the previous list would expose | ||
| # internal details | ||
| return iter(sorted(self._routes)) | ||
14 changes: 14 additions & 0 deletions
14
...ies/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/_routes/route_rank.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,14 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from enum import IntEnum | ||
|
|
||
| _MAX_RANK = 2**16 - 1 # 65,535 | ||
|
|
||
|
|
||
| class RouteRank(IntEnum): | ||
| """Defines the rank of a route. Lower values indicate higher priority.""" | ||
|
|
||
| FIRST = 0 | ||
| DEFAULT = _MAX_RANK // 2 | ||
| LAST = _MAX_RANK |
15 changes: 15 additions & 0 deletions
15
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/_type_defs.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,15 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from typing import Callable, TypeVar, Awaitable, Protocol | ||
|
|
||
| from ..turn_context import TurnContext | ||
| from .state import TurnState | ||
|
|
||
| RouteSelector = Callable[[TurnContext], bool] | ||
|
|
||
| StateT = TypeVar("StateT", bound=TurnState) | ||
|
|
||
|
|
||
| class RouteHandler(Protocol[StateT]): | ||
| def __call__(self, context: TurnContext, state: StateT) -> Awaitable[None]: ... |
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.