AgentApplication route registration improvements#429
Open
rodrigobr-msft wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors AgentApplication route registration to make selectors more flexible (supporting lists/patterns) and improves handoff registration ergonomics (decorator vs direct-call) with better typing. It also adds focused routing tests and applies minor test formatting cleanups.
Changes:
- Extend route selector behavior to accept lists for activity type and message match criteria (including regex patterns).
- Refactor
AgentApplication.handoffto support both decorator and direct-call usage, and adjust handler registration behavior. - Add new routing-focused tests and apply formatting/whitespace cleanups in existing tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py | Adds list/pattern selector support and refactors handoff registration/typing. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/turn_context.py | Adds a return type annotation for TurnContext.activity. |
| tests/hosting_core/app/test_agent_application_routes.py | New tests covering activity/message selectors, handoff routing, and route ordering. |
| tests/hosting_teams/test_teams_agent_extension.py | Test formatting-only changes for readability/consistency. |
| tests/hosting_core/app/proactive/test_proactive.py | Removes an unnecessary blank line. |
| tests/hosting_core/app/proactive/test_conversation_reference_builder.py | Removes an unnecessary blank line. |
| tests/hosting_core/app/proactive/test_conversation_builder.py | Removes an unnecessary blank line. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+360
to
+364
| if isinstance(select, list): | ||
| for item in select: | ||
| if isinstance(item, Pattern): | ||
| if re.fullmatch(item, text) is not None: | ||
| return True |
Comment on lines
369
to
+370
| if isinstance(select, Pattern): | ||
| hits = re.fullmatch(select, text) | ||
| return hits is not None | ||
| return re.fullmatch(select, text) is not None |
Comment on lines
+550
to
+554
| @overload | ||
| def handoff( | ||
| self, | ||
| func: Callable[[TurnContext, StateT, str], Awaitable[None]], | ||
| ) -> Callable[[TurnContext, StateT, str], Awaitable[None]]: ... |
| :return: | ||
| """ | ||
| return self._activity | ||
| return self._activity # type: ignore[return-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
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 refactors to the
AgentApplicationcore logic, particularly around route selectors and handler registration, as well as minor test code cleanups and formatting. The most significant changes are the enhanced flexibility in route selectors to support lists and patterns, improvements to thehandoffmethod's typing and decorator usability, and various test code formatting updates for clarity.Core Logic Improvements
agent_application.pyto support lists of allowedactivity_typevalues and lists of text or regex patterns for matching, making route definitions more flexible and expressive. [1] [2]handoffmethod inAgentApplicationto support both decorator and direct-call usage with proper type annotations and overloads, improving developer ergonomics and static analysis. [1] [2]handoffto wrap the provided function and ensure the correct handler is registered with the router, not the original function.activityproperty inTurnContextfor better type checking, with atype: ignorecomment to suppress mypy errors.Test Code Formatting and Cleanup
test_teams_agent_extension.pyto use consistent argument formatting and improved readability in context creation, without changing test logic. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]