@elizaos/training 2.0.0-alpha.21 → 2.0.0-alpha.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/.turbo/turbo-lint.log +2 -0
  2. package/.turbo/turbo-typecheck.log +1 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/adapter.js +59 -0
  5. package/dist/archetypes/ArchetypeConfigService.js +510 -0
  6. package/dist/archetypes/derive-archetype.js +196 -0
  7. package/dist/archetypes/index.js +7 -0
  8. package/dist/benchmark/ArchetypeMatchupBenchmark.js +547 -0
  9. package/dist/benchmark/BenchmarkChartGenerator.js +632 -0
  10. package/dist/benchmark/BenchmarkDataGenerator.js +825 -0
  11. package/dist/benchmark/BenchmarkDataViewer.js +197 -0
  12. package/dist/benchmark/BenchmarkHistoryService.js +135 -0
  13. package/dist/benchmark/BenchmarkRunner.js +483 -0
  14. package/dist/benchmark/BenchmarkValidator.js +158 -0
  15. package/dist/benchmark/FastEvalRunner.js +133 -0
  16. package/dist/benchmark/MetricsValidator.js +104 -0
  17. package/dist/benchmark/MetricsVisualizer.js +775 -0
  18. package/dist/benchmark/ModelBenchmarkService.js +433 -0
  19. package/dist/benchmark/ModelRegistry.js +122 -0
  20. package/dist/benchmark/RulerBenchmarkIntegration.js +168 -0
  21. package/dist/benchmark/SimulationA2AInterface.js +683 -0
  22. package/dist/benchmark/SimulationEngine.js +522 -0
  23. package/dist/benchmark/TaskRunner.js +60 -0
  24. package/dist/benchmark/__tests__/BenchmarkRunner.test.js +409 -0
  25. package/dist/benchmark/__tests__/HeadToHead.test.js +105 -0
  26. package/dist/benchmark/index.js +23 -0
  27. package/dist/benchmark/parseSimulationMetrics.js +86 -0
  28. package/dist/benchmark/simulation-types.js +1 -0
  29. package/dist/dependencies.js +197 -0
  30. package/dist/generation/TrajectoryGenerator.js +244 -0
  31. package/dist/generation/index.js +6 -0
  32. package/dist/huggingface/HuggingFaceDatasetUploader.js +463 -0
  33. package/dist/huggingface/HuggingFaceIntegrationService.js +272 -0
  34. package/dist/huggingface/HuggingFaceModelUploader.js +385 -0
  35. package/dist/huggingface/index.js +9 -0
  36. package/dist/huggingface/shared/HuggingFaceUploadUtil.js +144 -0
  37. package/dist/index.js +41 -0
  38. package/dist/init-training.js +43 -0
  39. package/dist/metrics/TrajectoryMetricsExtractor.js +523 -0
  40. package/dist/metrics/__tests__/TrajectoryMetricsExtractor.test.js +628 -0
  41. package/dist/metrics/index.js +7 -0
  42. package/dist/metrics/types.js +21 -0
  43. package/dist/rubrics/__tests__/index.test.js +150 -0
  44. package/dist/rubrics/ass-kisser.js +83 -0
  45. package/dist/rubrics/degen.js +78 -0
  46. package/dist/rubrics/goody-twoshoes.js +82 -0
  47. package/dist/rubrics/index.js +184 -0
  48. package/dist/rubrics/information-trader.js +82 -0
  49. package/dist/rubrics/infosec.js +99 -0
  50. package/dist/rubrics/liar.js +102 -0
  51. package/dist/rubrics/perps-trader.js +85 -0
  52. package/dist/rubrics/researcher.js +79 -0
  53. package/dist/rubrics/scammer.js +80 -0
  54. package/dist/rubrics/social-butterfly.js +71 -0
  55. package/dist/rubrics/super-predictor.js +95 -0
  56. package/dist/rubrics/trader.js +65 -0
  57. package/dist/scoring/ArchetypeScoringService.js +301 -0
  58. package/dist/scoring/JudgePromptBuilder.js +401 -0
  59. package/dist/scoring/LLMJudgeCache.js +263 -0
  60. package/dist/scoring/index.js +8 -0
  61. package/dist/training/AutomationPipeline.js +714 -0
  62. package/dist/training/BenchmarkService.js +370 -0
  63. package/dist/training/ConfigValidator.js +153 -0
  64. package/dist/training/MarketOutcomesTracker.js +142 -0
  65. package/dist/training/ModelDeployer.js +128 -0
  66. package/dist/training/ModelFetcher.js +48 -0
  67. package/dist/training/ModelSelectionService.js +248 -0
  68. package/dist/training/ModelUsageVerifier.js +106 -0
  69. package/dist/training/MultiModelOrchestrator.js +349 -0
  70. package/dist/training/RLModelConfig.js +295 -0
  71. package/dist/training/RewardBackpropagationService.js +117 -0
  72. package/dist/training/RulerScoringService.js +450 -0
  73. package/dist/training/TrainingMonitor.js +108 -0
  74. package/dist/training/TrajectoryRecorder.js +281 -0
  75. package/dist/training/__tests__/TrajectoryRecorder.test.js +363 -0
  76. package/dist/training/index.js +30 -0
  77. package/dist/training/logRLConfig.js +29 -0
  78. package/dist/training/pipeline.js +80 -0
  79. package/dist/training/storage/ModelStorageService.js +190 -0
  80. package/dist/training/storage/TrainingDataArchiver.js +136 -0
  81. package/dist/training/storage/index.js +7 -0
  82. package/dist/training/types.js +6 -0
  83. package/dist/training/window-utils.js +100 -0
  84. package/dist/utils/index.js +73 -0
  85. package/dist/utils/logger.js +55 -0
  86. package/dist/utils/snowflake.js +15 -0
  87. package/dist/utils/synthetic-detector.js +67 -0
  88. package/package.json +2 -2
  89. package/research-output/training-runs/training-run-1773742857616.json +38 -0
  90. package/research-output/training-runs/training-run-1773742946977.json +38 -0
  91. package/research-output/training-runs/training-run-1773743278891.json +38 -0
  92. package/research-output/training-runs/training-run-1773743409754.json +38 -0
  93. package/research-output/training-runs/training-run-1773743651086.json +38 -0
  94. package/research-output/training-runs/training-run-1773743782883.json +38 -0
@@ -0,0 +1,144 @@
1
+ /**
2
+ * HuggingFace Upload Utility
3
+ *
4
+ * Shared utility for uploading files to HuggingFace Hub.
5
+ * Consolidates upload logic used across different services.
6
+ */
7
+ import { exec } from "node:child_process";
8
+ import { promises as fs } from "node:fs";
9
+ import * as path from "node:path";
10
+ import { promisify } from "node:util";
11
+ import * as hubModule from "@huggingface/hub";
12
+ import { logger } from "../../utils/logger";
13
+ /**
14
+ * Get HuggingFace token from environment variables
15
+ *
16
+ * Checks both HUGGING_FACE_TOKEN and HF_TOKEN for compatibility
17
+ * with different HuggingFace tooling conventions.
18
+ *
19
+ * @returns Token string or undefined if not set
20
+ */
21
+ export function getHuggingFaceToken() {
22
+ return process.env.HUGGING_FACE_TOKEN || process.env.HF_TOKEN;
23
+ }
24
+ /**
25
+ * Get HuggingFace token or throw error if not set
26
+ *
27
+ * @throws Error if token is not configured
28
+ * @returns Token string
29
+ */
30
+ export function requireHuggingFaceToken() {
31
+ const token = getHuggingFaceToken();
32
+ if (!token) {
33
+ throw new Error("HuggingFace token not configured. Set HUGGING_FACE_TOKEN or HF_TOKEN environment variable.");
34
+ }
35
+ return token;
36
+ }
37
+ /**
38
+ * Upload a single file to HuggingFace Hub
39
+ */
40
+ export async function uploadFileToHub(repoName, repoType, filePath, fileContent, token) {
41
+ const uploadFile = hubModule.uploadFile;
42
+ await uploadFile({
43
+ repo: { type: repoType, name: repoName },
44
+ file: {
45
+ path: filePath,
46
+ content: new Blob([fileContent]),
47
+ },
48
+ credentials: {
49
+ accessToken: token,
50
+ },
51
+ });
52
+ logger.info(`Uploaded ${filePath} to ${repoName}`, {
53
+ repo: repoName,
54
+ type: repoType,
55
+ });
56
+ }
57
+ /**
58
+ * Upload directory to HuggingFace Hub
59
+ */
60
+ export async function uploadDirectoryToHub(repoName, repoType, localDir, token) {
61
+ const files = await fs.readdir(localDir);
62
+ let uploadCount = 0;
63
+ for (const file of files) {
64
+ const filePath = path.join(localDir, file);
65
+ const stats = await fs.stat(filePath);
66
+ if (stats.isFile()) {
67
+ const content = await fs.readFile(filePath, "utf-8");
68
+ await uploadFileToHub(repoName, repoType, file, content, token);
69
+ uploadCount++;
70
+ }
71
+ }
72
+ logger.info(`Uploaded ${uploadCount} files to ${repoName}`, {
73
+ repo: repoName,
74
+ count: uploadCount,
75
+ });
76
+ return uploadCount;
77
+ }
78
+ /**
79
+ * Ensure repository exists (create if needed)
80
+ */
81
+ export async function ensureHubRepository(repoName, repoType, token, isPrivate = false) {
82
+ const createRepo = hubModule.createRepo;
83
+ try {
84
+ await createRepo({
85
+ repo: { type: repoType, name: repoName },
86
+ credentials: { accessToken: token },
87
+ private: isPrivate,
88
+ });
89
+ logger.info("Created new repository", { repo: repoName, type: repoType });
90
+ }
91
+ catch (error) {
92
+ // Repository might already exist, which is fine
93
+ if (error instanceof Error &&
94
+ (error.message.includes("already exists") ||
95
+ error.message.includes("Repository not found"))) {
96
+ logger.info("Repository already exists or accessible", {
97
+ repo: repoName,
98
+ });
99
+ }
100
+ else {
101
+ logger.warn("Could not ensure repository exists", {
102
+ error,
103
+ repo: repoName,
104
+ });
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ * Upload using huggingface-cli (fallback method)
110
+ */
111
+ export async function uploadViaCLI(repoName, repoType, localDir, token) {
112
+ try {
113
+ const execAsync = promisify(exec);
114
+ // Set token as environment variable
115
+ process.env.HUGGINGFACE_HUB_TOKEN = token;
116
+ console.log(`Uploading ${localDir} to ${repoName} via huggingface-cli...`);
117
+ await execAsync(`huggingface-cli upload ${repoName} ${localDir} --repo-type ${repoType}`);
118
+ logger.info("Successfully uploaded via huggingface-cli", {
119
+ repo: repoName,
120
+ });
121
+ }
122
+ catch (error) {
123
+ logger.error("CLI upload failed", { error });
124
+ throw error;
125
+ }
126
+ }
127
+ /**
128
+ * Provide manual upload instructions
129
+ */
130
+ export function getManualUploadInstructions(repoName, repoType, localDir) {
131
+ return [
132
+ "1. Install huggingface-cli: pip install huggingface_hub",
133
+ "2. Login: huggingface-cli login",
134
+ `3. Upload: huggingface-cli upload ${repoName} ${localDir} --repo-type ${repoType}`,
135
+ ];
136
+ }
137
+ /** @deprecated Use uploadFileToHub, uploadDirectoryToHub, etc. instead */
138
+ export const HuggingFaceUploadUtil = {
139
+ uploadFile: uploadFileToHub,
140
+ uploadDirectory: uploadDirectoryToHub,
141
+ ensureRepository: ensureHubRepository,
142
+ uploadViaCLI,
143
+ getManualUploadInstructions,
144
+ };
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * ElizaOS Training Package
3
+ *
4
+ * A reusable RL training pipeline for agent trajectories including:
5
+ * - Benchmarking and evaluation
6
+ * - Automated training orchestration
7
+ * - HuggingFace publishing helpers
8
+ * - Archetype-aware scoring utilities
9
+ *
10
+ * ## Setup
11
+ *
12
+ * Before using training operations, register a data adapter:
13
+ *
14
+ * ```ts
15
+ * import { setTrainingDataAdapter } from '@elizaos/training';
16
+ * setTrainingDataAdapter(myDrizzleAdapter);
17
+ * ```
18
+ *
19
+ * @packageDocumentation
20
+ */
21
+ // Data adapter (must be registered before DB-dependent operations)
22
+ export { getLlmLogAdapter, getMarketDataAdapter, getTrainingDataAdapter, isDataAdapterRegistered, resetAdapters, setLlmLogAdapter, setMarketDataAdapter, setTrainingDataAdapter, } from "./adapter";
23
+ // Archetypes
24
+ export * from "./archetypes";
25
+ // Re-export all sub-modules
26
+ export * from "./benchmark";
27
+ // Dependencies configuration
28
+ export { areAgentDependenciesConfigured, areDependenciesConfigured, configureTrainingDependencies, getAgentRuntimeManager, getAgentService, getAutonomousCoordinator, getExportGroupedForGRPO, getExportToHuggingFace, getLLMCaller, getToTrainingMessages, } from "./dependencies";
29
+ // Generation
30
+ export * from "./generation";
31
+ export * from "./huggingface";
32
+ // Training initialization
33
+ export { initializeTrainingPackage, isTrainingInitialized, resetTrainingInitialization, } from "./init-training";
34
+ // Metrics (re-export for backwards compatibility, prefer import from './metrics')
35
+ export * from "./metrics";
36
+ export * from "./rubrics";
37
+ export * from "./scoring";
38
+ export * from "./training";
39
+ export { benchmarkAndMaybeDeployModel, checkTrainingReadiness, deployModelVersion, getAutomationPipelineStatus, getNextTrainingModelSelection, monitorTrainingJob, rollbackModelVersion, triggerTraining, } from "./training/pipeline";
40
+ // Utilities
41
+ export * from "./utils";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Training Package Initialization
3
+ *
4
+ * This module sets up all dependencies required by the training package.
5
+ * Import this before using TrajectoryGenerator or other training services.
6
+ *
7
+ * Usage:
8
+ * import { configureTrainingDependencies, initializeTrainingPackage } from '@elizaos/training';
9
+ * configureTrainingDependencies({ ... });
10
+ * await initializeTrainingPackage();
11
+ */
12
+ import { areDependenciesConfigured } from "./dependencies";
13
+ import { logger } from "./utils/logger";
14
+ let initialized = false;
15
+ /**
16
+ * Initialize training package.
17
+ *
18
+ * External dependencies must be configured first via `configureTrainingDependencies`.
19
+ */
20
+ export async function initializeTrainingPackage() {
21
+ if (initialized) {
22
+ logger.debug("Training package already initialized", {}, "TrainingInit");
23
+ return;
24
+ }
25
+ logger.info("Initializing training package...", {}, "TrainingInit");
26
+ if (!areDependenciesConfigured()) {
27
+ throw new Error("Training dependencies not configured. Call configureTrainingDependencies() first.");
28
+ }
29
+ initialized = true;
30
+ logger.info("Training package initialized successfully", {}, "TrainingInit");
31
+ }
32
+ /**
33
+ * Check if training package is initialized
34
+ */
35
+ export function isTrainingInitialized() {
36
+ return initialized;
37
+ }
38
+ /**
39
+ * Reset initialization state (for testing)
40
+ */
41
+ export function resetTrainingInitialization() {
42
+ initialized = false;
43
+ }