Bind extra agent subscribers only inside an agent session
Page-filter tweaks, extra validation, and prompt dialogs for the agent should not run for every user. Agent Session.IsAgentSession distinguishes agent UI sessions. Binding those subscribers on System Initialization only when the session is an agent session avoids global subscriber cost.
- communitylayer
- agentsdomain
- 2examples
- 2pull requests
Rule on GitHub · community layer · agents · BC 27.. · tier official · derived
Description
Page-filter tweaks, extra validation, and prompt dialogs for the agent should not run for every user. Agent Session.IsAgentSession distinguishes agent UI sessions. Binding those subscribers on System Initialization only when the session is an agent session avoids global subscriber cost. Models register SingleInstance table subscribers unconditionally.
Best Practice
On OnAfterInitialization, exit unless Agent Session.IsAgentSession. Then BindSubscription a single-instance codeunit that holds the current task id. Keep those subscribers internal.
See sample: bind-agent-subscribers-only-in-agent-session.good.al.
Anti Pattern
Event subscribers on Sales Header OnAfterInsert that always Message the agent, with no IsAgentSession guard. Detection signal: agent-only behaviour in a static subscriber that is not bind-gated.
See sample: bind-agent-subscribers-only-in-agent-session.bad.al.
Examples
- Good: bind-agent-subscribers-only-in-agent-session.good.al
- Bad: bind-agent-subscribers-only-in-agent-session.bad.al
Names
- Session.BindSubscription(Codeunit) Method (names BindSubscription)
- codeunit 150 “System Initialization” (possibly related: a code span names it)
Changed by
- #174 Make BCQuality documentation easier for partners to get started, 2026-09-09
- #137 Add community guidance and review support for Business Central agents, 2026-09-02
From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).