Do not create agent instances from install, upgrade, or background sessions
Agent.Create requires an interactive user session. The platform blocks creation from install codeunits, upgrade codeunits, and background sessions (job queue, scheduled tasks). Packaging an agent in an app does not mean spinning up instances at install.
- communitylayer
- agentsdomain
- 2examples
- 2pull requests
Rule on GitHub · community layer · agents · BC 27.. · tier official · derived
Description
Agent.Create requires an interactive user session. The platform blocks creation from install codeunits, upgrade codeunits, and background sessions (job queue, scheduled tasks). Packaging an agent in an app does not mean spinning up instances at install. Models still call Create from OnInstallAppPerCompany to activate the agent.
Best Practice
Create instances from a setup page, a wizard, or another UI-driven path after the user is in a client session. Apply instructions and Activate there. For existing companies after an upgrade, document that an admin must open setup; do not create from the upgrade codeunit.
See sample: do-not-create-agents-in-install-upgrade-or-background.good.al.
Anti Pattern
Agent.Create inside OnInstallAppPerCompany, OnUpgradePerCompany, or a job-queue codeunit. The call fails at runtime even if it compiles. Detection signal: Agent.Create in Subtype = Install, Subtype = Upgrade, or a non-UI session.
See sample: do-not-create-agents-in-install-upgrade-or-background.bad.al.
Examples
- Good: do-not-create-agents-in-install-upgrade-or-background.good.al
- Bad: do-not-create-agents-in-install-upgrade-or-background.bad.al
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).