Agent in AL
Convert your agent to AL code so it can be packaged and distributed as an extension.
Overview
A UI-built agent only lives in the environment where it was created. Moving it to AL means you can version control it, deploy to any environment, and eventually distribute it via AppSource. Use the XML from Stage 6 as your reference — you’ll recreate the same agent as a proper AL extension.
Part 1 — Create the AL Project
Create a new AL project using the Agent template
In VS Code, hit Ctrl+Shift+P and run AL: New Project. When prompted for a template, pick Agent.
Name it something like MyWorkshopAgent and choose a folder.
Set the runtime version in app.json
Open app.json and set "runtime" to "17.0" — you need this for the Agent SDK interfaces to be available.
{
"id": "...",
"name": "MyWorkshopAgent",
"runtime": "17.0",
...
}
Configure launch.json to point at your environment
Open .vscode/launch.json and update it to target your environment — grab the environment name and tenant ID from your handout.
{
"version": "0.2.0",
"configurations": [
{
"type": "al",
"request": "launch",
"name": "My Workshop Environment",
"environmentType": "Sandbox",
"environmentName": "<your-environment-name>",
"tenant": "<your-tenant-id>"
}
]
}
Replace the placeholder values with what's on your handout (same environment name as the URL).
Download symbols
Run AL: Download Symbols from the command palette. VS Code will connect to your environment and pull down the symbols needed to compile. You'll be asked to sign in if needed.
Explore the generated structure
The template gives you a full working skeleton. Key files:
- AgentMetadataProvider enum extension — registers your agent type
- AgentFactory codeunit — implements
IAgentFactory(default profile, permissions, setup page) - AgentMetadata codeunit — implements
IAgentMetadata(display name, initials, summary) - AgentTaskExecution codeunit — implements
IAgentTaskExecution - Instructions .txt resource file — the plain-text instructions for your agent
- Setup page — the configuration dialog shown when creating an instance
- Install codeunit — registers the Copilot capability on installation
Part 2 — Adapt the Template to Match Your Exported Agent
Keep the XML from Stage 6 open alongside VS Code — you’ll use it as a reference for the next few steps.
Copy the instructions into the resource file
Find the instructions text in the XML and paste it into the instructions .txt resource file generated by the template, replacing the placeholder. The IAgentFactory loads this on agent creation.
Set the default profile
In the AgentFactory codeunit, find the GetDefaultProfile method. Update the Profile ID to match the profile from your exported agent (e.g. 'BUSINESS MANAGER').
procedure GetDefaultProfile(var TempAllProfile: Record "All Profile" temporary)
begin
TempAllProfile."Profile ID" := 'BUSINESS MANAGER';
TempAllProfile."App ID" := '437dbf0e-84ff-417a-965d-ed2bb9650972';
TempAllProfile.Insert();
end;
Set the default permissions
Open the My Agent permission set included in the template and add the permission sets from the XML. We used SUPER for the workshop, but you'd normally go least-privilege in production.
Update the display name and initials
In the Setup page, update the display name and initials to match your agent.
Part 3 — Publish and Verify
Publish the extension
Press F5 (or run AL: Publish) to compile and deploy the extension to Business Central.
Create an instance of your AL agent
Go to the Agents (preview) page — your agent type should be listed. Select it and run through the setup dialog. It'll apply the profile and permissions from your AL code automatically.
.app file, and eventually submit to AppSource — no BC UI needed.