Skip to content

Comments

Sales Validation Agent - Implementation of the sample agent via the AL SDK#345

Open
BazookaMusic wants to merge 2 commits intomicrosoft:masterfrom
BazookaMusic:feature/sva
Open

Sales Validation Agent - Implementation of the sample agent via the AL SDK#345
BazookaMusic wants to merge 2 commits intomicrosoft:masterfrom
BazookaMusic:feature/sva

Conversation

@BazookaMusic
Copy link

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.

Comment on lines +4 to +5
using System.Agents;
using SalesValidationAgent.Setup;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: using ordering

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in most files


AgentTaskBuilder.Initialize(AgentUserSecurityId, TaskTitle);
ExternalId := Format(CreateGuid());
AgentTaskBuilder.SetExternalId(ExternalId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SalesValAgentSetupRec.IsEmpty()?

profile "Sales Validation Agent"
{
Caption = 'Sales Validation Agent (Copilot)';
Enabled = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: "SV Sales Order"? Same for the other customizations

exit(Instructions);
end;

internal procedure GetDefaultProfile(var TempAllProfile: Record "All Profile" temporary)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should mention the avatar and the role center as the starting point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants