Skip to content

Commit ab725dd

Browse files
authored
Merge pull request #908 from iceljc/master
Refine global stats lock key
2 parents 0ace41e + 64831f5 commit ab725dd

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Infrastructure/BotSharp.Core/Conversations/Services/TokenStatistics.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ public void AddToken(TokenStatsModel stats, RoleDialogModel message)
6060
stat.SetState("llm_total_cost", total_cost, isNeedVersion: false, source: StateSource.Application);
6161

6262
// Save stats
63+
var metric = StatsMetric.AgentLlmCost;
64+
var dim = "agent";
6365
var agentId = message.CurrentAgentId ?? string.Empty;
6466
var globalStats = _services.GetRequiredService<IBotSharpStatsService>();
6567
var body = new BotSharpStatsInput
6668
{
67-
Metric = StatsMetric.AgentLlmCost,
68-
Dimension = "agent",
69+
Metric = metric,
70+
Dimension = dim,
6971
DimRefVal = agentId,
7072
RecordTime = DateTime.UtcNow,
7173
IntervalType = StatsInterval.Day,
@@ -76,7 +78,7 @@ public void AddToken(TokenStatsModel stats, RoleDialogModel message)
7678
new StatsKeyValuePair("completion_cost_total", deltaCompletionCost)
7779
]
7880
};
79-
globalStats.UpdateStats($"global-llm-cost-{agentId}", body);
81+
globalStats.UpdateStats($"global-{metric}-{dim}-{agentId}", body);
8082
}
8183

8284
public void PrintStatistics()

src/Infrastructure/BotSharp.Logger/Hooks/GlobalStatsConversationHook.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@ private void UpdateAgentCall(RoleDialogModel message)
2525
// record agent call
2626
var globalStats = _services.GetRequiredService<IBotSharpStatsService>();
2727

28+
var metric = StatsMetric.AgentCall;
29+
var dim = "agent";
2830
var agentId = message.CurrentAgentId ?? string.Empty;
2931
var body = new BotSharpStatsInput
3032
{
31-
Metric = StatsMetric.AgentCall,
32-
Dimension = "agent",
33+
Metric = metric,
34+
Dimension = dim,
3335
DimRefVal = agentId,
3436
RecordTime = DateTime.UtcNow,
3537
IntervalType = StatsInterval.Day,
3638
Data = [
3739
new StatsKeyValuePair("agent_call_count", 1)
3840
]
3941
};
40-
globalStats.UpdateStats($"global-agent-call-{agentId}", body);
42+
globalStats.UpdateStats($"global-{metric}-{dim}-{agentId}", body);
4143
}
4244
}

0 commit comments

Comments
 (0)