Skip to content

fix: A365 Notification Routes Not Marked as Agentic — Deprioritized by SDK 1.4.68+ Route Ordering#231

Merged
flaviocdc merged 2 commits intomainfrom
fix/notification-agentic-routing
Apr 2, 2026
Merged

fix: A365 Notification Routes Not Marked as Agentic — Deprioritized by SDK 1.4.68+ Route Ordering#231
flaviocdc merged 2 commits intomainfrom
fix/notification-agentic-routing

Conversation

@flaviocdc
Copy link
Copy Markdown
Member

@flaviocdc flaviocdc commented Apr 2, 2026

A365 Notification Routes Not Marked as Agentic — Deprioritized by SDK 1.4.68+ Route Ordering

Problem

After upgrading Microsoft.Agents.Builder, A365 notification activities (email, comment) with type=message, channelId=agents, recipient.role=agenticUser are no longer routed to OnAgentNotification. Instead, they are intercepted by application-level OnActivity(ActivityTypes.Message, isAgenticOnly: true) handlers.

This repo pins Microsoft.Agents.Builder at 1.4.83 (see Directory.Packages.props). The breaking change was introduced in SDK 1.4.68-beta and also affects the latest 1.5.83 beta.

Root Cause

In microsoft/Agents-for-net@90e3d788 ("Using RouteBuilders internally", version 1.4.68-beta), AgentApplication.AddRoute(RouteSelector, ...) gained a new bool isAgenticOnly = false parameter. Routes created with isAgenticOnly: true (e.g., via OnActivity) are now flagged with RouteFlags.Agentic, which gives them Order = Agentic(1) in RouteList — sorted before all Order = Other(0) routes regardless of rank or insertion order.

AgentExtension.AddRoute (used by AgentNotification.OnAgentNotification and OnLifecycleNotification) calls AgentApplication.AddRoute without passing isAgenticOnly, so it defaults to false. This means notification routes are classified as Other(0) and are evaluated after any Agentic(1) routes.

In 1.4.1, AddRoute had no isAgenticOnly parameter — both notification and message routes were Other(0), so insertion order determined priority and OnAgentNotification (registered first) won.

In 1.4.68+, OnActivity(Message, isAgenticOnly: true) is Agentic(1) and always evaluated first, intercepting notifications before OnAgentNotification gets a chance.

Timeline

Version Commit Behavior
1.4.1 microsoft/Agents-for-net@693890ed Both routes Other(0) → insertion order wins → notifications routed correctly
1.4.68 microsoft/Agents-for-net@90e3d788 AddRoute gains isAgenticOnly param; OnActivity now uses TypeRouteBuilder.AsAgentic(true)breaking change
1.4.83 / 1.5.83 microsoft/Agents-for-net@cc1ec4d8 Same broken behavior; message routes are Agentic(1), notification routes remain Other(0)

Fix

Mark A365 notification routes as agentic since they are always agentic requests (recipient.role = agenticUser):

- AddRoute(_app, routeSelector, routeHandler, false, rank, autoSignInHandlers);
+ AddRoute(_app, routeSelector, routeHandler, isAgenticOnly: true, rank: rank, autoSignInHandlers: autoSignInHandlers);

Applied to both OnAgentNotification and OnLifecycleNotification in AgentNotification.cs.

Additional changes

  • Azure.Identity bumped from 1.14.2 → 1.17.1 to satisfy transitive dependency from Microsoft.Agents.Authentication.Msal 1.4.83
  • 9 routing integration tests added that exercise the real AgentApplication.OnTurnAsync dispatch pipeline, proving notification handlers win over competing generic agentic message handlers. With isAgenticOnly: false, 7 of 9 tests fail.

Notification routes registered via OnAgentNotification and OnLifecycleNotification
were not passing isAgenticOnly: true to AgentExtension.AddRoute. Starting with
Microsoft.Agents.Builder 1.4.68, routes flagged as Agentic (Order=1) are evaluated
before Other (Order=0) routes. This caused OnActivity(Message, isAgenticOnly: true)
handlers to intercept agentic notifications before the notification handler ran.

Fix: pass isAgenticOnly: true in both OnAgentNotification and OnLifecycleNotification
since A365 notifications are always agentic requests (recipient.role = agenticUser).

Also bumps Azure.Identity 1.14.2 -> 1.17.1 to satisfy transitive dependency from
Microsoft.Agents.Authentication.Msal 1.4.83, and adds routing integration tests that
exercise the real AgentApplication dispatch pipeline to verify notification handlers
win over competing generic message handlers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@flaviocdc flaviocdc requested review from a team as code owners April 2, 2026 18:23
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 339a2e6.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes A365 notification routing priority regressions introduced by agentic route ordering changes in newer Microsoft.Agents.* SDKs by ensuring notification routes are classified as agentic and therefore evaluated before generic agentic message routes.

Changes:

  • Mark OnAgentNotification and OnLifecycleNotification routes as isAgenticOnly: true so they participate in agentic route ordering.
  • Add integration-style routing tests that exercise AgentApplication.OnTurnAsync dispatch behavior in the presence of competing agentic message handlers.
  • Update central package versions (notably Azure.Identity and Microsoft.Agents.*).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/Tests/Microsoft.Agents.A365.Notifications.Tests/AgentNotificationRoutingTests.cs Adds routing integration tests to validate notification handlers win over generic agentic message handlers.
src/Notification/Microsoft.Agents.A365.Notifications/AgentNotification.cs Updates notification/lifecycle route registration to pass isAgenticOnly: true.
src/Directory.Packages.props Bumps central package versions for Azure.Identity and Microsoft.Agents.*.

- Add using declarations on TurnContext instances to ensure disposal
- Use ChannelId constructor instead of implicit string conversion for
  msteams and directline channel IDs for consistency
- Fix grammar in comment: 'we will required' -> 'we will require'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member Author

@flaviocdc flaviocdc left a comment

Choose a reason for hiding this comment

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

Thanks for the review feedback — all 5 comments addressed in 339a2e6.

@flaviocdc flaviocdc merged commit 3d00e82 into main Apr 2, 2026
7 checks passed
@flaviocdc flaviocdc deleted the fix/notification-agentic-routing branch April 2, 2026 19:39
flaviocdc added a commit to flaviocdc/Agents-for-net that referenced this pull request Apr 3, 2026
Adds tests that verify agentic route priority through OnTurnAsync dispatch,
closing a coverage gap exposed by microsoft/Agent365-dotnet#231 where
notification routes registered without isAgenticOnly were deprioritized.

- Agentic route beats non-agentic for agentic requests
- Two agentic routes at same rank: first match wins
- Non-agentic request skips agentic-only routes
- AgentExtension.AddRoute propagates isAgenticOnly flag correctly

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

6 participants