Address agent review feedback

This commit is contained in:
Stefano Demiliani 2026-08-27 16:33:40 +02:00
parent 38d341eabb
commit e98fb8ec38
11 changed files with 63 additions and 20 deletions

View file

@ -15,8 +15,7 @@ Instance setup is not a Card or StandardDialog. The toolkit expects `PageType =
## Best Practice
Declare `PageType = ConfigurationDialog`, host `part(...; "Agent Setup Part")`, and put agent-specific fields in another group. Keep system OK/Cancel. Use a temporary source record and defer persistence until Update, as described in `agent-setup-source-table-is-temporary.md`.
The Extensible property of the page must be set to false.
Declare `PageType = ConfigurationDialog`, host `part(...; "Agent Setup Part")`, and put agent-specific fields in another group. Keep system OK/Cancel. Use a temporary source record and defer persistence until Update, as described in `agent-setup-source-table-is-temporary.md`. Following Microsoft's agent setup samples, set `Extensible = false`.
See sample: `agent-setup-page-is-configuration-dialog.good.al`.

View file

@ -3,14 +3,29 @@ codeunit 50100 "Sales Review Agent Task"
procedure AnalyzeAgentTaskMessage(AgentTaskMessage: Record "Agent Task Message"; var Annotations: Record "Agent Annotation")
var
AgentMessage: Codeunit "Agent Message";
EmptyMessageMsg: Label 'Message is empty.';
EmptyMessageDetailsTxt: Label 'Provide a sales order task before running the agent.';
NotRelevantMsg: Label 'Message is not a sales order task.';
NotRelevantDetailsTxt: Label 'Provide a message related to sales order review.';
MessageText: Text;
begin
if AgentTaskMessage.Type = AgentTaskMessage.Type::Output then begin
AgentMessage.UpdateText(AgentTaskMessage, AgentMessage.GetText(AgentTaskMessage) + '\n\nWritten with the help of AI');
AgentMessage.UpdateText(AgentTaskMessage, AgentMessage.GetText(AgentTaskMessage) + #13#10 + #13#10 + 'Written with the help of AI');
exit;
end;
if not IsRelevant(AgentMessage.GetText(AgentTaskMessage)) then begin
MessageText := AgentMessage.GetText(AgentTaskMessage);
if MessageText = '' then begin
Clear(Annotations);
Annotations.Code := 'MESSAGE001';
Annotations.Severity := Annotations.Severity::Error;
Annotations.Message := EmptyMessageMsg;
Annotations.Details := EmptyMessageDetailsTxt;
Annotations.Insert();
exit;
end;
if not IsRelevant(MessageText) then begin
Clear(Annotations);
Annotations.Code := 'RELEVANCE001';
Annotations.Severity := Annotations.Severity::Warning;
Annotations.Message := NotRelevantMsg;
@ -21,6 +36,6 @@ codeunit 50100 "Sales Review Agent Task"
local procedure IsRelevant(MessageText: Text): Boolean
begin
exit(MessageText <> '');
exit(StrPos(LowerCase(MessageText), 'sales order') > 0);
end;
}

View file

@ -1,3 +1,16 @@
codeunit 50101 "Sales Review Agent Subscribers"
{
Access = Internal;
EventSubscriberInstance = Manual;
SingleInstance = true;
[EventSubscriber(ObjectType::Table, Database::"Sales Header", OnAfterInsertEvent, '', false, false)]
local procedure OnAfterInsertSalesHeader(var Rec: Record "Sales Header")
begin
Message('Keep going, agent.');
end;
}
codeunit 50102 "Agent Session Events"
{
Access = Internal;
@ -6,7 +19,7 @@ codeunit 50102 "Agent Session Events"
InherentPermissions = X;
var
GlobalAgentEvents: Codeunit "Sales Review Agent Events";
GlobalAgentSubscribers: Codeunit "Sales Review Agent Subscribers";
[EventSubscriber(ObjectType::Codeunit, Codeunit::"System Initialization", OnAfterInitialization, '', false, false)]
local procedure RegisterSubscribersOnAfterInitialization()
@ -16,6 +29,6 @@ codeunit 50102 "Agent Session Events"
begin
if not AgentSession.IsAgentSession(AgentMetadataProvider) then
exit;
if BindSubscription(GlobalAgentEvents) then;
if BindSubscription(GlobalAgentSubscribers) then;
end;
}

View file

@ -21,17 +21,15 @@ page 50100 "Sales Review Agent Setup"
trigger OnQueryClosePage(CloseAction: Action): Boolean
var
Agent: Codeunit Agent;
TempAgentAccessControl: Record "Agent Access Control" temporary;
AgentSetup: Codeunit "Agent Setup";
TempAgentSetupBuffer: Record "Agent Setup Buffer" temporary;
AgentUserSecurityId: Guid;
begin
if CloseAction = CloseAction::Cancel then
exit(true);
AgentUserSecurityId := Agent.Create(
Enum::"Agent Metadata Provider"::"Sales Review Agent",
'SALESREVIEW',
'Sales Review Agent',
TempAgentAccessControl);
CurrPage.AgentSetupPart.Page.GetAgentSetupBuffer(TempAgentSetupBuffer);
AgentUserSecurityId := AgentSetup.SaveChanges(TempAgentSetupBuffer);
Agent.SetInstructions(AgentUserSecurityId, GetInstructions());
Agent.Activate(AgentUserSecurityId);
exit(true);

View file

@ -20,7 +20,7 @@ codeunit 50101 "Sales Review Agent Install"
CopilotCapability.RegisterCapability(
Enum::"Copilot Capability"::"Sales Review Agent",
Enum::"Copilot Availability"::Preview,
"Copilot Billing Type"::"Microsoft Billed",
Enum::"Copilot Billing Type"::"Microsoft Billed",
LearnMoreUrlTxt);
end;
}

View file

@ -11,7 +11,7 @@ application-area: [all]
## Description
The agent runtime looks for specific phrases: ask for assistance, request a review, reply, write an email, memorize, set a field, use lookup, invoke an action. Ordinary English such as get a human to look or remember this is weaker. Outbound reply and email always require review; that is platform policy, not optional tone.
The agent runtime looks for specific phrases: ask for assistance, request a review, reply, write an email, memorize, `Set field`, use lookup, `Invoke action`. Ordinary English such as get a human to look or remember this is weaker. Outbound reply and email always require review; that is platform policy, not optional tone.
## Best Practice

View file

@ -4,7 +4,7 @@ enumextension 50100 "Sales Review Agent Metadata" extends "Agent Metadata Provid
{
Caption = 'Sales Review Agent';
Implementation = IAgentFactory = "Sales Review Agent Factory",
IAgentMetadata = "Sales Review Agent Metadata",
IAgentMetadata = "Sales Review Agent Meta. Impl.",
IAgentTaskExecution = "Sales Review Agent Task";
}
}