Skip to content
Draft
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 @@ -137,15 +137,15 @@ codeunit 4303 "Agent Task"
end;

/// <summary>
/// Gets the total Copilot credits consumed by the agent task.
/// Gets the details for the specified agent task log entry.
/// </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
/// <param name="AgentTaskLogEntry">The agent task log entry to get details for.</param>
/// <returns>The details of the agent task log entry.</returns>
procedure GetDetailsForAgentTaskLogEntry(var AgentTaskLogEntry: Record "Agent Task Log Entry"): Text
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
exit(AgentTaskImpl.GetCopilotCreditsConsumed(AgentTaskID));
exit(AgentTaskImpl.GetDetailsForAgentTaskLogEntry(AgentTaskLogEntry));
end;

var
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ namespace System.Agents;

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

codeunit 4300 "Agent Task Impl."
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;
Permissions = tabledata "User AI Consumption Data" = r;

procedure SetMessageText(var AgentTaskMessage: Record "Agent Task Message"; MessageText: Text)
var
Expand Down Expand Up @@ -154,18 +152,6 @@ 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 @@ -108,18 +108,16 @@ page 4300 "Agent Task List"
}
field(Credits; ConsumedCredits)
{
Visible = ConsumedCreditsVisible;
Caption = 'Copilot credits';
ToolTip = 'Specifies the number of Copilot credits consumed by the agent task.';
AutoFormatType = 0;
DecimalPlaces = 0 : 2;

trigger OnDrillDown()
var
UserAIConsumptionData: Record "User AI Consumption Data";
AgentConsumptionOverview: Codeunit "Agent Consumption Overview";
begin
UserAIConsumptionData.SetRange("Agent Task Id", Rec.ID);
Page.Run(Page::"Agent Consumption Overview", UserAIConsumptionData);
AgentConsumptionOverview.OpenAgentTaskConsumptionOverview(Rec.ID);
end;
}
}
Expand Down Expand Up @@ -205,13 +203,6 @@ page 4300 "Agent Task List"
}
}

trigger OnOpenPage()
var
AgentSystemPermissions: Codeunit "Agent System Permissions";
begin
ConsumedCreditsVisible := AgentSystemPermissions.CurrentUserCanSeeConsumptionData();
end;

trigger OnAfterGetRecord()
begin
UpdateControls();
Expand All @@ -226,16 +217,9 @@ page 4300 "Agent Task List"

local procedure CalculateTaskConsumedCredits()
var
UserAIConsumptionData: Record "User AI Consumption Data";
AgentConsumptionOverview: Codeunit "Agent Consumption Overview";
begin
if not ConsumedCreditsVisible then begin
Clear(ConsumedCredits);
exit;
end;

UserAIConsumptionData.SetRange("Agent Task Id", Rec.ID);
UserAIConsumptionData.CalcSums("Copilot Credits");
ConsumedCredits := UserAIConsumptionData."Copilot Credits";
ConsumedCredits := AgentConsumptionOverview.GetCopilotCreditsConsumed(Rec.ID);
end;

local procedure UpdateControls()
Expand All @@ -258,5 +242,4 @@ page 4300 "Agent Task List"
NumberOfStepsDone: Integer;
TaskSelected: Boolean;
ConsumedCredits: Decimal;
ConsumedCreditsVisible: Boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.Agents;
using System.Environment.Consumption;

codeunit 4333 "Agent Consumption Overview"
{
InherentEntitlements = X;
InherentPermissions = X;
Permissions = tabledata "Agent Task" = r,
tabledata "User AI Consumption Data" = r;

/// <summary>
/// Gets the total Copilot credits consumed by the agent task.
/// </summary>
/// <param name="TaskId">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(TaskId: BigInteger): Decimal
var
UserAIConsumptionData: Record "User AI Consumption Data";
begin
UserAIConsumptionData.SetRange("Agent Task Id", TaskId);
UserAIConsumptionData.CalcSums("Copilot Credits");
exit(UserAIConsumptionData."Copilot Credits");
end;

/// <summary>
/// Opens the agent consumption overview page for the specified agent.
/// </summary>
/// <param name="AgentUserSecurityId">The agent user security ID.</param>
procedure OpenAgentConsumptionOverview(AgentUserSecurityId: Guid)
var
AgentTaskConsumption: Record "Agent Task Consumption";
begin
AgentTaskConsumption.SetRange("Agent User Security ID", AgentUserSecurityId);
Page.Run(Page::"Agent Consumption Overview", AgentTaskConsumption);
end;

/// <summary>
/// Opens the agent consumption overview page for the specified agent task.
/// </summary>
/// <param name="TaskId">The ID of the agent task.</param>
procedure OpenAgentTaskConsumptionOverview(TaskId: BigInteger)
var
AgentTaskConsumption: Record "Agent Task Consumption";
begin
AgentTaskConsumption.SetRange("Task ID", TaskId);
Page.Run(Page::"Agent Consumption Overview", AgentTaskConsumption);
end;

/// <summary>
/// Opens the agent consumption overview page for the agent tasks matching the specified filter.
/// </summary>
/// <param name="TaskIDFilter">The filter for the agent task IDs.</param>
procedure OpenAgentTaskConsumptionOverview(TaskIDFilter: Text)
var
AgentTaskConsumption: Record "Agent Task Consumption";
AgentConsumptionOverview: Page "Agent Consumption Overview";
begin
AgentTaskConsumption.SetFilter("Task ID", TaskIDFilter);
AgentConsumptionOverview.SetTableView(AgentTaskConsumption);
AgentConsumptionOverview.Run();
end;
}
Loading
Loading