Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ codeunit 4303 "Agent Task"
exit(AgentTaskImpl.IsTaskStopped(AgentTask));
end;

/// <summary>
/// Gets the total Copilot credits consumed by the agent task.
/// </summary>
/// <param name="AgentTaskID">The ID of the agent task to get consumed credits for.</param>
/// <returns>The total Copilot credits consumed by the agent task.</returns>
procedure GetCopilotCreditsConsumed(AgentTaskID: BigInteger): Decimal
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
exit(AgentTaskImpl.GetCopilotCreditsConsumed(AgentTaskID));
end;

var
FeatureAccessManagement: Codeunit "Feature Access Management";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,18 @@ codeunit 4316 "Agent Task Message Builder"
/// </summary>
/// <param name="AgentTaskFile">The file to attach.</param>
/// <returns>This instance of the Agent Task Message Builder.</returns>
procedure AddAttachment(AgentTaskFile: Record "Agent Task File"): codeunit "Agent Task Message Builder"
#if not CLEAN28
#pragma warning disable AS0078
#endif
procedure AddAttachment(var AgentTaskFile: Record "Agent Task File"): codeunit "Agent Task Message Builder"
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentTaskMsgBuilderImpl.AddAttachment(AgentTaskFile);
exit(this);
end;

#if not CLEAN28
#pragma warning restore AS0078
#endif
/// <summary>
/// Uploads a file to the task message.
/// The file will be attached when the message is created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace System.Agents;

using System.Agents.Troubleshooting;
using System.Environment;
using System.Environment.Consumption;
using System.Integration;

codeunit 4300 "Agent Task Impl."
Expand Down Expand Up @@ -152,6 +153,18 @@ codeunit 4300 "Agent Task Impl."
exit((AgentTask.Status = AgentTask.Status::"Stopped by User") or (AgentTask.Status = AgentTask.Status::"Stopped by System"));
end;

procedure GetCopilotCreditsConsumed(AgentTaskID: BigInteger): Decimal
var
AgentTask: Record "Agent Task";
UserAIConsumptionData: Record "User AI Consumption Data";
begin
if not AgentTask.Get(AgentTaskID) then
exit(0);
UserAIConsumptionData.SetRange("Agent Task Id", AgentTask.ID);
UserAIConsumptionData.CalcSums("Copilot Credits");
exit(UserAIConsumptionData."Copilot Credits");
end;

internal procedure TryGetAgentRecordFromTaskId(TaskId: Integer; var Agent: Record Agent): Boolean
var
AgentTask: Record "Agent Task";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ codeunit 4311 "Agent Task Msg. Builder Impl."

[Scope('OnPrem')]
procedure AddAttachment(var AgentTaskFile: Record "Agent Task File"): codeunit "Agent Task Msg. Builder Impl."
var
FileInStream: InStream;
begin
TempAgentTaskFileToAttach.Copy(AgentTaskFile);
TempAgentTaskFileToAttach.ID := TempAgentTaskFileToAttach.Count() + 1;
TempAgentTaskFileToAttach.Insert();
AgentTaskFile.CalcFields(Content);
AgentTaskFile.Content.CreateInStream(FileInStream);
AddAttachment(AgentTaskFile."File Name", AgentTaskFile."File MIME Type", FileInStream);
exit(this);
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,17 @@ codeunit 4301 "Agent Impl."
end;

procedure SelectAgent(var Agent: Record "Agent")
begin
SelectAgent(Agent, false);
end;

procedure SelectAgent(var Agent: Record "Agent"; AlwaysShowUI: Boolean)
begin
Agent.SetRange(State, Agent.State::Enabled);
if Agent.Count() = 0 then
Error(NoActiveAgentsErr);

if Agent.Count() = 1 then begin
if (Agent.Count() = 1) and (not AlwaysShowUI) then begin
Agent.FindFirst();
exit;
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ codeunit 4324 "Agent Setup"
exit(AgentSetupImpl.OpenAgentLookup(AgentUserSecurityId));
end;

/// <summary>
/// Finds the agent user security ID based on the provided user name.
/// </summary>
/// <param name="AgentUserName">The user name to search for. You can provide a partial or full user name.</param>
/// <param name="AgentUserSecurityId">The security ID of the agent user if found, otherwise a null guid.</param>
/// <returns>True if an agent with the provided user name is found, false otherwise.</returns>
procedure FindAgentByUserName(AgentUserName: Text; var AgentUserSecurityId: Guid): Boolean
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
exit(AgentSetupImpl.FindAgentByUserName(AgentUserName, AgentUserSecurityId));
end;

/// <summary>
/// Allows the user to select an agent out of the list of enabled agents.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ codeunit 4325 "Agent Setup Impl."
AgentImpl.OpenSetupPageId(Agent."Agent Metadata Provider", AgentUserSecurityID);
end;

[Scope('OnPrem')]
procedure FindAgentByUserName(AgentUserName: Text; var AgentUserSecurityId: Guid): Boolean
var
AgentRec: Record Agent;
begin
AgentRec.SetRange("User Name", AgentUserName);
if AgentRec.FindFirst() then begin
AgentUserSecurityId := AgentRec."User Security ID";
exit(true);
end;

AgentRec.SetFilter("User Name", '@' + AgentUserName + '*');
if AgentRec.FindFirst() then begin
AgentUserSecurityId := AgentRec."User Security ID";
AgentUserName := AgentRec."User Name";
exit(true);
end;

exit(false);
end;

[Scope('OnPrem')]
procedure OpenAgentLookup(var AgentUserSecurityId: Guid): Boolean
var
Expand Down
7 changes: 7 additions & 0 deletions src/Tools/AI Test Toolkit/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
"version": "28.0.0.0"
}
],
"internalsVisibleTo": [
{
"id": "5afe217e-507a-40b4-9aa5-f4325b6e8230",
"name": "Agent Test Library",
"publisher": "Microsoft"
}
],
"screenshots": [],
"platform": "28.0.0.0",
"idRanges": [
Expand Down
16 changes: 16 additions & 0 deletions src/Tools/AI Test Toolkit/src/API/AITLogEntryAPI.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ page 149038 "AIT Log Entry API"
{
Caption = 'Total Tokens Consumed';
}
field(copilotCredits; CopilotCredits)
{
Caption = 'Copilot credits';
Editable = false;
}
field(agentTaskIDs; AgentTaskIDs)
{
Caption = 'Agent tasks';
Editable = false;
}
field("startTime"; Rec."Start Time")
{
Caption = 'Start Time';
Expand Down Expand Up @@ -127,13 +137,17 @@ page 149038 "AIT Log Entry API"
}

trigger OnAfterGetRecord()
var
AgentTestContextImpl: Codeunit "Agent Test Context Impl.";
begin
InputText := Rec.GetInputBlob();
OutputText := Rec.GetOutputBlob();
MessageTxt := Rec.GetMessage();
ErrorCallStackText := Rec.GetErrorCallStack();
SuiteDescription := Rec.GetSuiteDescription();
TestMethodLineDescription := Rec.GetTestMethodLineDescription();
CopilotCredits := AgentTestContextImpl.GetCopilotCreditsForLogEntry(Rec."Entry No.");
AgentTaskIDs := AgentTestContextImpl.GetAgentTaskIDsForLogEntry(Rec."Entry No.");
end;

var
Expand All @@ -143,4 +157,6 @@ page 149038 "AIT Log Entry API"
ErrorCallStackText: Text;
SuiteDescription: Text[250];
TestMethodLineDescription: Text[250];
CopilotCredits: Decimal;
AgentTaskIDs: Text;
}
54 changes: 54 additions & 0 deletions src/Tools/AI Test Toolkit/src/Agent/AgentLogEntries.PageExt.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.TestTools.AITestToolkit;

pageextension 149030 "Agent Log Entries" extends "AIT Log Entries"
{
layout
{
addafter("Tokens Consumed")
{
field("Copilot Credits"; CopilotCredits)
{
ApplicationArea = All;
AutoFormatType = 0;
Caption = 'Copilot credits';
ToolTip = 'Specifies the total Copilot Credits consumed by the Agent Tasks for this log entry.';
Editable = false;
}
field("Agent Task IDs"; AgentTaskIDs)
{
ApplicationArea = All;
Caption = 'Agent tasks';
ToolTip = 'Specifies the comma-separated list of Agent Task IDs related to this log entry.';
Editable = false;

trigger OnDrillDown()
var
AgentTestContextImpl: Codeunit "Agent Test Context Impl.";
begin
AgentTestContextImpl.OpenAgentTaskList(AgentTaskIDs);
end;
}
}
}

trigger OnAfterGetRecord()
begin
UpdateAgentTaskMetrics();
end;

local procedure UpdateAgentTaskMetrics()
begin
CopilotCredits := AgentTestContextImpl.GetCopilotCreditsForLogEntry(Rec."Entry No.");
AgentTaskIDs := AgentTestContextImpl.GetAgentTaskIDsForLogEntry(Rec."Entry No.");
end;

var
AgentTestContextImpl: Codeunit "Agent Test Context Impl.";
CopilotCredits: Decimal;
AgentTaskIDs: Text;
}
90 changes: 90 additions & 0 deletions src/Tools/AI Test Toolkit/src/Agent/AgentRunHistory.PageExt.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.TestTools.AITestToolkit;

pageextension 149032 "Agent Run History" extends "AIT Run History"
{
layout
{
addafter("Tokens - By Version")
{
field("Copilot Credits - By Version"; Rec."Copilot Credits")
{
ApplicationArea = All;
AutoFormatType = 0;
Visible = ViewBy = ViewBy::Version;
Caption = 'Copilot credits';
ToolTip = 'Specifies the total Copilot Credits consumed by the Agent Tasks in the current version.';
Editable = false;
}
field("Agent Task Count - By Version"; AgentTaskCountByVersion)
{
ApplicationArea = All;
Visible = ViewBy = ViewBy::Version;
Caption = 'Agent tasks';
ToolTip = 'Specifies the number of Agent Tasks related to the current version.';
Editable = false;

trigger OnDrillDown()
var
AgentTestContextImpl: Codeunit "Agent Test Context Impl.";
begin
AgentTestContextImpl.OpenAgentTaskList(Rec."Agent Task IDs");
end;
}
}
addafter("Tokens - By Tag")
{
field("Copilot Credits - By Tag"; Rec."Copilot Credits - By Tag")
{
ApplicationArea = All;
AutoFormatType = 0;
Visible = ViewBy = ViewBy::Tag;
Caption = 'Copilot credits';
ToolTip = 'Specifies the total Copilot Credits consumed by the Agent Tasks for the tag.';
Editable = false;
}
field("Agent Task Count - By Tag"; AgentTaskCountByTag)
{
ApplicationArea = All;
Visible = ViewBy = ViewBy::Tag;
Caption = 'Agent tasks';
ToolTip = 'Specifies the number of Agent Tasks related to the tag.';
Editable = false;

trigger OnDrillDown()
var
AgentTestContextImpl: Codeunit "Agent Test Context Impl.";
begin
AgentTestContextImpl.OpenAgentTaskList(Rec."Agent Task IDs - By Tag");
end;
}
}
}

trigger OnAfterGetRecord()
begin
UpdateAgentTaskCounts();
end;

trigger OnAfterGetCurrRecord()
begin
UpdateAgentTaskCounts();
end;

local procedure UpdateAgentTaskCounts()
begin
AgentTaskCountByVersion := AgentTestContextImpl.GetAgentTaskCount(Rec."Agent Task IDs");
AgentTaskCountByTag := AgentTestContextImpl.GetAgentTaskCount(Rec."Agent Task IDs - By Tag");
end;

var
AgentTestContextImpl: Codeunit "Agent Test Context Impl.";
AgentTaskCountByVersion: Integer;
AgentTaskCountByTag: Integer;

}

43 changes: 43 additions & 0 deletions src/Tools/AI Test Toolkit/src/Agent/AgentRunHistory.TableExt.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.TestTools.AITestToolkit;

tableextension 149030 "Agent Run History" extends "AIT Run History"
{
fields
{
field(15; "Copilot Credits"; Decimal)
{
DataClassification = SystemMetadata;
AutoFormatType = 0;
Caption = 'Copilot credits';
ToolTip = 'Specifies the total Copilot Credits consumed by the Agent Tasks in the current version.';
Editable = false;
}
field(16; "Agent Task IDs"; Text[2048])
{
DataClassification = SystemMetadata;
Caption = 'Agent tasks';
ToolTip = 'Specifies the comma-separated list of Agent Task IDs related to the current version.';
Editable = false;
}
field(25; "Copilot Credits - By Tag"; Decimal)
{
DataClassification = SystemMetadata;
AutoFormatType = 0;
Caption = 'Copilot credits';
ToolTip = 'Specifies the total Copilot Credits consumed by the Agent Tasks for the tag.';
Editable = false;
}
field(26; "Agent Task IDs - By Tag"; Text[2048])
{
DataClassification = SystemMetadata;
Caption = 'Agent tasks';
ToolTip = 'Specifies the comma-separated list of Agent Task IDs related to the tag.';
Editable = false;
}
}
}
Loading
Loading