onRunEnd method
Called when a dataset run completes. Implementations may use this hook to record run-level aggregate scores (pass@k, F1 …).
Implementation
@override
Future<void> onRunEnd({
required String runName,
required String suiteName,
required Map<String, double> aggregateScores,
}) async {
// 给 run 整体建一个 summary trace,把所有 aggregate score 挂上去。
// 这样在 langfuse dashboard 可以按 userId=runName 筛出整次跑的概览。
final summaryTraceId = _uuid.v4();
final now = DateTime.now();
_client.enqueue(
LangfuseEvent(
id: _uuid.v4(),
type: 'trace-create',
timestamp: now,
body: {
'id': summaryTraceId,
'timestamp': now.toUtc().toIso8601String(),
'name': 'run-summary:$suiteName',
'environment': config.environment,
'userId': runName,
'sessionId': suiteName,
'tags': ['summary', 'run:$runName', 'suite:$suiteName'],
'metadata': {'aggregateScores': aggregateScores},
},
),
);
for (final entry in aggregateScores.entries) {
_client.enqueue(
LangfuseEvent(
id: _uuid.v4(),
type: 'score-create',
timestamp: now,
body: {
'id': _uuid.v4(),
'traceId': summaryTraceId,
'environment': config.environment,
'name': entry.key,
'value': entry.value,
'dataType': 'NUMERIC',
},
),
);
}
}