Skip to content

Expanding route hook APIs in AgentApplication, SlackAgentExtension, and TeamsAgentExtension - #627

Draft
Rodrigo Brandão (rodrigobr-msft) wants to merge 10 commits into
mainfrom
users/robrandao/slack-routes
Draft

Rodrigo Brandão (rodrigobr-msft) wants to merge 10 commits into
mainfrom
users/robrandao/slack-routes

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

This pull request introduces a flexible and extensible system for defining application route hooks and selectors in the AgentApplication class, 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:

  • Added reusable route selector utilities (_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))
  • Introduced the TextSelector type (string, regex, or list of these) for matching activity text or event names, and added the _matches_text utility 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:

  • Added new decorator methods to AgentApplication for handling event, invoke, and installation_update activities, each supporting optional channel scoping and text/regex pattern matching. Updated the message and activity decorators 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))
  • Extended the changelog to document the new application route hooks, channel-aware selectors, and Teams/Slack-scoped features. ([changelog.mdR10-R17](https://github.com/microsoft/Agents-for-python/pull/627/files#diff-3bd14d078188074c410028847113ceae68865d0ad5b844a27183ef87fbe2fcc3R10-R17))

Type and API improvements:

  • Updated parameter types throughout AgentApplication to 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Invoke registration and dispatch defects, Slack keyword compatibility breaks, and missing subchannel client binding remain unresolved.

5 open findings
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Previously reported routing regressions remain unresolved in the supplied code.

0 open findings

5 resolved since last review

🧠 Review effort: Balanced

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.

Supply extended set of route registration hooks via the SlackAgentExtension

2 participants