diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/TokenStatistics.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/TokenStatistics.cs index 9fa5c7185..8387e1872 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/TokenStatistics.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/TokenStatistics.cs @@ -60,12 +60,13 @@ public void AddToken(TokenStatsModel stats, RoleDialogModel message) stat.SetState("llm_total_cost", total_cost, isNeedVersion: false, source: StateSource.Application); // Save stats + var agentId = message.CurrentAgentId ?? string.Empty; var globalStats = _services.GetRequiredService(); var body = new BotSharpStatsInput { Metric = StatsMetric.AgentLlmCost, Dimension = "agent", - DimRefVal = message.CurrentAgentId, + DimRefVal = agentId, RecordTime = DateTime.UtcNow, IntervalType = StatsInterval.Day, Data = [ @@ -75,7 +76,7 @@ public void AddToken(TokenStatsModel stats, RoleDialogModel message) new StatsKeyValuePair("completion_cost_total", deltaCompletionCost) ] }; - globalStats.UpdateStats("global-llm-cost", body); + globalStats.UpdateStats($"global-llm-cost-{agentId}", body); } public void PrintStatistics() diff --git a/src/Infrastructure/BotSharp.Logger/Hooks/GlobalStatsConversationHook.cs b/src/Infrastructure/BotSharp.Logger/Hooks/GlobalStatsConversationHook.cs index 2cc2c9fbd..34fda9634 100644 --- a/src/Infrastructure/BotSharp.Logger/Hooks/GlobalStatsConversationHook.cs +++ b/src/Infrastructure/BotSharp.Logger/Hooks/GlobalStatsConversationHook.cs @@ -25,17 +25,18 @@ private void UpdateAgentCall(RoleDialogModel message) // record agent call var globalStats = _services.GetRequiredService(); + var agentId = message.CurrentAgentId ?? string.Empty; var body = new BotSharpStatsInput { Metric = StatsMetric.AgentCall, Dimension = "agent", - DimRefVal = message.CurrentAgentId ?? string.Empty, + DimRefVal = agentId, RecordTime = DateTime.UtcNow, IntervalType = StatsInterval.Day, Data = [ new StatsKeyValuePair("agent_call_count", 1) ] }; - globalStats.UpdateStats("global-agent-call", body); + globalStats.UpdateStats($"global-agent-call-{agentId}", body); } }