Sales Validation Agent - Implementation of the sample agent via the AL SDK#345
Sales Validation Agent - Implementation of the sample agent via the AL SDK#345BazookaMusic wants to merge 2 commits intomicrosoft:masterfrom
Conversation
| using System.Agents; | ||
| using SalesValidationAgent.Setup; |
|
|
||
| AgentTaskBuilder.Initialize(AgentUserSecurityId, TaskTitle); | ||
| ExternalId := Format(CreateGuid()); | ||
| AgentTaskBuilder.SetExternalId(ExternalId); |
There was a problem hiding this comment.
How about using this syntax?
AgentTaskBuilder.Initialize(AgentUserSecurityId, TaskTitle)
.SetExternalId(ExternalId)
.AddTaskMessage(From, Message)
.Create();| AgentTaskBuilder.Create(); | ||
|
|
||
| AgentTask.ReadIsolation(IsolationLevel::ReadCommitted); | ||
| AgentTask.SetRange("External ID", ExternalId); |
There was a problem hiding this comment.
Is it the recommended pattern to find back the task based on External ID?
The Create method returns the task, so you can query the db to see if you find a task with the same ID
| var | ||
| UserSecurityIDFilter: Text; | ||
| begin | ||
| if IsNullGuid(Rec."User Security ID") then begin |
There was a problem hiding this comment.
Maybe we should have a comment explaining how that page behaves and is launched.
There's a convention that the source record must have a User Security ID Guid field and that the record is not fully populated. A comment would explain your code.
|
|
||
| fields | ||
| { | ||
| field(1; "User Security ID"; Guid) |
There was a problem hiding this comment.
Same here, I would add a comment saying it's part of the implementation contract for the GetSummaryPageId page on the IAgentMetadata
| SalesValAgentSetupRec: Record "Sales Val. Agent Setup"; | ||
| begin | ||
| // Single instance agent | ||
| exit(not SalesValAgentSetupRec.FindFirst()); |
There was a problem hiding this comment.
SalesValAgentSetupRec.IsEmpty()?
| profile "Sales Validation Agent" | ||
| { | ||
| Caption = 'Sales Validation Agent (Copilot)'; | ||
| Enabled = false; |
There was a problem hiding this comment.
I think we should enable it. The sample version from the agent samples gets enabled on import, but that one should always be enabled
|
|
||
| using Microsoft.Sales.Document; | ||
|
|
||
| pagecustomization SVSalesOrder customizes "Sales Order" |
There was a problem hiding this comment.
NIT: "SV Sales Order"? Same for the other customizations
| exit(Instructions); | ||
| end; | ||
|
|
||
| internal procedure GetDefaultProfile(var TempAllProfile: Record "All Profile" temporary) |
There was a problem hiding this comment.
The codeunit is marked as Internal, no need to mark the methods too
| { | ||
| Caption = 'User Security ID'; | ||
| ToolTip = 'Specifies the unique identifier for the user.'; | ||
| DataClassification = EndUserPseudonymousIdentifiers; |
There was a problem hiding this comment.
Same here, it's part of the interface contract, we could have a comment explaining why we have it that way
| @@ -0,0 +1,35 @@ | |||
| { | |||
| "id": "5878e09e-13b4-4058-a9f6-4a9ee1605d6a", | |||
| "name": "SalesValidationAgent", | |||
There was a problem hiding this comment.
Sales Validation Agent Sample?
|
|
||
| #### Metadata | ||
|
|
||
| Implements the `IAgentFactory` and `IAgentMetadata` interfaces required by the Business Central Agent framework. The factory provides default initials, the setup page, the Copilot capability, the default profile, and access control templates, and enforces a **single-instance** constraint (only one agent can be created). The metadata codeunit supplies page IDs for setup, summary, and task message cards. An enum extension on `Agent Metadata Provider` wires these implementations into the platform. |
There was a problem hiding this comment.
The enforces a **single-instance** is not really true. It's true from the role center avatars, but if the app exposes a different way to create agents that does not start from there, it would be possible. The method is named ShowCanCreateAgent since it's UI only. If the app wants to enforce it, the app needs changes in the Setup table/page.
|
|
||
| ## How It Works | ||
|
|
||
| 1. **Enable the capability** – An admin enables *Sales Validation Agent* in the Copilot & AI Capabilities page. |
There was a problem hiding this comment.
The capability is marked as Preview, so it is enabled by default.
| ## How It Works | ||
|
|
||
| 1. **Enable the capability** – An admin enables *Sales Validation Agent* in the Copilot & AI Capabilities page. | ||
| 2. **Create the agent** – Open the *Sales Val. Agent Setup* configuration dialog to provision the agent user with the correct profile and permissions. |
There was a problem hiding this comment.
We probably should mention the avatar and the role center as the starting point
This PR adds the "Sales Validation Agent" which is packaged as a sample app when designing agents in Business Central. It demonstrates how the agent can be packaged into an app and the different components that this app contains.