Skip to content

Commit 5c90f2c

Browse files
authored
Merge pull request #905 from iceljc/master
add agent id in resource key
2 parents b5eade4 + 152811c commit 5c90f2c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ 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 agentId = message.CurrentAgentId ?? string.Empty;
6364
var globalStats = _services.GetRequiredService<IBotSharpStatsService>();
6465
var body = new BotSharpStatsInput
6566
{
6667
Metric = StatsMetric.AgentLlmCost,
6768
Dimension = "agent",
68-
DimRefVal = message.CurrentAgentId,
69+
DimRefVal = agentId,
6970
RecordTime = DateTime.UtcNow,
7071
IntervalType = StatsInterval.Day,
7172
Data = [
@@ -75,7 +76,7 @@ public void AddToken(TokenStatsModel stats, RoleDialogModel message)
7576
new StatsKeyValuePair("completion_cost_total", deltaCompletionCost)
7677
]
7778
};
78-
globalStats.UpdateStats("global-llm-cost", body);
79+
globalStats.UpdateStats($"global-llm-cost-{agentId}", body);
7980
}
8081

8182
public void PrintStatistics()

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

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

28+
var agentId = message.CurrentAgentId ?? string.Empty;
2829
var body = new BotSharpStatsInput
2930
{
3031
Metric = StatsMetric.AgentCall,
3132
Dimension = "agent",
32-
DimRefVal = message.CurrentAgentId ?? string.Empty,
33+
DimRefVal = agentId,
3334
RecordTime = DateTime.UtcNow,
3435
IntervalType = StatsInterval.Day,
3536
Data = [
3637
new StatsKeyValuePair("agent_call_count", 1)
3738
]
3839
};
39-
globalStats.UpdateStats("global-agent-call", body);
40+
globalStats.UpdateStats($"global-agent-call-{agentId}", body);
4041
}
4142
}

0 commit comments

Comments
 (0)