Repository navigation
Expanding route hook APIs in AgentApplication, SlackAgentExtension, and TeamsAgentExtension - #627
Draft
Rodrigo Brandão (rodrigobr-msft) wants to merge 10 commits into
Draft
Rodrigo Brandão (rodrigobr-msft) wants to merge 10 commits into
Rodrigo Brandão (rodrigobr-msft) wants to merge 10 commits into
Conversation
…nnel id for various route hooks
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Invoke registration and dispatch defects, Slack keyword compatibility breaks, and missing subchannel client binding remain unresolved.
5 open findings
Make handoff routes invoke-enabled for correct priority ordering · New Allow unnamed invokes for catch-all handlers · New Remove is_invoke from kwargs before forwarding to add_route · New Bind clients for Slack subchannel turns · New Consume event_name selector alias before forwarding route options · New
What changed in this PR
Expands routing in the Python Agents SDK with reusable selectors and channel-scoped hooks for core, Slack, and Teams applications.
Changes:
- Adds channel, text, regex, and event-name filtering.
- Extends route decorators and channel-specific integrations.
- Adds routing tests and updates documentation.
| File | Description |
|---|---|
| tests/hosting_slack/test_slack_agent_extension.py | Tests Slack hooks and handler wrapping. |
| tests/hosting_msteams/test_routing_integration.py | Tests Teams channel filtering. |
| tests/hosting_core/app/test_selector.py | Tests reusable selectors. |
| tests/hosting_core/app/test_agent_application_routes.py | Tests hooks, filtering, and ranking. |
| tests/activity/test_channel_id.py | Tests directional channel matching. |
| test_samples/README.md | Refreshes sample setup and navigation. |
| libraries/microsoft-agents-hosting-slack/readme.md | Documents Slack route hooks. |
| libraries/microsoft-agents-hosting-slack/microsoft_agents/hosting/slack/slack_agent_extension.py | Delegates Slack hooks to core routing. |
| libraries/microsoft-agents-hosting-msteams/microsoft_agents/hosting/msteams/teams_agent_extension.py | Adds hooks and Teams scoping. |
| libraries/microsoft-agents-hosting-msteams/microsoft_agents/hosting/msteams/message/message.py | Reuses invoke selection. |
| libraries/microsoft-agents-hosting-msteams/microsoft_agents/hosting/msteams/message_extension/message_extension.py | Reuses invoke selectors. |
| libraries/microsoft-agents-hosting-msteams/microsoft_agents/hosting/msteams/config/config.py | Reuses configuration invoke selection. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py | Expands decorators and channel filtering. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/_utils.py | Centralizes text matching. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/_type_defs.py | Defines the shared text-selector type. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/_selector.py | Adds composable routing selectors. |
| libraries/microsoft-agents-activity/microsoft_agents/activity/channel_id.py | Adds directional channel inclusion. |
| changelog.md | Records routing enhancements. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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 a flexible and extensible system for defining application route hooks and selectors in the
AgentApplicationclass, supporting advanced filtering by channel, activity type, and text patterns (including regex). It adds new decorator methods for handling events, invokes, installation updates, and other activity types, and introduces reusable selector utilities for channel- and text-aware routing. These changes enable fine-grained, channel-scoped, and pattern-based routing for bot activities, and lay the foundation for channel-specific extensions in both Slack and Teams.Major enhancements to routing and selectors:
_selector.py), including_text_selector,_event_selector,_invoke_event_selector,_activity_type_selector,_channel_selector, and_SimpleRouteSelector, to enable flexible matching of activities by text, event name, activity type, and channel. ([libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/_selector.pyR1-R151](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-b069582c6fca82e19228dbf40737c5a46d152f72db89af662429f51a257cf10eR1-R151))TextSelectortype (string, regex, or list of these) for matching activity text or event names, and added the_matches_textutility for consistent selector matching. ([[1]](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-7d383f679e814f078c571ed8a5b792d7a7d11d73076a7e43d2246d890a963288R15),[[2]](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-dbaf8346acbf59de2dd121440de08fd22093a1d80751fc84b5aa4cccc51079e6R41-R66))New and improved application route hooks:
AgentApplicationfor handlingevent,invoke, andinstallation_updateactivities, each supporting optional channel scoping and text/regex pattern matching. Updated themessageandactivitydecorators to support channel scoping and flexible selectors. ([[1]](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-a0c0028a01efc798e89b84f1bca0d4323b71753bd6f43d02800f29e66bc766a6L388-R398),[[2]](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-a0c0028a01efc798e89b84f1bca0d4323b71753bd6f43d02800f29e66bc766a6L405-R533))[changelog.mdR10-R17](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-3bd14d078188074c410028847113ceae68865d0ad5b844a27183ef87fbe2fcc3R10-R17))Type and API improvements:
AgentApplicationto use Python 3.10+ union syntax (e.g.,list[str] | None), clarified docstrings, and improved type annotations for route handlers and selectors. ([[1]](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-a0c0028a01efc798e89b84f1bca0d4323b71753bd6f43d02800f29e66bc766a6L106-R119),[[2]](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-a0c0028a01efc798e89b84f1bca0d4323b71753bd6f43d02800f29e66bc766a6L349-R358),[[3]](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-a0c0028a01efc798e89b84f1bca0d4323b71753bd6f43d02800f29e66bc766a6L367-R376),[[4]](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-a0c0028a01efc798e89b84f1bca0d4323b71753bd6f43d02800f29e66bc766a6L53-R69),[[5]](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-a0c0028a01efc798e89b84f1bca0d4323b71753bd6f43d02800f29e66bc766a6L26-R31))These changes make it much easier to define sophisticated, channel-specific, and pattern-based routing logic for bot activities, and provide a foundation for further channel-aware extensions in both Slack and Teams.