@elizaos/training 2.0.0-alpha.11
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.
- package/Dockerfile +75 -0
- package/Makefile +374 -0
- package/README.md +346 -0
- package/config/rubrics.json +137 -0
- package/data/.gitkeep +0 -0
- package/data/degen/.gitkeep +2 -0
- package/data/trader/.gitkeep +2 -0
- package/docker-compose.test.yml +57 -0
- package/package.json +58 -0
- package/python/config/babylon_atropos.yaml +90 -0
- package/python/config/profiles/12gb.json +11 -0
- package/python/config/profiles/16gb.json +10 -0
- package/python/config/profiles/24gb.json +10 -0
- package/python/config/profiles/48gb.json +10 -0
- package/python/config/profiles/cpu.json +11 -0
- package/python/config/profiles/l40-2gpu-safe.json +20 -0
- package/python/config/profiles/l40-2gpu.json +22 -0
- package/python/config/profiles/l40-4gpu.json +21 -0
- package/python/config/profiles/l40.json +17 -0
- package/python/config/tinker_training.yaml +143 -0
- package/python/curriculum_state.json +165 -0
- package/python/env.template +86 -0
- package/python/env.training.template +46 -0
- package/python/pyproject.toml +41 -0
- package/python/requirements-ci.txt +31 -0
- package/python/requirements.txt +87 -0
- package/python/scripts/__init__.py +4 -0
- package/python/scripts/import_json_trajectories.py +412 -0
- package/python/scripts/local-finetune/README.md +63 -0
- package/python/scripts/local-finetune/ingest_and_score.py +139 -0
- package/python/scripts/local-finetune/merge_model.py +32 -0
- package/python/scripts/local-finetune/test_adapter.py +91 -0
- package/python/scripts/local-finetune/train_from_csv.py +132 -0
- package/python/scripts/merge_trajectories.py +318 -0
- package/python/scripts/run_ab_test.py +143 -0
- package/python/scripts/run_full_pipeline.py +544 -0
- package/python/scripts/run_tinker_training.py +192 -0
- package/python/scripts/run_training.py +914 -0
- package/python/scripts/test_judge.py +155 -0
- package/python/scripts/test_pipeline.py +356 -0
- package/python/scripts/test_trained_model.py +380 -0
- package/python/scripts/train_local.py +528 -0
- package/python/setup.py +20 -0
- package/python/src/__init__.py +190 -0
- package/python/src/data_bridge/__init__.py +24 -0
- package/python/src/data_bridge/converter.py +435 -0
- package/python/src/data_bridge/reader.py +393 -0
- package/python/src/models.py +283 -0
- package/python/src/training/__init__.py +605 -0
- package/python/src/training/ab_testing.py +404 -0
- package/python/src/training/action_executor.py +621 -0
- package/python/src/training/archetype_trainer.py +347 -0
- package/python/src/training/atropos_trainer.py +980 -0
- package/python/src/training/babylon_env.py +1254 -0
- package/python/src/training/error_recovery.py +647 -0
- package/python/src/training/evaluation.py +856 -0
- package/python/src/training/fast_simulator.py +880 -0
- package/python/src/training/format_validator.py +584 -0
- package/python/src/training/hybrid_env.py +522 -0
- package/python/src/training/kl_controller.py +628 -0
- package/python/src/training/multi_prompt_dataset.py +883 -0
- package/python/src/training/multi_turn.py +656 -0
- package/python/src/training/online_env.py +1084 -0
- package/python/src/training/quality_scorer.py +391 -0
- package/python/src/training/quality_utils.py +633 -0
- package/python/src/training/rewards.py +1344 -0
- package/python/src/training/rlaif_env.py +17 -0
- package/python/src/training/rollout_generator.py +502 -0
- package/python/src/training/rubric_loader.py +198 -0
- package/python/src/training/scenario_pool.py +1072 -0
- package/python/src/training/schemas.py +481 -0
- package/python/src/training/service_manager.py +552 -0
- package/python/src/training/simulation_bridge.py +535 -0
- package/python/src/training/tick_reward_attribution.py +399 -0
- package/python/src/training/tinker_client.py +575 -0
- package/python/src/training/tinker_trainer.py +646 -0
- package/python/src/training/tokenization_utils.py +402 -0
- package/python/tests/e2e/__init__.py +13 -0
- package/python/tests/e2e/conftest.py +258 -0
- package/python/tests/e2e/test_full_pipeline.py +643 -0
- package/python/tests/e2e/test_online_training_e2e.py +365 -0
- package/python/tests/integration/__init__.py +12 -0
- package/python/tests/integration/conftest.py +383 -0
- package/python/tests/integration/test_db_integration.py +649 -0
- package/python/tests/integration/test_json_mode_integration.py +554 -0
- package/python/tests/test_action_executor.py +594 -0
- package/python/tests/test_archetype_scoring.py +1027 -0
- package/python/tests/test_atropos_integration.py +360 -0
- package/python/tests/test_evaluation.py +727 -0
- package/python/tests/test_format_validator.py +486 -0
- package/python/tests/test_kl_controller.py +432 -0
- package/python/tests/test_lr_scheduler.py +579 -0
- package/python/tests/test_multi_turn.py +590 -0
- package/python/tests/test_online_env.py +519 -0
- package/python/tests/test_quality_scorer.py +474 -0
- package/python/tests/test_scenario_pool.py +735 -0
- package/python/tests/test_service_manager.py +585 -0
- package/python/tests/test_simulation_rollout.py +581 -0
- package/python/tests/test_tokenization_utils.py +501 -0
- package/python/tests/test_training_orchestrator.py +497 -0
- package/python/tests/test_training_output_structure.py +661 -0
- package/research-output/training-runs/training-run-1770772042899.json +26 -0
- package/research-output/training-runs/training-run-1770930079670.json +32 -0
- package/research-output/training-runs/training-run-1770930143700.json +44 -0
- package/research-output/training-runs/training-run-1770930183638.json +38 -0
- package/research-output/training-runs/training-run-1770930442049.json +38 -0
- package/research-output/training-runs/training-run-1770930793243.json +38 -0
- package/scripts/assess-training-data.ts +422 -0
- package/scripts/e2e-training-test.ts +550 -0
- package/scripts/export-rubrics.ts +64 -0
- package/scripts/generate-research-report.ts +1523 -0
- package/scripts/generate_dataset.sh +173 -0
- package/scripts/json-mode-benchmark.ts +399 -0
- package/scripts/real-archetype-benchmark.ts +210 -0
- package/scripts/run-baseline-comparison.ts +116 -0
- package/scripts/run-full-pipeline.ts +272 -0
- package/scripts/runpod_setup.sh +137 -0
- package/scripts/runpod_validate.sh +147 -0
- package/scripts/test-model-in-game.ts +955 -0
- package/scripts/test-scoring.ts +73 -0
- package/scripts/test-trained-model.ts +209 -0
- package/scripts/train-and-test.ts +824 -0
- package/scripts/verify-final.ts +118 -0
- package/src/adapter.ts +516 -0
- package/src/archetypes/ArchetypeConfigService.ts +626 -0
- package/src/archetypes/derive-archetype.ts +249 -0
- package/src/archetypes/index.ts +22 -0
- package/src/benchmark/ArchetypeMatchupBenchmark.ts +825 -0
- package/src/benchmark/BenchmarkChartGenerator.ts +748 -0
- package/src/benchmark/BenchmarkDataGenerator.ts +1288 -0
- package/src/benchmark/BenchmarkDataViewer.ts +324 -0
- package/src/benchmark/BenchmarkHistoryService.ts +221 -0
- package/src/benchmark/BenchmarkRunner.ts +685 -0
- package/src/benchmark/BenchmarkValidator.ts +206 -0
- package/src/benchmark/FastEvalRunner.ts +225 -0
- package/src/benchmark/MetricsValidator.ts +165 -0
- package/src/benchmark/MetricsVisualizer.ts +909 -0
- package/src/benchmark/ModelBenchmarkService.ts +611 -0
- package/src/benchmark/ModelRegistry.ts +158 -0
- package/src/benchmark/RulerBenchmarkIntegration.ts +235 -0
- package/src/benchmark/SimulationA2AInterface.ts +1169 -0
- package/src/benchmark/SimulationEngine.ts +832 -0
- package/src/benchmark/__tests__/BenchmarkRunner.test.ts +534 -0
- package/src/benchmark/__tests__/HeadToHead.test.ts +126 -0
- package/src/benchmark/index.ts +89 -0
- package/src/benchmark/parseSimulationMetrics.ts +124 -0
- package/src/benchmark/simulation-types.ts +78 -0
- package/src/dependencies.ts +439 -0
- package/src/generation/TrajectoryGenerator.ts +387 -0
- package/src/generation/index.ts +12 -0
- package/src/huggingface/HuggingFaceDatasetUploader.ts +636 -0
- package/src/huggingface/HuggingFaceIntegrationService.ts +426 -0
- package/src/huggingface/HuggingFaceModelUploader.ts +532 -0
- package/src/huggingface/index.ts +27 -0
- package/src/huggingface/shared/HuggingFaceUploadUtil.ts +206 -0
- package/src/index.ts +102 -0
- package/src/init-training.ts +53 -0
- package/src/metrics/TrajectoryMetricsExtractor.ts +653 -0
- package/src/metrics/__tests__/TrajectoryMetricsExtractor.test.ts +759 -0
- package/src/metrics/index.ts +8 -0
- package/src/metrics/types.ts +200 -0
- package/src/rubrics/__tests__/index.test.ts +184 -0
- package/src/rubrics/ass-kisser.ts +85 -0
- package/src/rubrics/degen.ts +80 -0
- package/src/rubrics/goody-twoshoes.ts +84 -0
- package/src/rubrics/index.ts +236 -0
- package/src/rubrics/information-trader.ts +84 -0
- package/src/rubrics/infosec.ts +101 -0
- package/src/rubrics/liar.ts +104 -0
- package/src/rubrics/perps-trader.ts +87 -0
- package/src/rubrics/researcher.ts +81 -0
- package/src/rubrics/scammer.ts +82 -0
- package/src/rubrics/social-butterfly.ts +73 -0
- package/src/rubrics/super-predictor.ts +97 -0
- package/src/rubrics/trader.ts +67 -0
- package/src/scoring/ArchetypeScoringService.ts +486 -0
- package/src/scoring/JudgePromptBuilder.ts +556 -0
- package/src/scoring/LLMJudgeCache.ts +401 -0
- package/src/scoring/index.ts +9 -0
- package/src/training/AutomationPipeline.ts +916 -0
- package/src/training/BenchmarkService.ts +518 -0
- package/src/training/ConfigValidator.ts +220 -0
- package/src/training/MarketOutcomesTracker.ts +187 -0
- package/src/training/ModelDeployer.ts +186 -0
- package/src/training/ModelFetcher.ts +76 -0
- package/src/training/ModelSelectionService.ts +341 -0
- package/src/training/ModelUsageVerifier.ts +160 -0
- package/src/training/MultiModelOrchestrator.ts +580 -0
- package/src/training/RLModelConfig.ts +407 -0
- package/src/training/RewardBackpropagationService.ts +149 -0
- package/src/training/RulerScoringService.ts +666 -0
- package/src/training/TrainingMonitor.ts +166 -0
- package/src/training/TrajectoryRecorder.ts +399 -0
- package/src/training/__tests__/TrajectoryRecorder.test.ts +472 -0
- package/src/training/index.ts +100 -0
- package/src/training/logRLConfig.ts +34 -0
- package/src/training/pipeline.ts +129 -0
- package/src/training/storage/ModelStorageService.ts +279 -0
- package/src/training/storage/TrainingDataArchiver.ts +197 -0
- package/src/training/storage/index.ts +17 -0
- package/src/training/types.ts +207 -0
- package/src/training/window-utils.ts +138 -0
- package/src/utils/index.ts +101 -0
- package/src/utils/logger.ts +59 -0
- package/src/utils/snowflake.ts +17 -0
- package/src/utils/synthetic-detector.ts +111 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External Dependencies for Training Package
|
|
3
|
+
*
|
|
4
|
+
* Defines interfaces for external dependencies that must be provided
|
|
5
|
+
* by the consuming application (e.g., apps/web). The training package
|
|
6
|
+
* is decoupled from specific implementations to maintain clean
|
|
7
|
+
* package boundaries.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { configureTrainingDependencies } from '@elizaos/training';
|
|
12
|
+
*
|
|
13
|
+
* configureTrainingDependencies({
|
|
14
|
+
* agentService,
|
|
15
|
+
* agentRuntimeManager,
|
|
16
|
+
* autonomousCoordinator,
|
|
17
|
+
* llmCaller,
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import type { JsonValue } from './adapter';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Minimal agent runtime interface.
|
|
28
|
+
* Replaces the `IAgentRuntime` import from `@elizaos/core`.
|
|
29
|
+
* Consumers can pass a full IAgentRuntime; we only require what we use.
|
|
30
|
+
*/
|
|
31
|
+
export interface IAgentRuntimeLike {
|
|
32
|
+
agentId: string;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Minimal user record returned by agent creation.
|
|
38
|
+
* Replaces the `User` type from `@elizaos/db`.
|
|
39
|
+
*/
|
|
40
|
+
export interface UserLike {
|
|
41
|
+
id: string;
|
|
42
|
+
displayName?: string | null;
|
|
43
|
+
username?: string | null;
|
|
44
|
+
[key: string]: JsonValue | boolean | Date | null | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Parameters for creating an agent
|
|
49
|
+
*/
|
|
50
|
+
export interface CreateAgentParams {
|
|
51
|
+
userId: string;
|
|
52
|
+
name: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
profileImageUrl?: string;
|
|
55
|
+
coverImageUrl?: string;
|
|
56
|
+
system: string;
|
|
57
|
+
bio?: string[];
|
|
58
|
+
personality?: string;
|
|
59
|
+
tradingStrategy?: string;
|
|
60
|
+
initialDeposit?: number;
|
|
61
|
+
modelTier?: 'lite' | 'standard' | 'pro';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Interface for agent creation service
|
|
66
|
+
*/
|
|
67
|
+
export interface IAgentService {
|
|
68
|
+
createAgent(params: CreateAgentParams): Promise<UserLike>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Interface for managing agent runtimes
|
|
73
|
+
*/
|
|
74
|
+
export interface IAgentRuntimeManager {
|
|
75
|
+
getRuntime(agentId: string): Promise<IAgentRuntimeLike>;
|
|
76
|
+
resetRuntime(agentId: string): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Interface for LLM calling functionality
|
|
81
|
+
*/
|
|
82
|
+
export interface ILLMCaller {
|
|
83
|
+
callGroqDirect(params: {
|
|
84
|
+
prompt: string;
|
|
85
|
+
system: string;
|
|
86
|
+
modelSize?: 'small' | 'medium' | 'large';
|
|
87
|
+
temperature?: number;
|
|
88
|
+
maxTokens?: number;
|
|
89
|
+
actionType?: string;
|
|
90
|
+
responseFormat?: { type: 'json_object' };
|
|
91
|
+
}): Promise<string>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Export function type for trajectory data
|
|
96
|
+
*/
|
|
97
|
+
export type ExportGroupedForGRPOFn = (options: {
|
|
98
|
+
outputPath: string;
|
|
99
|
+
minTrajectoriesPerGroup?: number;
|
|
100
|
+
maxGroupSize?: number;
|
|
101
|
+
}) => Promise<{
|
|
102
|
+
success: boolean;
|
|
103
|
+
groupsExported: number;
|
|
104
|
+
trajectoriesExported: number;
|
|
105
|
+
outputPath: string;
|
|
106
|
+
error?: string;
|
|
107
|
+
}>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Export function type for HuggingFace
|
|
111
|
+
*/
|
|
112
|
+
export type ExportToHuggingFaceFn = (options: {
|
|
113
|
+
datasetName: string;
|
|
114
|
+
trajectoryIds?: string[];
|
|
115
|
+
format?: 'parquet' | 'jsonl';
|
|
116
|
+
}) => Promise<{ success: boolean; url?: string; error?: string }>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Convert trajectory to training format messages
|
|
120
|
+
*/
|
|
121
|
+
export type ToTrainingMessagesFn = (
|
|
122
|
+
trajectory: TrajectoryForTraining
|
|
123
|
+
) => TrainingMessage[];
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Rich trajectory type for training and RLAIF scoring
|
|
127
|
+
*/
|
|
128
|
+
export interface TrajectoryForTraining {
|
|
129
|
+
trajectoryId: string;
|
|
130
|
+
agentId: string;
|
|
131
|
+
startTime: number;
|
|
132
|
+
endTime: number;
|
|
133
|
+
durationMs: number;
|
|
134
|
+
scenarioId?: string;
|
|
135
|
+
steps: TrajectoryStepForTraining[];
|
|
136
|
+
totalReward: number;
|
|
137
|
+
rewardComponents: Record<string, number>;
|
|
138
|
+
metrics: {
|
|
139
|
+
episodeLength: number;
|
|
140
|
+
finalStatus: string;
|
|
141
|
+
finalPnL?: number;
|
|
142
|
+
};
|
|
143
|
+
metadata: {
|
|
144
|
+
isTrainingData: boolean;
|
|
145
|
+
[key: string]: JsonValue;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface TrajectoryStepForTraining {
|
|
150
|
+
stepId: string;
|
|
151
|
+
stepNumber: number;
|
|
152
|
+
timestamp: number;
|
|
153
|
+
environmentState: Record<string, JsonValue> & {
|
|
154
|
+
timestamp: number;
|
|
155
|
+
agentPoints: number;
|
|
156
|
+
};
|
|
157
|
+
observation: Record<string, JsonValue>;
|
|
158
|
+
providerAccesses: Array<{
|
|
159
|
+
providerId: string;
|
|
160
|
+
providerName: string;
|
|
161
|
+
timestamp: number;
|
|
162
|
+
query: Record<string, JsonValue>;
|
|
163
|
+
data: Record<string, JsonValue>;
|
|
164
|
+
purpose: string;
|
|
165
|
+
}>;
|
|
166
|
+
llmCalls: Array<{
|
|
167
|
+
callId: string;
|
|
168
|
+
timestamp: number;
|
|
169
|
+
model: string;
|
|
170
|
+
modelVersion?: string;
|
|
171
|
+
systemPrompt: string;
|
|
172
|
+
userPrompt: string;
|
|
173
|
+
response: string;
|
|
174
|
+
reasoning?: string;
|
|
175
|
+
temperature: number;
|
|
176
|
+
maxTokens: number;
|
|
177
|
+
latencyMs?: number;
|
|
178
|
+
purpose: 'action' | 'reasoning' | 'evaluation' | 'response' | 'other';
|
|
179
|
+
actionType?: string;
|
|
180
|
+
}>;
|
|
181
|
+
action: {
|
|
182
|
+
attemptId: string;
|
|
183
|
+
timestamp: number;
|
|
184
|
+
actionType: string;
|
|
185
|
+
actionName: string;
|
|
186
|
+
parameters: Record<string, JsonValue>;
|
|
187
|
+
reasoning?: string;
|
|
188
|
+
success: boolean;
|
|
189
|
+
result?: Record<string, JsonValue>;
|
|
190
|
+
error?: string;
|
|
191
|
+
};
|
|
192
|
+
reward: number;
|
|
193
|
+
done: boolean;
|
|
194
|
+
metadata: Record<string, JsonValue>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface TrainingMessage {
|
|
198
|
+
role: 'system' | 'user' | 'assistant';
|
|
199
|
+
content: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Global configuration for external dependencies
|
|
204
|
+
* This should be initialized before using the training package
|
|
205
|
+
*/
|
|
206
|
+
let _agentService: IAgentService | null = null;
|
|
207
|
+
let _agentRuntimeManager: IAgentRuntimeManager | null = null;
|
|
208
|
+
let _autonomousCoordinator: IAutonomousCoordinator | null = null;
|
|
209
|
+
let _llmCaller: ILLMCaller | null = null;
|
|
210
|
+
let _exportGroupedForGRPO: ExportGroupedForGRPOFn | null = null;
|
|
211
|
+
let _exportToHuggingFace: ExportToHuggingFaceFn | null = null;
|
|
212
|
+
let _toTrainingMessages: ToTrainingMessagesFn | null = null;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Validate that a dependency has the expected shape at runtime.
|
|
216
|
+
* Throws immediately on misconfiguration instead of failing at call time.
|
|
217
|
+
*/
|
|
218
|
+
function assertFn(dep: unknown, name: string, methods: string[]): void {
|
|
219
|
+
if (dep == null) return; // allow explicit null/undefined (means "skip")
|
|
220
|
+
for (const method of methods) {
|
|
221
|
+
if (typeof (dep as Record<string, unknown>)[method] !== 'function') {
|
|
222
|
+
throw new TypeError(
|
|
223
|
+
`configureTrainingDependencies: ${name}.${method} must be a function, got ${typeof (dep as Record<string, unknown>)[method]}`
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Configure external dependencies.
|
|
231
|
+
*
|
|
232
|
+
* Performs runtime shape validation so mismatched adapters fail early with a
|
|
233
|
+
* clear error instead of silently producing broken behavior downstream.
|
|
234
|
+
*/
|
|
235
|
+
export function configureTrainingDependencies(config: {
|
|
236
|
+
agentService?: IAgentService;
|
|
237
|
+
agentRuntimeManager?: IAgentRuntimeManager;
|
|
238
|
+
autonomousCoordinator?: IAutonomousCoordinator;
|
|
239
|
+
llmCaller?: ILLMCaller;
|
|
240
|
+
exportGroupedForGRPO?: ExportGroupedForGRPOFn;
|
|
241
|
+
exportToHuggingFace?: ExportToHuggingFaceFn;
|
|
242
|
+
toTrainingMessages?: ToTrainingMessagesFn;
|
|
243
|
+
}): void {
|
|
244
|
+
// Runtime shape checks – catch adapter mismatches early
|
|
245
|
+
assertFn(config.agentService, 'agentService', ['createAgent']);
|
|
246
|
+
assertFn(config.agentRuntimeManager, 'agentRuntimeManager', [
|
|
247
|
+
'getRuntime',
|
|
248
|
+
'resetRuntime',
|
|
249
|
+
]);
|
|
250
|
+
assertFn(config.autonomousCoordinator, 'autonomousCoordinator', [
|
|
251
|
+
'executeAutonomousTick',
|
|
252
|
+
]);
|
|
253
|
+
assertFn(config.llmCaller, 'llmCaller', ['callGroqDirect']);
|
|
254
|
+
|
|
255
|
+
if (
|
|
256
|
+
config.exportGroupedForGRPO !== undefined &&
|
|
257
|
+
config.exportGroupedForGRPO !== null &&
|
|
258
|
+
typeof config.exportGroupedForGRPO !== 'function'
|
|
259
|
+
) {
|
|
260
|
+
throw new TypeError(
|
|
261
|
+
'configureTrainingDependencies: exportGroupedForGRPO must be a function'
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
if (
|
|
265
|
+
config.exportToHuggingFace !== undefined &&
|
|
266
|
+
config.exportToHuggingFace !== null &&
|
|
267
|
+
typeof config.exportToHuggingFace !== 'function'
|
|
268
|
+
) {
|
|
269
|
+
throw new TypeError(
|
|
270
|
+
'configureTrainingDependencies: exportToHuggingFace must be a function'
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
if (
|
|
274
|
+
config.toTrainingMessages !== undefined &&
|
|
275
|
+
config.toTrainingMessages !== null &&
|
|
276
|
+
typeof config.toTrainingMessages !== 'function'
|
|
277
|
+
) {
|
|
278
|
+
throw new TypeError(
|
|
279
|
+
'configureTrainingDependencies: toTrainingMessages must be a function'
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (config.agentService) {
|
|
284
|
+
_agentService = config.agentService;
|
|
285
|
+
}
|
|
286
|
+
if (config.agentRuntimeManager) {
|
|
287
|
+
_agentRuntimeManager = config.agentRuntimeManager;
|
|
288
|
+
}
|
|
289
|
+
if (config.autonomousCoordinator) {
|
|
290
|
+
_autonomousCoordinator = config.autonomousCoordinator;
|
|
291
|
+
}
|
|
292
|
+
if (config.llmCaller) {
|
|
293
|
+
_llmCaller = config.llmCaller;
|
|
294
|
+
}
|
|
295
|
+
if (config.exportGroupedForGRPO) {
|
|
296
|
+
_exportGroupedForGRPO = config.exportGroupedForGRPO;
|
|
297
|
+
}
|
|
298
|
+
if (config.exportToHuggingFace) {
|
|
299
|
+
_exportToHuggingFace = config.exportToHuggingFace;
|
|
300
|
+
}
|
|
301
|
+
if (config.toTrainingMessages) {
|
|
302
|
+
_toTrainingMessages = config.toTrainingMessages;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Get the agent service
|
|
308
|
+
* @throws Error if not configured
|
|
309
|
+
*/
|
|
310
|
+
export function getAgentService(): IAgentService {
|
|
311
|
+
if (!_agentService) {
|
|
312
|
+
throw new Error(
|
|
313
|
+
'AgentService not configured. Call configureTrainingDependencies() first.'
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
return _agentService;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Get the agent runtime manager
|
|
321
|
+
* @throws Error if not configured
|
|
322
|
+
*/
|
|
323
|
+
export function getAgentRuntimeManager(): IAgentRuntimeManager {
|
|
324
|
+
if (!_agentRuntimeManager) {
|
|
325
|
+
throw new Error(
|
|
326
|
+
'AgentRuntimeManager not configured. Call configureTrainingDependencies() first.'
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
return _agentRuntimeManager;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Get the autonomous coordinator
|
|
334
|
+
* @throws Error if not configured
|
|
335
|
+
*/
|
|
336
|
+
export function getAutonomousCoordinator(): IAutonomousCoordinator {
|
|
337
|
+
if (!_autonomousCoordinator) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
'AutonomousCoordinator not configured. Call configureTrainingDependencies() first.'
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
return _autonomousCoordinator;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Get the LLM caller
|
|
347
|
+
* @throws Error if not configured
|
|
348
|
+
*/
|
|
349
|
+
export function getLLMCaller(): ILLMCaller {
|
|
350
|
+
if (!_llmCaller) {
|
|
351
|
+
throw new Error(
|
|
352
|
+
'LLMCaller not configured. Call configureTrainingDependencies() first.'
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
return _llmCaller;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Get the export function for GRPO
|
|
360
|
+
* @throws Error if not configured
|
|
361
|
+
*/
|
|
362
|
+
export function getExportGroupedForGRPO(): ExportGroupedForGRPOFn {
|
|
363
|
+
if (!_exportGroupedForGRPO) {
|
|
364
|
+
throw new Error(
|
|
365
|
+
'exportGroupedForGRPO not configured. Call configureTrainingDependencies() first.'
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
return _exportGroupedForGRPO;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Get the export function for HuggingFace
|
|
373
|
+
* @throws Error if not configured
|
|
374
|
+
*/
|
|
375
|
+
export function getExportToHuggingFace(): ExportToHuggingFaceFn {
|
|
376
|
+
if (!_exportToHuggingFace) {
|
|
377
|
+
throw new Error(
|
|
378
|
+
'exportToHuggingFace not configured. Call configureTrainingDependencies() first.'
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
return _exportToHuggingFace;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Get the toTrainingMessages function
|
|
386
|
+
* @throws Error if not configured
|
|
387
|
+
*/
|
|
388
|
+
export function getToTrainingMessages(): ToTrainingMessagesFn {
|
|
389
|
+
if (!_toTrainingMessages) {
|
|
390
|
+
throw new Error(
|
|
391
|
+
'toTrainingMessages not configured. Call configureTrainingDependencies() first.'
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
return _toTrainingMessages;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Check if dependencies are configured
|
|
398
|
+
*/
|
|
399
|
+
export function areDependenciesConfigured(): boolean {
|
|
400
|
+
return (
|
|
401
|
+
_agentService !== null &&
|
|
402
|
+
_agentRuntimeManager !== null &&
|
|
403
|
+
_autonomousCoordinator !== null
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Check if specific agent dependencies are configured for parallel generation
|
|
409
|
+
*/
|
|
410
|
+
export function areAgentDependenciesConfigured(): boolean {
|
|
411
|
+
return (
|
|
412
|
+
_agentService !== null &&
|
|
413
|
+
_agentRuntimeManager !== null &&
|
|
414
|
+
_autonomousCoordinator !== null
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Interface for autonomous tick execution
|
|
420
|
+
*/
|
|
421
|
+
export interface IAutonomousCoordinator {
|
|
422
|
+
executeAutonomousTick(
|
|
423
|
+
agentUserId: string,
|
|
424
|
+
agentRuntime: IAgentRuntimeLike,
|
|
425
|
+
recordTrajectories?: boolean
|
|
426
|
+
): Promise<{
|
|
427
|
+
success: boolean;
|
|
428
|
+
actionsExecuted?: {
|
|
429
|
+
trades: number;
|
|
430
|
+
posts: number;
|
|
431
|
+
comments: number;
|
|
432
|
+
messages: number;
|
|
433
|
+
groupMessages: number;
|
|
434
|
+
engagements: number;
|
|
435
|
+
};
|
|
436
|
+
trajectoryId?: string;
|
|
437
|
+
error?: string;
|
|
438
|
+
}>;
|
|
439
|
+
}
|