import 'dart:convert'; import 'dart:io'; import 'package:cutdex_agent/cutdex_agent.dart'; void main(List args) { const usage = 'Usage: dart run tool/diagnostics/benchmark_agent_context.dart '; if (args.length == 1 && (args.single == '--help' || args.single == '-h')) { stdout.writeln(usage); return; } if (args.length != 1) { stderr.writeln(usage); exitCode = 2; return; } final history = (jsonDecode(File(args[0]).readAsStringSync()) as List) .map( (m) => AgentMessage.fromJson( Map.from(m as Map), ), ) .toList(); final builder = HarnessContextBuilder(); final current = builder.projectHistory(history); final result = { 'messages': history.length, 'fullHistoryTokens': builder.measureInput(system: '', history: history), 'projectedHistoryTokens': builder.measureInput( system: '', history: current, ), 'originalBytes': jsonEncode(history.map((m) => m.toJson()).toList()).length, 'projectedBytes': jsonEncode(current.map((m) => m.toJson()).toList()) .length, }; stdout.writeln(const JsonEncoder.withIndent(' ').convert(result)); }