bcquality/community/knowledge/agents/do-not-create-agents-in-install-upgrade-or-background.md
Stefano Demiliani 53e2cf2fa4
Add community guidance and review support for Business Central agents (#137)
* feat(community/agents): add AL agent quality guidance

- add 20 agent knowledge rules with good and bad AL samples
- clarify setup dialog shape, temporary persistence, permissions, profiles, instructions, capability registration, and interface wiring
- add the community-owned AL agents review skill
- make review fixture discovery layer-aware with custom, community, and Microsoft precedence
- document layer-aware evaluation behavior

* fix(community/agents): align setup and permission samples

- mark agent setup pages as non-extensible where required
- narrow the agent profile by hiding an unrelated sales-order field
- define a dedicated read-only permission set for the sales review agent
- assign AL-defined permission sets with system scope and the owning app ID
- clarify the permission scope guidance for default access controls

* Address agent review feedback
2026-09-02 16:06:25 +02:00

1.3 KiB

bc-version domain keywords technologies countries application-area
27..
agents
agent-create
install
upgrade
job-queue
interactive-session
background
al
w1
all

Do not create agent instances from install, upgrade, or background sessions

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.