@elizaos/plugin-training 2.0.3-beta.6 → 2.0.3-beta.7
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/dist/backends/native.d.ts +96 -0
- package/dist/backends/native.d.ts.map +1 -0
- package/dist/backends/native.js +308 -0
- package/dist/backends/native.js.map +1 -0
- package/dist/cli/train.d.ts +22 -0
- package/dist/cli/train.d.ts.map +1 -0
- package/dist/cli/train.js +219 -0
- package/dist/cli/train.js.map +1 -0
- package/dist/core/action-benchmark-runner.d.ts +55 -0
- package/dist/core/action-benchmark-runner.d.ts.map +1 -0
- package/dist/core/action-benchmark-runner.js +341 -0
- package/dist/core/action-benchmark-runner.js.map +1 -0
- package/dist/core/artifact-store.d.ts +72 -0
- package/dist/core/artifact-store.d.ts.map +1 -0
- package/dist/core/artifact-store.js +50 -0
- package/dist/core/artifact-store.js.map +1 -0
- package/dist/core/benchmark-matrix-artifact.d.ts +102 -0
- package/dist/core/benchmark-matrix-artifact.d.ts.map +1 -0
- package/dist/core/benchmark-matrix-artifact.js +381 -0
- package/dist/core/benchmark-matrix-artifact.js.map +1 -0
- package/dist/core/benchmark-vs-cerebras-runner.d.ts +37 -0
- package/dist/core/benchmark-vs-cerebras-runner.d.ts.map +1 -0
- package/dist/core/benchmark-vs-cerebras-runner.js +151 -0
- package/dist/core/benchmark-vs-cerebras-runner.js.map +1 -0
- package/dist/core/cerebras-eval-model.d.ts +54 -0
- package/dist/core/cerebras-eval-model.d.ts.map +1 -0
- package/dist/core/cerebras-eval-model.js +249 -0
- package/dist/core/cerebras-eval-model.js.map +1 -0
- package/dist/core/cli.d.ts +15 -0
- package/dist/core/cli.d.ts.map +1 -0
- package/dist/core/cli.js +1003 -0
- package/dist/core/cli.js.map +1 -0
- package/dist/core/context-audit.d.ts +51 -0
- package/dist/core/context-audit.d.ts.map +1 -0
- package/dist/core/context-audit.js +166 -0
- package/dist/core/context-audit.js.map +1 -0
- package/dist/core/context-catalog.d.ts +47 -0
- package/dist/core/context-catalog.d.ts.map +1 -0
- package/dist/core/context-catalog.js +269 -0
- package/dist/core/context-catalog.js.map +1 -0
- package/dist/core/context-types.d.ts +3 -0
- package/dist/core/context-types.d.ts.map +1 -0
- package/dist/core/context-types.js +18 -0
- package/dist/core/context-types.js.map +1 -0
- package/dist/core/dataset-generator.d.ts +135 -0
- package/dist/core/dataset-generator.d.ts.map +1 -0
- package/dist/core/dataset-generator.js +895 -0
- package/dist/core/dataset-generator.js.map +1 -0
- package/dist/core/eliza1-benchmark-recipe.d.ts +18 -0
- package/dist/core/eliza1-benchmark-recipe.d.ts.map +1 -0
- package/dist/core/eliza1-benchmark-recipe.js +64 -0
- package/dist/core/eliza1-benchmark-recipe.js.map +1 -0
- package/dist/core/eliza1-bundle-stager.d.ts +57 -0
- package/dist/core/eliza1-bundle-stager.d.ts.map +1 -0
- package/dist/core/eliza1-bundle-stager.js +149 -0
- package/dist/core/eliza1-bundle-stager.js.map +1 -0
- package/dist/core/ensure-cron-job.d.ts +53 -0
- package/dist/core/ensure-cron-job.d.ts.map +1 -0
- package/dist/core/ensure-cron-job.js +51 -0
- package/dist/core/ensure-cron-job.js.map +1 -0
- package/dist/core/eval-comparison-artifact.d.ts +72 -0
- package/dist/core/eval-comparison-artifact.d.ts.map +1 -0
- package/dist/core/eval-comparison-artifact.js +281 -0
- package/dist/core/eval-comparison-artifact.js.map +1 -0
- package/dist/core/feed-generation-runner.d.ts +37 -0
- package/dist/core/feed-generation-runner.d.ts.map +1 -0
- package/dist/core/feed-generation-runner.js +232 -0
- package/dist/core/feed-generation-runner.js.map +1 -0
- package/dist/core/html-escape.d.ts +5 -0
- package/dist/core/html-escape.d.ts.map +1 -0
- package/dist/core/html-escape.js +11 -0
- package/dist/core/html-escape.js.map +1 -0
- package/dist/core/huggingface-dataset-ingest.d.ts +52 -0
- package/dist/core/huggingface-dataset-ingest.d.ts.map +1 -0
- package/dist/core/huggingface-dataset-ingest.js +134 -0
- package/dist/core/huggingface-dataset-ingest.js.map +1 -0
- package/dist/core/index.d.ts +29 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +204 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/privacy-filter.d.ts +95 -0
- package/dist/core/privacy-filter.d.ts.map +1 -0
- package/dist/core/privacy-filter.js +324 -0
- package/dist/core/privacy-filter.js.map +1 -0
- package/dist/core/promotion-gate.d.ts +117 -0
- package/dist/core/promotion-gate.d.ts.map +1 -0
- package/dist/core/promotion-gate.js +85 -0
- package/dist/core/promotion-gate.js.map +1 -0
- package/dist/core/promotion-persist.d.ts +116 -0
- package/dist/core/promotion-persist.d.ts.map +1 -0
- package/dist/core/promotion-persist.js +93 -0
- package/dist/core/promotion-persist.js.map +1 -0
- package/dist/core/prompt-compare.d.ts +99 -0
- package/dist/core/prompt-compare.d.ts.map +1 -0
- package/dist/core/prompt-compare.js +210 -0
- package/dist/core/prompt-compare.js.map +1 -0
- package/dist/core/replay-validator.d.ts +136 -0
- package/dist/core/replay-validator.d.ts.map +1 -0
- package/dist/core/replay-validator.js +312 -0
- package/dist/core/replay-validator.js.map +1 -0
- package/dist/core/roleplay-executor.d.ts +123 -0
- package/dist/core/roleplay-executor.d.ts.map +1 -0
- package/dist/core/roleplay-executor.js +675 -0
- package/dist/core/roleplay-executor.js.map +1 -0
- package/dist/core/roleplay-trajectories.d.ts +54 -0
- package/dist/core/roleplay-trajectories.d.ts.map +1 -0
- package/dist/core/roleplay-trajectories.js +88 -0
- package/dist/core/roleplay-trajectories.js.map +1 -0
- package/dist/core/scenario-blueprints.d.ts +62 -0
- package/dist/core/scenario-blueprints.d.ts.map +1 -0
- package/dist/core/scenario-blueprints.js +850 -0
- package/dist/core/scenario-blueprints.js.map +1 -0
- package/dist/core/scenario-runner.d.ts +36 -0
- package/dist/core/scenario-runner.d.ts.map +1 -0
- package/dist/core/scenario-runner.js +216 -0
- package/dist/core/scenario-runner.js.map +1 -0
- package/dist/core/skill-scoring-cron.d.ts +57 -0
- package/dist/core/skill-scoring-cron.d.ts.map +1 -0
- package/dist/core/skill-scoring-cron.js +180 -0
- package/dist/core/skill-scoring-cron.js.map +1 -0
- package/dist/core/test-trajectory-collector.d.ts +37 -0
- package/dist/core/test-trajectory-collector.d.ts.map +1 -0
- package/dist/core/test-trajectory-collector.js +225 -0
- package/dist/core/test-trajectory-collector.js.map +1 -0
- package/dist/core/track-c-queue-task.d.ts +37 -0
- package/dist/core/track-c-queue-task.d.ts.map +1 -0
- package/dist/core/track-c-queue-task.js +104 -0
- package/dist/core/track-c-queue-task.js.map +1 -0
- package/dist/core/training-analysis-index.d.ts +104 -0
- package/dist/core/training-analysis-index.d.ts.map +1 -0
- package/dist/core/training-analysis-index.js +3297 -0
- package/dist/core/training-analysis-index.js.map +1 -0
- package/dist/core/training-collection-runner.d.ts +508 -0
- package/dist/core/training-collection-runner.d.ts.map +1 -0
- package/dist/core/training-collection-runner.js +2299 -0
- package/dist/core/training-collection-runner.js.map +1 -0
- package/dist/core/training-config.d.ts +52 -0
- package/dist/core/training-config.d.ts.map +1 -0
- package/dist/core/training-config.js +117 -0
- package/dist/core/training-config.js.map +1 -0
- package/dist/core/training-orchestrator.d.ts +112 -0
- package/dist/core/training-orchestrator.d.ts.map +1 -0
- package/dist/core/training-orchestrator.js +729 -0
- package/dist/core/training-orchestrator.js.map +1 -0
- package/dist/core/training-readiness-report.d.ts +52 -0
- package/dist/core/training-readiness-report.d.ts.map +1 -0
- package/dist/core/training-readiness-report.js +765 -0
- package/dist/core/training-readiness-report.js.map +1 -0
- package/dist/core/trajectory-consumer.d.ts +15 -0
- package/dist/core/trajectory-consumer.d.ts.map +1 -0
- package/dist/core/trajectory-consumer.js +61 -0
- package/dist/core/trajectory-consumer.js.map +1 -0
- package/dist/core/trajectory-export-bundle.d.ts +95 -0
- package/dist/core/trajectory-export-bundle.d.ts.map +1 -0
- package/dist/core/trajectory-export-bundle.js +561 -0
- package/dist/core/trajectory-export-bundle.js.map +1 -0
- package/dist/core/trajectory-export-cron.d.ts +57 -0
- package/dist/core/trajectory-export-cron.d.ts.map +1 -0
- package/dist/core/trajectory-export-cron.js +170 -0
- package/dist/core/trajectory-export-cron.js.map +1 -0
- package/dist/core/trajectory-hf-upload.d.ts +50 -0
- package/dist/core/trajectory-hf-upload.d.ts.map +1 -0
- package/dist/core/trajectory-hf-upload.js +111 -0
- package/dist/core/trajectory-hf-upload.js.map +1 -0
- package/dist/core/trajectory-task-datasets.d.ts +62 -0
- package/dist/core/trajectory-task-datasets.d.ts.map +1 -0
- package/dist/core/trajectory-task-datasets.js +427 -0
- package/dist/core/trajectory-task-datasets.js.map +1 -0
- package/dist/core/wait-for-service.d.ts +25 -0
- package/dist/core/wait-for-service.d.ts.map +1 -0
- package/dist/core/wait-for-service.js +19 -0
- package/dist/core/wait-for-service.js.map +1 -0
- package/dist/core/workspace-runtime.d.ts +4 -0
- package/dist/core/workspace-runtime.d.ts.map +1 -0
- package/dist/core/workspace-runtime.js +25 -0
- package/dist/core/workspace-runtime.js.map +1 -0
- package/dist/dspy/artifact.d.ts +54 -0
- package/dist/dspy/artifact.d.ts.map +1 -0
- package/dist/dspy/artifact.js +61 -0
- package/dist/dspy/artifact.js.map +1 -0
- package/dist/dspy/chain-of-thought.d.ts +27 -0
- package/dist/dspy/chain-of-thought.d.ts.map +1 -0
- package/dist/dspy/chain-of-thought.js +43 -0
- package/dist/dspy/chain-of-thought.js.map +1 -0
- package/dist/dspy/examples.d.ts +72 -0
- package/dist/dspy/examples.d.ts.map +1 -0
- package/dist/dspy/examples.js +105 -0
- package/dist/dspy/examples.js.map +1 -0
- package/dist/dspy/index.d.ts +15 -0
- package/dist/dspy/index.d.ts.map +1 -0
- package/dist/dspy/index.js +40 -0
- package/dist/dspy/index.js.map +1 -0
- package/dist/dspy/lm-adapter.d.ts +100 -0
- package/dist/dspy/lm-adapter.d.ts.map +1 -0
- package/dist/dspy/lm-adapter.js +81 -0
- package/dist/dspy/lm-adapter.js.map +1 -0
- package/dist/dspy/optimizers/dspy-bootstrap-fewshot.d.ts +23 -0
- package/dist/dspy/optimizers/dspy-bootstrap-fewshot.d.ts.map +1 -0
- package/dist/dspy/optimizers/dspy-bootstrap-fewshot.js +85 -0
- package/dist/dspy/optimizers/dspy-bootstrap-fewshot.js.map +1 -0
- package/dist/dspy/optimizers/dspy-copro.d.ts +29 -0
- package/dist/dspy/optimizers/dspy-copro.d.ts.map +1 -0
- package/dist/dspy/optimizers/dspy-copro.js +141 -0
- package/dist/dspy/optimizers/dspy-copro.js.map +1 -0
- package/dist/dspy/optimizers/dspy-mipro.d.ts +37 -0
- package/dist/dspy/optimizers/dspy-mipro.d.ts.map +1 -0
- package/dist/dspy/optimizers/dspy-mipro.js +194 -0
- package/dist/dspy/optimizers/dspy-mipro.js.map +1 -0
- package/dist/dspy/optimizers/index.d.ts +5 -0
- package/dist/dspy/optimizers/index.d.ts.map +1 -0
- package/dist/dspy/optimizers/index.js +11 -0
- package/dist/dspy/optimizers/index.js.map +1 -0
- package/dist/dspy/optimizers/types.d.ts +39 -0
- package/dist/dspy/optimizers/types.d.ts.map +1 -0
- package/dist/dspy/optimizers/types.js +1 -0
- package/dist/dspy/optimizers/types.js.map +1 -0
- package/dist/dspy/predict.d.ts +49 -0
- package/dist/dspy/predict.d.ts.map +1 -0
- package/dist/dspy/predict.js +73 -0
- package/dist/dspy/predict.js.map +1 -0
- package/dist/dspy/signature.d.ts +88 -0
- package/dist/dspy/signature.d.ts.map +1 -0
- package/dist/dspy/signature.js +205 -0
- package/dist/dspy/signature.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/optimizers/bootstrap-fewshot.d.ts +42 -0
- package/dist/optimizers/bootstrap-fewshot.d.ts.map +1 -0
- package/dist/optimizers/bootstrap-fewshot.js +92 -0
- package/dist/optimizers/bootstrap-fewshot.js.map +1 -0
- package/dist/optimizers/gepa.d.ts +63 -0
- package/dist/optimizers/gepa.d.ts.map +1 -0
- package/dist/optimizers/gepa.js +232 -0
- package/dist/optimizers/gepa.js.map +1 -0
- package/dist/optimizers/index.d.ts +7 -0
- package/dist/optimizers/index.d.ts.map +1 -0
- package/dist/optimizers/index.js +51 -0
- package/dist/optimizers/index.js.map +1 -0
- package/dist/optimizers/instruction-search.d.ts +39 -0
- package/dist/optimizers/instruction-search.d.ts.map +1 -0
- package/dist/optimizers/instruction-search.js +108 -0
- package/dist/optimizers/instruction-search.js.map +1 -0
- package/dist/optimizers/prompt-evolution.d.ts +39 -0
- package/dist/optimizers/prompt-evolution.d.ts.map +1 -0
- package/dist/optimizers/prompt-evolution.js +101 -0
- package/dist/optimizers/prompt-evolution.js.map +1 -0
- package/dist/optimizers/scoring.d.ts +139 -0
- package/dist/optimizers/scoring.d.ts.map +1 -0
- package/dist/optimizers/scoring.js +299 -0
- package/dist/optimizers/scoring.js.map +1 -0
- package/dist/optimizers/types.d.ts +105 -0
- package/dist/optimizers/types.d.ts.map +1 -0
- package/dist/optimizers/types.js +1 -0
- package/dist/optimizers/types.js.map +1 -0
- package/dist/register-runtime.d.ts +3 -0
- package/dist/register-runtime.d.ts.map +1 -0
- package/dist/register-runtime.js +60 -0
- package/dist/register-runtime.js.map +1 -0
- package/dist/register-terminal-view.d.ts +15 -0
- package/dist/register-terminal-view.d.ts.map +1 -0
- package/dist/register-terminal-view.js +31 -0
- package/dist/register-terminal-view.js.map +1 -0
- package/dist/routes/experience-routes.d.ts +21 -0
- package/dist/routes/experience-routes.d.ts.map +1 -0
- package/dist/routes/experience-routes.js +513 -0
- package/dist/routes/experience-routes.js.map +1 -0
- package/dist/routes/index.d.ts +5 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +17 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/training-routes.d.ts +10 -0
- package/dist/routes/training-routes.d.ts.map +1 -0
- package/dist/routes/training-routes.js +1239 -0
- package/dist/routes/training-routes.js.map +1 -0
- package/dist/routes/training-vast-routes.d.ts +35 -0
- package/dist/routes/training-vast-routes.d.ts.map +1 -0
- package/dist/routes/training-vast-routes.js +249 -0
- package/dist/routes/training-vast-routes.js.map +1 -0
- package/dist/routes/trajectory-routes.d.ts +19 -0
- package/dist/routes/trajectory-routes.d.ts.map +1 -0
- package/dist/routes/trajectory-routes.js +1122 -0
- package/dist/routes/trajectory-routes.js.map +1 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +63 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/training-backend-check.d.ts +8 -0
- package/dist/services/training-backend-check.d.ts.map +1 -0
- package/dist/services/training-backend-check.js +31 -0
- package/dist/services/training-backend-check.js.map +1 -0
- package/dist/services/training-service-like.d.ts +40 -0
- package/dist/services/training-service-like.d.ts.map +1 -0
- package/dist/services/training-service-like.js +1 -0
- package/dist/services/training-service-like.js.map +1 -0
- package/dist/services/training-service-registry.d.ts +4 -0
- package/dist/services/training-service-registry.d.ts.map +1 -0
- package/dist/services/training-service-registry.js +12 -0
- package/dist/services/training-service-registry.js.map +1 -0
- package/dist/services/training-service.d.ts +59 -0
- package/dist/services/training-service.d.ts.map +1 -0
- package/dist/services/training-service.js +154 -0
- package/dist/services/training-service.js.map +1 -0
- package/dist/services/training-trigger.d.ts +177 -0
- package/dist/services/training-trigger.d.ts.map +1 -0
- package/dist/services/training-trigger.js +300 -0
- package/dist/services/training-trigger.js.map +1 -0
- package/dist/services/training-vast-service.d.ts +149 -0
- package/dist/services/training-vast-service.d.ts.map +1 -0
- package/dist/services/training-vast-service.js +648 -0
- package/dist/services/training-vast-service.js.map +1 -0
- package/dist/services/vast-inference-stats.d.ts +37 -0
- package/dist/services/vast-inference-stats.d.ts.map +1 -0
- package/dist/services/vast-inference-stats.js +81 -0
- package/dist/services/vast-inference-stats.js.map +1 -0
- package/dist/services/vast-job-store.d.ts +74 -0
- package/dist/services/vast-job-store.d.ts.map +1 -0
- package/dist/services/vast-job-store.js +194 -0
- package/dist/services/vast-job-store.js.map +1 -0
- package/dist/services/vast-subprocess.d.ts +27 -0
- package/dist/services/vast-subprocess.d.ts.map +1 -0
- package/dist/services/vast-subprocess.js +78 -0
- package/dist/services/vast-subprocess.js.map +1 -0
- package/dist/setup-routes.d.ts +17 -0
- package/dist/setup-routes.d.ts.map +1 -0
- package/dist/setup-routes.js +319 -0
- package/dist/setup-routes.js.map +1 -0
- package/dist/ui/FineTuningSpatialView.d.ts +49 -0
- package/dist/ui/FineTuningSpatialView.d.ts.map +1 -0
- package/dist/ui/FineTuningSpatialView.js +154 -0
- package/dist/ui/FineTuningSpatialView.js.map +1 -0
- package/dist/ui/FineTuningView.d.ts +7 -0
- package/dist/ui/FineTuningView.d.ts.map +1 -0
- package/dist/ui/FineTuningView.helpers.d.ts +17 -0
- package/dist/ui/FineTuningView.helpers.d.ts.map +1 -0
- package/dist/ui/FineTuningView.helpers.js +30 -0
- package/dist/ui/FineTuningView.helpers.js.map +1 -0
- package/dist/ui/FineTuningView.interact.d.ts +2 -0
- package/dist/ui/FineTuningView.interact.d.ts.map +1 -0
- package/dist/ui/FineTuningView.interact.js +300 -0
- package/dist/ui/FineTuningView.interact.js.map +1 -0
- package/dist/ui/FineTuningView.js +4653 -0
- package/dist/ui/FineTuningView.js.map +1 -0
- package/dist/ui/fine-tuning-panels.d.ts +100 -0
- package/dist/ui/fine-tuning-panels.d.ts.map +1 -0
- package/dist/ui/fine-tuning-panels.helpers.d.ts +19 -0
- package/dist/ui/fine-tuning-panels.helpers.d.ts.map +1 -0
- package/dist/ui/fine-tuning-panels.helpers.js +77 -0
- package/dist/ui/fine-tuning-panels.helpers.js.map +1 -0
- package/dist/ui/fine-tuning-panels.js +928 -0
- package/dist/ui/fine-tuning-panels.js.map +1 -0
- package/dist/ui/index.d.ts +5 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +5 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/training-view-bundle.d.ts +3 -0
- package/dist/ui/training-view-bundle.d.ts.map +1 -0
- package/dist/ui/training-view-bundle.js +7 -0
- package/dist/ui/training-view-bundle.js.map +1 -0
- package/dist/views/bundle.js +5312 -0
- package/dist/views/bundle.js.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,895 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import * as ElizaCore from "@elizaos/core";
|
|
5
|
+
import {
|
|
6
|
+
buildElizaNativeTrajectoryRows,
|
|
7
|
+
ELIZA_NATIVE_TRAJECTORY_FORMAT,
|
|
8
|
+
iterateTrajectoryLlmCalls
|
|
9
|
+
} from "@elizaos/core";
|
|
10
|
+
import {
|
|
11
|
+
ACTION_CONTEXT_MAP,
|
|
12
|
+
ALL_CONTEXTS,
|
|
13
|
+
PROVIDER_CONTEXT_MAP
|
|
14
|
+
} from "./context-catalog.js";
|
|
15
|
+
import {
|
|
16
|
+
ALL_BLUEPRINTS
|
|
17
|
+
} from "./scenario-blueprints.js";
|
|
18
|
+
const SHOULD_RESPOND_PROMPT_TEMPLATE = `task: Decide whether {{agentName}} should respond, ignore, or stop.
|
|
19
|
+
|
|
20
|
+
context:
|
|
21
|
+
{{providers}}
|
|
22
|
+
|
|
23
|
+
available_contexts:
|
|
24
|
+
{{availableContexts}}
|
|
25
|
+
|
|
26
|
+
rules[6]:
|
|
27
|
+
- direct mention of {{agentName}} -> RESPOND
|
|
28
|
+
- different assistant name or talking to someone else -> IGNORE unless {{agentName}} is also directly addressed
|
|
29
|
+
- prior participation by {{agentName}} in the thread is not enough by itself; the newest message must still clearly expect {{agentName}} -> otherwise IGNORE
|
|
30
|
+
- request to stop or be quiet directed at {{agentName}} -> STOP
|
|
31
|
+
- if multiple people are mentioned and {{agentName}} is one of the addressees -> RESPOND
|
|
32
|
+
- if unsure whether the speaker is talking to {{agentName}}, prefer IGNORE over hallucinating relevance
|
|
33
|
+
|
|
34
|
+
message_handler:
|
|
35
|
+
- action: RESPOND, IGNORE, or STOP
|
|
36
|
+
- contexts: list of available_contexts needed for planner/tool/provider work; ["simple"] for direct replies (the reply is the full answer); [] for IGNORE or STOP
|
|
37
|
+
- thought: short internal routing rationale
|
|
38
|
+
- reply: required user-visible reply when contexts is ["simple"]
|
|
39
|
+
|
|
40
|
+
decision_note:
|
|
41
|
+
- respond only when the latest message is talking TO {{agentName}}
|
|
42
|
+
- talking TO {{agentName}} means name mention, reply chain, or a clear follow-up that still expects {{agentName}} to answer
|
|
43
|
+
- casual conversation between other users is not enough
|
|
44
|
+
- if another assistant already answered and nobody re-addressed {{agentName}}, IGNORE
|
|
45
|
+
- if {{agentName}} already replied recently and nobody re-addressed {{agentName}}, IGNORE
|
|
46
|
+
- talking ABOUT {{agentName}} or continuing a room conversation around them is not enough
|
|
47
|
+
|
|
48
|
+
output:
|
|
49
|
+
JSON object only. No prose, markdown, XML, or hidden reasoning.
|
|
50
|
+
|
|
51
|
+
Example:
|
|
52
|
+
{"messageHandler":{"action":"RESPOND","contexts":["wallet"],"thought":"Direct mention and clear follow-up needs wallet context.","reply":""}}
|
|
53
|
+
|
|
54
|
+
Example:
|
|
55
|
+
{"messageHandler":{"action":"IGNORE","contexts":[],"thought":"The latest message is not addressed to {{agentName}}.","reply":""}}`;
|
|
56
|
+
const AGENT_NAMES = [
|
|
57
|
+
"Nova",
|
|
58
|
+
"Kai",
|
|
59
|
+
"Echo",
|
|
60
|
+
"Luna",
|
|
61
|
+
"Atlas",
|
|
62
|
+
"Vex",
|
|
63
|
+
"Iris",
|
|
64
|
+
"Cypher",
|
|
65
|
+
"Sage",
|
|
66
|
+
"Bolt",
|
|
67
|
+
"Pixel",
|
|
68
|
+
"Nyx",
|
|
69
|
+
"Orion",
|
|
70
|
+
"Zephyr",
|
|
71
|
+
"Flux",
|
|
72
|
+
"Aria",
|
|
73
|
+
"Cosmo",
|
|
74
|
+
"Dash",
|
|
75
|
+
"Ember",
|
|
76
|
+
"Ghost",
|
|
77
|
+
"Helix",
|
|
78
|
+
"Jade",
|
|
79
|
+
"Karma",
|
|
80
|
+
"Lux",
|
|
81
|
+
"Muse",
|
|
82
|
+
"Neo",
|
|
83
|
+
"Onyx",
|
|
84
|
+
"Proto",
|
|
85
|
+
"Qubit",
|
|
86
|
+
"Rune",
|
|
87
|
+
"Spark",
|
|
88
|
+
"Titan",
|
|
89
|
+
"Uno",
|
|
90
|
+
"Volt",
|
|
91
|
+
"Wren",
|
|
92
|
+
"Xeno",
|
|
93
|
+
"Yara",
|
|
94
|
+
"Zen",
|
|
95
|
+
"Chip",
|
|
96
|
+
"Delta",
|
|
97
|
+
"Ava",
|
|
98
|
+
"Rex",
|
|
99
|
+
"Sky",
|
|
100
|
+
"Zara"
|
|
101
|
+
];
|
|
102
|
+
const PARTICIPANT_NAMES = [
|
|
103
|
+
"Alice",
|
|
104
|
+
"Bob",
|
|
105
|
+
"Charlie",
|
|
106
|
+
"Dave",
|
|
107
|
+
"Eve",
|
|
108
|
+
"Frank",
|
|
109
|
+
"Grace",
|
|
110
|
+
"Hank",
|
|
111
|
+
"Ivy",
|
|
112
|
+
"Jack",
|
|
113
|
+
"Karen",
|
|
114
|
+
"Leo",
|
|
115
|
+
"Mia",
|
|
116
|
+
"Nick",
|
|
117
|
+
"Olivia",
|
|
118
|
+
"Pete",
|
|
119
|
+
"Quinn",
|
|
120
|
+
"Rose",
|
|
121
|
+
"Sam",
|
|
122
|
+
"Tina",
|
|
123
|
+
"Uma",
|
|
124
|
+
"Vince",
|
|
125
|
+
"Wendy",
|
|
126
|
+
"Xavier",
|
|
127
|
+
"Yuki",
|
|
128
|
+
"Zack",
|
|
129
|
+
"Maya",
|
|
130
|
+
"Raj",
|
|
131
|
+
"Sofia",
|
|
132
|
+
"Tyler",
|
|
133
|
+
"Aisha",
|
|
134
|
+
"Ben",
|
|
135
|
+
"Chloe",
|
|
136
|
+
"Dan",
|
|
137
|
+
"Elena",
|
|
138
|
+
"Finn",
|
|
139
|
+
"Gabe",
|
|
140
|
+
"Hannah",
|
|
141
|
+
"Isaac",
|
|
142
|
+
"Jade"
|
|
143
|
+
];
|
|
144
|
+
const OTHER_BOT_NAMES = [
|
|
145
|
+
"AssistBot",
|
|
146
|
+
"Helper",
|
|
147
|
+
"Cortana",
|
|
148
|
+
"Alexa",
|
|
149
|
+
"Siri",
|
|
150
|
+
"Bard",
|
|
151
|
+
"CoPilot",
|
|
152
|
+
"Genie",
|
|
153
|
+
"Oracle",
|
|
154
|
+
"Alfred",
|
|
155
|
+
"Jarvis",
|
|
156
|
+
"Friday"
|
|
157
|
+
];
|
|
158
|
+
const PLATFORMS = ["telegram", "discord", "slack", "matrix", "irc"];
|
|
159
|
+
const recordLlmCall = "recordLlmCall" in ElizaCore && typeof ElizaCore.recordLlmCall === "function" ? ElizaCore.recordLlmCall : async (_runtime, _details, callback) => await callback();
|
|
160
|
+
const withStandaloneTrajectory = "withStandaloneTrajectory" in ElizaCore && typeof ElizaCore.withStandaloneTrajectory === "function" ? ElizaCore.withStandaloneTrajectory : async (_runtime, _options, callback) => await callback();
|
|
161
|
+
function createAnthropicTeacher(apiKey, runtime) {
|
|
162
|
+
return {
|
|
163
|
+
name: "anthropic/claude-sonnet-4.6",
|
|
164
|
+
async generate(systemPrompt, userPrompt) {
|
|
165
|
+
return await withStandaloneTrajectory(
|
|
166
|
+
runtime,
|
|
167
|
+
{
|
|
168
|
+
source: "training",
|
|
169
|
+
metadata: {
|
|
170
|
+
provider: "anthropic",
|
|
171
|
+
model: "claude-sonnet-4-6",
|
|
172
|
+
purpose: "teacher"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
async () => {
|
|
176
|
+
const details = {
|
|
177
|
+
model: "anthropic/claude-sonnet-4.6",
|
|
178
|
+
modelVersion: "claude-sonnet-4-6",
|
|
179
|
+
systemPrompt,
|
|
180
|
+
userPrompt,
|
|
181
|
+
temperature: 1,
|
|
182
|
+
maxTokens: 4096,
|
|
183
|
+
purpose: "training.teacher",
|
|
184
|
+
actionType: "training.teacher.anthropic.generate"
|
|
185
|
+
};
|
|
186
|
+
return await recordLlmCall(runtime, details, async () => {
|
|
187
|
+
const response = await fetch(
|
|
188
|
+
"https://api.anthropic.com/v1/messages",
|
|
189
|
+
{
|
|
190
|
+
method: "POST",
|
|
191
|
+
headers: {
|
|
192
|
+
"content-type": "application/json",
|
|
193
|
+
"x-api-key": apiKey,
|
|
194
|
+
"anthropic-version": "2023-06-01"
|
|
195
|
+
},
|
|
196
|
+
body: JSON.stringify({
|
|
197
|
+
model: "claude-sonnet-4-6",
|
|
198
|
+
max_tokens: 4096,
|
|
199
|
+
temperature: 1,
|
|
200
|
+
system: systemPrompt,
|
|
201
|
+
messages: [{ role: "user", content: userPrompt }]
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
if (!response.ok) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
`Anthropic API error: ${response.status} ${await response.text()}`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const data = await response.json();
|
|
211
|
+
details.promptTokens = data.usage?.input_tokens;
|
|
212
|
+
details.completionTokens = data.usage?.output_tokens;
|
|
213
|
+
return data.content[0]?.text ?? "";
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function createOpenAITeacher(apiKey, runtime) {
|
|
221
|
+
return {
|
|
222
|
+
name: "openai/gpt-5.4",
|
|
223
|
+
async generate(systemPrompt, userPrompt) {
|
|
224
|
+
return await withStandaloneTrajectory(
|
|
225
|
+
runtime,
|
|
226
|
+
{
|
|
227
|
+
source: "training",
|
|
228
|
+
metadata: {
|
|
229
|
+
provider: "openai",
|
|
230
|
+
model: "gpt-5.4",
|
|
231
|
+
purpose: "teacher"
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
async () => {
|
|
235
|
+
const details = {
|
|
236
|
+
model: "openai/gpt-5.4",
|
|
237
|
+
modelVersion: "gpt-5.4",
|
|
238
|
+
systemPrompt,
|
|
239
|
+
userPrompt,
|
|
240
|
+
temperature: 0.9,
|
|
241
|
+
maxTokens: 4096,
|
|
242
|
+
purpose: "training.teacher",
|
|
243
|
+
actionType: "training.teacher.openai.generate"
|
|
244
|
+
};
|
|
245
|
+
return await recordLlmCall(runtime, details, async () => {
|
|
246
|
+
const response = await fetch(
|
|
247
|
+
"https://api.openai.com/v1/chat/completions",
|
|
248
|
+
{
|
|
249
|
+
method: "POST",
|
|
250
|
+
headers: {
|
|
251
|
+
"content-type": "application/json",
|
|
252
|
+
authorization: `Bearer ${apiKey}`
|
|
253
|
+
},
|
|
254
|
+
body: JSON.stringify({
|
|
255
|
+
model: "gpt-5.4",
|
|
256
|
+
messages: [
|
|
257
|
+
{ role: "system", content: systemPrompt },
|
|
258
|
+
{ role: "user", content: userPrompt }
|
|
259
|
+
],
|
|
260
|
+
max_tokens: 4096,
|
|
261
|
+
temperature: 0.9
|
|
262
|
+
})
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
if (!response.ok) {
|
|
266
|
+
throw new Error(
|
|
267
|
+
`OpenAI API error: ${response.status} ${await response.text()}`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
const data = await response.json();
|
|
271
|
+
details.modelVersion = data.model;
|
|
272
|
+
details.promptTokens = data.usage?.prompt_tokens;
|
|
273
|
+
details.completionTokens = data.usage?.completion_tokens;
|
|
274
|
+
return data.choices[0]?.message?.content ?? "";
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function createCerebrasTeacher(runtime) {
|
|
282
|
+
const model = process.env.TRAIN_MODEL?.trim() ?? process.env.CEREBRAS_MODEL?.trim() ?? "gpt-oss-120b";
|
|
283
|
+
return {
|
|
284
|
+
name: `cerebras/${model}`,
|
|
285
|
+
async generate(systemPrompt, userPrompt) {
|
|
286
|
+
return await withStandaloneTrajectory(
|
|
287
|
+
runtime,
|
|
288
|
+
{
|
|
289
|
+
source: "training",
|
|
290
|
+
metadata: { provider: "cerebras", model, purpose: "teacher" }
|
|
291
|
+
},
|
|
292
|
+
async () => {
|
|
293
|
+
const details = {
|
|
294
|
+
model: `cerebras/${model}`,
|
|
295
|
+
modelVersion: model,
|
|
296
|
+
systemPrompt,
|
|
297
|
+
userPrompt,
|
|
298
|
+
temperature: 0.9,
|
|
299
|
+
maxTokens: 4096,
|
|
300
|
+
purpose: "training.teacher",
|
|
301
|
+
actionType: "training.teacher.cerebras.generate"
|
|
302
|
+
};
|
|
303
|
+
return await recordLlmCall(runtime, details, async () => {
|
|
304
|
+
const { getTrainingModelClient } = await import("./cerebras-eval-model.js");
|
|
305
|
+
const client = getTrainingModelClient();
|
|
306
|
+
const result = await client({
|
|
307
|
+
prompt: userPrompt,
|
|
308
|
+
systemPrompt,
|
|
309
|
+
temperature: 0.9,
|
|
310
|
+
maxTokens: 4096
|
|
311
|
+
});
|
|
312
|
+
details.promptTokens = result.usage?.promptTokens;
|
|
313
|
+
details.completionTokens = result.usage?.completionTokens;
|
|
314
|
+
return result.text;
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function pickRandom(arr) {
|
|
322
|
+
const value = arr[Math.floor(Math.random() * arr.length)];
|
|
323
|
+
if (value === void 0) {
|
|
324
|
+
throw new Error("Cannot pick a random value from an empty array");
|
|
325
|
+
}
|
|
326
|
+
return value;
|
|
327
|
+
}
|
|
328
|
+
function pickN(arr, n) {
|
|
329
|
+
const shuffled = [...arr].sort(() => Math.random() - 0.5);
|
|
330
|
+
return shuffled.slice(0, n);
|
|
331
|
+
}
|
|
332
|
+
function randomAgentName(exclude = []) {
|
|
333
|
+
const available = AGENT_NAMES.filter(
|
|
334
|
+
(n) => !exclude.map((e) => e.toLowerCase()).includes(n.toLowerCase())
|
|
335
|
+
);
|
|
336
|
+
return pickRandom(available.length > 0 ? available : AGENT_NAMES);
|
|
337
|
+
}
|
|
338
|
+
function randomParticipants(count, exclude = []) {
|
|
339
|
+
const available = PARTICIPANT_NAMES.filter(
|
|
340
|
+
(n) => !exclude.map((e) => e.toLowerCase()).includes(n.toLowerCase())
|
|
341
|
+
);
|
|
342
|
+
return pickN(available, count);
|
|
343
|
+
}
|
|
344
|
+
function buildTeacherSystemPrompt() {
|
|
345
|
+
return `Generate synthetic multi-turn group chat conversations for training an AI agent's v5 messageHandler router.
|
|
346
|
+
Your task is to generate realistic multi-turn group chat conversations.
|
|
347
|
+
|
|
348
|
+
IMPORTANT RULES:
|
|
349
|
+
1. Output ONLY a JSON object. No markdown, no explanation, no preamble.
|
|
350
|
+
2. Each message must have "name" (speaker name) and "content" (message text).
|
|
351
|
+
3. Messages should feel natural - casual, varied length, sometimes with typos.
|
|
352
|
+
4. Group chats should have 3-6 participants plus optionally the agent.
|
|
353
|
+
5. The agent's messages (when present) should be clearly from an AI assistant.
|
|
354
|
+
6. NEVER include the expected messageHandler routing output in the conversation itself.
|
|
355
|
+
7. Messages should be diverse in tone: some short, some long, some with emoji.
|
|
356
|
+
|
|
357
|
+
Output format:
|
|
358
|
+
{"messages":[{"name":"Alice","content":"hey everyone"},{"name":"Bob","content":"what's up"}]}`;
|
|
359
|
+
}
|
|
360
|
+
function buildTeacherUserPrompt(blueprint, agentName, participants, platform, otherBotName, variant = 0) {
|
|
361
|
+
const turnRange = `${blueprint.minContextTurns}-${blueprint.maxContextTurns}`;
|
|
362
|
+
const participantList = participants.join(", ");
|
|
363
|
+
let extraInstructions = "";
|
|
364
|
+
if (blueprint.pattern === "group_wrong_agent" && otherBotName) {
|
|
365
|
+
extraInstructions = `There is ANOTHER bot named "${otherBotName}" in the chat. Someone addresses "${otherBotName}" (not "${agentName}"). "${agentName}" should NOT be addressed.`;
|
|
366
|
+
}
|
|
367
|
+
if (blueprint.pattern === "group_about_agent") {
|
|
368
|
+
extraInstructions = `People talk ABOUT "${agentName}" in third person ("the bot", "it", "${agentName} can do X") but NEVER address it directly. No "@${agentName}" or "${agentName}, can you...".`;
|
|
369
|
+
}
|
|
370
|
+
if (blueprint.pattern === "group_noise") {
|
|
371
|
+
extraInstructions = `"${agentName}" should NOT appear in any message at all. This is pure human conversation.`;
|
|
372
|
+
}
|
|
373
|
+
if (blueprint.pattern === "group_action_emergence") {
|
|
374
|
+
extraInstructions = `The intent to perform an action should emerge GRADUALLY over multiple messages. Users discuss the topic, one user's intent builds up, and finally they ask the agent to execute. The last 1-2 messages should clearly direct the agent.`;
|
|
375
|
+
}
|
|
376
|
+
if (blueprint.pattern === "group_multi_turn_intent") {
|
|
377
|
+
extraInstructions = `The action intent should build across 3+ messages from the same user. They start by observing/discussing, then express desire, then finally ask the agent to act.`;
|
|
378
|
+
}
|
|
379
|
+
const keywordsHint = blueprint.groundingKeywords.length > 0 ? `Try to naturally include some of these words/phrases: ${blueprint.groundingKeywords.join(", ")}` : "";
|
|
380
|
+
return `Generate variant #${variant + 1} of a ${platform} group chat conversation.
|
|
381
|
+
|
|
382
|
+
SCENARIO: ${blueprint.description}
|
|
383
|
+
AGENT NAME: ${agentName}
|
|
384
|
+
PARTICIPANTS: ${participantList}
|
|
385
|
+
PLATFORM: ${platform}
|
|
386
|
+
TARGET TURNS: ${turnRange} messages
|
|
387
|
+
CONVERSATION PATTERN: ${blueprint.pattern}
|
|
388
|
+
${keywordsHint}
|
|
389
|
+
${extraInstructions}
|
|
390
|
+
|
|
391
|
+
${blueprint.generationHint}
|
|
392
|
+
|
|
393
|
+
Remember:
|
|
394
|
+
- Output ONLY a JSON object with a messages array
|
|
395
|
+
- Each message has "name" and "content"
|
|
396
|
+
- Make it feel natural and realistic
|
|
397
|
+
- Vary message lengths and tones
|
|
398
|
+
- The last message should be the one the messageHandler router evaluates`;
|
|
399
|
+
}
|
|
400
|
+
function stripOutputFences(raw) {
|
|
401
|
+
return raw.replace(/^```[a-z0-9_-]*\s*/i, "").replace(/\s*```$/i, "").trim();
|
|
402
|
+
}
|
|
403
|
+
function parseTeacherJsonMessages(raw) {
|
|
404
|
+
const cleaned = stripOutputFences(raw);
|
|
405
|
+
const parsed = JSON.parse(cleaned);
|
|
406
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
407
|
+
throw new Error("Teacher output must be a JSON object");
|
|
408
|
+
}
|
|
409
|
+
const messages = parsed.messages;
|
|
410
|
+
if (!Array.isArray(messages)) {
|
|
411
|
+
throw new Error("Teacher JSON output must include a messages array");
|
|
412
|
+
}
|
|
413
|
+
const parsedMessages = messages.filter(
|
|
414
|
+
(message) => Boolean(message) && typeof message === "object" && !Array.isArray(message)
|
|
415
|
+
).map((message) => ({
|
|
416
|
+
name: String(message.name ?? "").trim(),
|
|
417
|
+
content: String(message.content ?? "").trim()
|
|
418
|
+
})).filter((message) => message.name.length > 0 && message.content.length > 0);
|
|
419
|
+
if (parsedMessages.length === 0) {
|
|
420
|
+
throw new Error("Teacher JSON output did not include valid messages");
|
|
421
|
+
}
|
|
422
|
+
return {
|
|
423
|
+
messages: parsedMessages
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
function parseTeacherLegacyMessages(raw) {
|
|
427
|
+
const text = stripOutputFences(raw);
|
|
428
|
+
const lines = text.split(/\r?\n/);
|
|
429
|
+
const messages = [];
|
|
430
|
+
let current = null;
|
|
431
|
+
const flush = () => {
|
|
432
|
+
if (current?.name && current.content !== void 0) {
|
|
433
|
+
messages.push({
|
|
434
|
+
name: current.name.trim(),
|
|
435
|
+
content: current.content.trim()
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
current = null;
|
|
439
|
+
};
|
|
440
|
+
for (const line of lines) {
|
|
441
|
+
const trimmed = line.trim();
|
|
442
|
+
if (!trimmed || /^messages(?::|\[)/i.test(trimmed)) continue;
|
|
443
|
+
const rowMatch = trimmed.match(/^-\s*([^|:]+?)\s*\|\s*(.*)$/);
|
|
444
|
+
if (rowMatch) {
|
|
445
|
+
flush();
|
|
446
|
+
messages.push({
|
|
447
|
+
name: (rowMatch[1] ?? "").trim(),
|
|
448
|
+
content: (rowMatch[2] ?? "").trim()
|
|
449
|
+
});
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
const itemNameMatch = trimmed.match(/^-\s*name:\s*(.*)$/i);
|
|
453
|
+
if (itemNameMatch) {
|
|
454
|
+
flush();
|
|
455
|
+
current = { name: (itemNameMatch[1] ?? "").trim() };
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
const nameMatch = trimmed.match(/^name:\s*(.*)$/i);
|
|
459
|
+
if (nameMatch) {
|
|
460
|
+
current ??= {};
|
|
461
|
+
current.name = (nameMatch[1] ?? "").trim();
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
const contentMatch = trimmed.match(/^content:\s*(.*)$/i);
|
|
465
|
+
if (contentMatch) {
|
|
466
|
+
current ??= {};
|
|
467
|
+
current.content = (contentMatch[1] ?? "").trim();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
flush();
|
|
471
|
+
if (messages.length === 0) {
|
|
472
|
+
throw new Error("No teacher messages found in legacy output");
|
|
473
|
+
}
|
|
474
|
+
return { messages };
|
|
475
|
+
}
|
|
476
|
+
async function generateSample(blueprint, teacher, variant, totalVariants) {
|
|
477
|
+
const agentName = randomAgentName();
|
|
478
|
+
const participantCount = 3 + Math.floor(Math.random() * 3);
|
|
479
|
+
const participants = randomParticipants(participantCount, [agentName]);
|
|
480
|
+
const platform = pickRandom(PLATFORMS);
|
|
481
|
+
const otherBotName = blueprint.pattern === "group_wrong_agent" ? pickRandom(OTHER_BOT_NAMES) : void 0;
|
|
482
|
+
const systemPrompt = buildTeacherSystemPrompt();
|
|
483
|
+
const userPrompt = buildTeacherUserPrompt(
|
|
484
|
+
blueprint,
|
|
485
|
+
agentName,
|
|
486
|
+
participants,
|
|
487
|
+
platform,
|
|
488
|
+
otherBotName,
|
|
489
|
+
variant
|
|
490
|
+
);
|
|
491
|
+
const raw = await teacher.generate(systemPrompt, userPrompt);
|
|
492
|
+
let parsed;
|
|
493
|
+
try {
|
|
494
|
+
parsed = parseTeacherJsonMessages(raw);
|
|
495
|
+
} catch {
|
|
496
|
+
try {
|
|
497
|
+
parsed = parseTeacherLegacyMessages(raw);
|
|
498
|
+
} catch {
|
|
499
|
+
const [firstParticipant = "Alice", secondParticipant = "Bob"] = participants;
|
|
500
|
+
parsed = {
|
|
501
|
+
messages: [
|
|
502
|
+
{ name: firstParticipant, content: "Hey everyone" },
|
|
503
|
+
{
|
|
504
|
+
name: secondParticipant,
|
|
505
|
+
content: blueprint.decision === "RESPOND" ? `${agentName}, can you help?` : "What's for lunch?"
|
|
506
|
+
}
|
|
507
|
+
]
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
const messages = parsed.messages.map((m) => ({
|
|
512
|
+
role: m.name.trim().toLowerCase() === agentName.trim().toLowerCase() ? "assistant" : "user",
|
|
513
|
+
name: m.name,
|
|
514
|
+
content: m.content
|
|
515
|
+
}));
|
|
516
|
+
const expectedOutput = {
|
|
517
|
+
decision: blueprint.decision,
|
|
518
|
+
primaryContext: blueprint.primaryContext,
|
|
519
|
+
secondaryContexts: blueprint.secondaryContexts ?? [],
|
|
520
|
+
reasoning: blueprint.description,
|
|
521
|
+
expectedAction: blueprint.expectedAction
|
|
522
|
+
};
|
|
523
|
+
return {
|
|
524
|
+
id: randomUUID(),
|
|
525
|
+
blueprintId: blueprint.id,
|
|
526
|
+
agentName,
|
|
527
|
+
messages,
|
|
528
|
+
expectedOutput,
|
|
529
|
+
metadata: {
|
|
530
|
+
platform,
|
|
531
|
+
pattern: blueprint.pattern,
|
|
532
|
+
turnCount: messages.length,
|
|
533
|
+
generatedBy: teacher.name,
|
|
534
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
535
|
+
variant,
|
|
536
|
+
totalVariants
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
async function generateDataset(config) {
|
|
541
|
+
let blueprints = ALL_BLUEPRINTS;
|
|
542
|
+
if (config.filterContexts) {
|
|
543
|
+
const ctxSet = new Set(config.filterContexts);
|
|
544
|
+
blueprints = blueprints.filter(
|
|
545
|
+
(b) => ctxSet.has(b.primaryContext) || b.secondaryContexts?.some((c) => ctxSet.has(c))
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
if (config.filterDecisions) {
|
|
549
|
+
const decSet = new Set(config.filterDecisions);
|
|
550
|
+
blueprints = blueprints.filter((b) => decSet.has(b.decision));
|
|
551
|
+
}
|
|
552
|
+
if (config.limitBlueprints && config.limitBlueprints > 0) {
|
|
553
|
+
blueprints = blueprints.slice(0, config.limitBlueprints);
|
|
554
|
+
}
|
|
555
|
+
const totalSamples = blueprints.length * config.variantsPerBlueprint;
|
|
556
|
+
const samples = [];
|
|
557
|
+
let completed = 0;
|
|
558
|
+
const concurrency = config.concurrency ?? 5;
|
|
559
|
+
const tasks = [];
|
|
560
|
+
for (const blueprint of blueprints) {
|
|
561
|
+
for (let v = 0; v < config.variantsPerBlueprint; v++) {
|
|
562
|
+
tasks.push(
|
|
563
|
+
() => generateSample(
|
|
564
|
+
blueprint,
|
|
565
|
+
config.teacher,
|
|
566
|
+
v,
|
|
567
|
+
config.variantsPerBlueprint
|
|
568
|
+
)
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
for (let i = 0; i < tasks.length; i += concurrency) {
|
|
573
|
+
const batch = tasks.slice(i, i + concurrency);
|
|
574
|
+
const results = await Promise.allSettled(batch.map((fn) => fn()));
|
|
575
|
+
for (const result of results) {
|
|
576
|
+
completed++;
|
|
577
|
+
if (result.status === "fulfilled") {
|
|
578
|
+
samples.push(result.value);
|
|
579
|
+
config.onProgress?.(completed, totalSamples, result.value);
|
|
580
|
+
} else {
|
|
581
|
+
console.error(`Failed to generate sample: ${result.reason}`);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return samples;
|
|
586
|
+
}
|
|
587
|
+
function toElizaNativeFormat(sample, includeContextRouting = true) {
|
|
588
|
+
const systemContent = buildShouldRespondSystemPrompt(
|
|
589
|
+
sample,
|
|
590
|
+
includeContextRouting
|
|
591
|
+
);
|
|
592
|
+
const userContent = buildShouldRespondUserPrompt(sample);
|
|
593
|
+
const responseText = buildMessageHandlerJsonResponse(
|
|
594
|
+
sample,
|
|
595
|
+
includeContextRouting
|
|
596
|
+
);
|
|
597
|
+
return {
|
|
598
|
+
format: ELIZA_NATIVE_TRAJECTORY_FORMAT,
|
|
599
|
+
schemaVersion: 1,
|
|
600
|
+
boundary: "vercel_ai_sdk.generateText",
|
|
601
|
+
trajectoryId: sample.id,
|
|
602
|
+
agentId: sample.agentName,
|
|
603
|
+
source: "app-training",
|
|
604
|
+
status: "completed",
|
|
605
|
+
stepId: `${sample.id}:message-handler`,
|
|
606
|
+
callId: `${sample.id}:message-handler:call-1`,
|
|
607
|
+
stepIndex: 0,
|
|
608
|
+
callIndex: 0,
|
|
609
|
+
timestamp: Date.parse(sample.metadata.generatedAt) || Date.now(),
|
|
610
|
+
purpose: "should_respond",
|
|
611
|
+
actionType: "app-training.synthetic.message_handler",
|
|
612
|
+
stepType: includeContextRouting ? "context_routing" : "should_respond",
|
|
613
|
+
tags: ["synthetic", "message_handler"],
|
|
614
|
+
model: "teacher",
|
|
615
|
+
request: {
|
|
616
|
+
messages: [
|
|
617
|
+
{ role: "system", content: systemContent },
|
|
618
|
+
{ role: "user", content: userContent }
|
|
619
|
+
]
|
|
620
|
+
},
|
|
621
|
+
response: {
|
|
622
|
+
text: responseText
|
|
623
|
+
},
|
|
624
|
+
metadata: {
|
|
625
|
+
task_type: includeContextRouting ? "context_routing" : "should_respond",
|
|
626
|
+
source_dataset: "app_training_synthetic",
|
|
627
|
+
trajectory_id: sample.id,
|
|
628
|
+
step_id: `${sample.id}:message-handler`,
|
|
629
|
+
call_id: `${sample.id}:message-handler:call-1`,
|
|
630
|
+
agent_id: sample.agentName,
|
|
631
|
+
blueprint_id: sample.blueprintId,
|
|
632
|
+
platform: sample.metadata.platform,
|
|
633
|
+
pattern: sample.metadata.pattern
|
|
634
|
+
},
|
|
635
|
+
trajectoryTotals: {
|
|
636
|
+
stepCount: 1,
|
|
637
|
+
llmCallCount: 1,
|
|
638
|
+
providerAccessCount: 0,
|
|
639
|
+
promptTokens: 0,
|
|
640
|
+
completionTokens: 0,
|
|
641
|
+
cacheReadInputTokens: 0,
|
|
642
|
+
cacheCreationInputTokens: 0
|
|
643
|
+
},
|
|
644
|
+
cacheStats: {
|
|
645
|
+
totalInputTokens: 0,
|
|
646
|
+
promptTokens: 0,
|
|
647
|
+
completionTokens: 0,
|
|
648
|
+
cacheReadInputTokens: 0,
|
|
649
|
+
cacheCreationInputTokens: 0,
|
|
650
|
+
cachedCallCount: 0,
|
|
651
|
+
cacheReadCallCount: 0,
|
|
652
|
+
cacheWriteCallCount: 0,
|
|
653
|
+
tokenUsageEstimatedCallCount: 0
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function renderTemplate(template, values) {
|
|
658
|
+
return template.replace(/{{(\w+)}}/g, (_match, key) => values[key] ?? "");
|
|
659
|
+
}
|
|
660
|
+
function uniqueStrings(values) {
|
|
661
|
+
return [...new Set(values.filter((value) => value.trim().length > 0))];
|
|
662
|
+
}
|
|
663
|
+
function listContextsForSample(sample) {
|
|
664
|
+
const contexts = /* @__PURE__ */ new Set([
|
|
665
|
+
"general",
|
|
666
|
+
sample.expectedOutput.primaryContext,
|
|
667
|
+
...sample.expectedOutput.secondaryContexts
|
|
668
|
+
]);
|
|
669
|
+
if (sample.expectedOutput.expectedAction) {
|
|
670
|
+
for (const actionContext of ACTION_CONTEXT_MAP[sample.expectedOutput.expectedAction] ?? []) {
|
|
671
|
+
contexts.add(actionContext);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return [...contexts];
|
|
675
|
+
}
|
|
676
|
+
function listMessageHandlerContextsForSample(sample) {
|
|
677
|
+
const contexts = /* @__PURE__ */ new Set([
|
|
678
|
+
sample.expectedOutput.primaryContext,
|
|
679
|
+
...sample.expectedOutput.secondaryContexts
|
|
680
|
+
]);
|
|
681
|
+
if (sample.expectedOutput.expectedAction) {
|
|
682
|
+
for (const actionContext of ACTION_CONTEXT_MAP[sample.expectedOutput.expectedAction] ?? []) {
|
|
683
|
+
contexts.add(actionContext);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
contexts.delete("general");
|
|
687
|
+
return [...contexts];
|
|
688
|
+
}
|
|
689
|
+
function getRelevantActions(sample) {
|
|
690
|
+
const activeContexts = new Set(listContextsForSample(sample));
|
|
691
|
+
const contextualActions = Object.entries(ACTION_CONTEXT_MAP).filter(
|
|
692
|
+
([, contexts]) => contexts.some((context) => activeContexts.has(context))
|
|
693
|
+
).map(([actionName]) => actionName);
|
|
694
|
+
return uniqueStrings([
|
|
695
|
+
sample.expectedOutput.expectedAction ?? "",
|
|
696
|
+
...contextualActions
|
|
697
|
+
]).slice(0, 18);
|
|
698
|
+
}
|
|
699
|
+
function getRelevantProviders(sample) {
|
|
700
|
+
const activeContexts = new Set(listContextsForSample(sample));
|
|
701
|
+
return Object.entries(PROVIDER_CONTEXT_MAP).filter(
|
|
702
|
+
([, contexts]) => contexts.some((context) => activeContexts.has(context))
|
|
703
|
+
).map(([providerName]) => providerName).slice(0, 12);
|
|
704
|
+
}
|
|
705
|
+
function buildProvidersBlock(sample) {
|
|
706
|
+
const actions = getRelevantActions(sample);
|
|
707
|
+
const providers = getRelevantProviders(sample);
|
|
708
|
+
return [
|
|
709
|
+
`platform: ${sample.metadata.platform}`,
|
|
710
|
+
"actions:",
|
|
711
|
+
...(actions.length > 0 ? actions : ["REPLY"]).map(
|
|
712
|
+
(action) => `- ${action}`
|
|
713
|
+
),
|
|
714
|
+
"providers:",
|
|
715
|
+
...(providers.length > 0 ? providers : ["recentMessages"]).map(
|
|
716
|
+
(provider) => `- ${provider}`
|
|
717
|
+
)
|
|
718
|
+
].join("\n");
|
|
719
|
+
}
|
|
720
|
+
function buildShouldRespondSystemPrompt(sample, includeContextRouting) {
|
|
721
|
+
const baseTemplate = includeContextRouting ? SHOULD_RESPOND_PROMPT_TEMPLATE : SHOULD_RESPOND_PROMPT_TEMPLATE.replace(
|
|
722
|
+
/\nmessage_handler:[\s\S]*?\ndecision_note:/m,
|
|
723
|
+
"\ndecision_note:"
|
|
724
|
+
).replace(
|
|
725
|
+
/\nExample:\n\{"messageHandler":\{"action":"RESPOND"[\s\S]*$/m,
|
|
726
|
+
'\nExample:\n{"messageHandler":{"action":"RESPOND","simple":true,"contexts":[],"thought":"Direct mention can be answered directly.","reply":""}}'
|
|
727
|
+
);
|
|
728
|
+
return renderTemplate(baseTemplate, {
|
|
729
|
+
agentName: sample.agentName,
|
|
730
|
+
providers: buildProvidersBlock(sample),
|
|
731
|
+
availableContexts: listContextsForSample(sample).join(", ")
|
|
732
|
+
}).trim();
|
|
733
|
+
}
|
|
734
|
+
function buildShouldRespondUserPrompt(sample) {
|
|
735
|
+
const conversationLines = sample.messages.map((message, index) => {
|
|
736
|
+
const turnId = `turn-${String(index + 1).padStart(3, "0")}`;
|
|
737
|
+
const speaker = message.role === "assistant" ? sample.agentName : message.name ?? "user";
|
|
738
|
+
return `[${turnId}] ${speaker}: ${message.content}`;
|
|
739
|
+
}).join("\n");
|
|
740
|
+
return [
|
|
741
|
+
`platform: ${sample.metadata.platform}`,
|
|
742
|
+
`agent_name: ${sample.agentName}`,
|
|
743
|
+
"conversation:",
|
|
744
|
+
conversationLines,
|
|
745
|
+
"decision_target: evaluate the final message in this group-chat window."
|
|
746
|
+
].join("\n");
|
|
747
|
+
}
|
|
748
|
+
function buildMessageHandlerJsonResponse(sample, includeContextRouting) {
|
|
749
|
+
const contexts = includeContextRouting && sample.expectedOutput.decision === "RESPOND" ? listMessageHandlerContextsForSample(sample) : [];
|
|
750
|
+
const output = {
|
|
751
|
+
messageHandler: {
|
|
752
|
+
action: sample.expectedOutput.decision,
|
|
753
|
+
simple: sample.expectedOutput.decision === "RESPOND" && contexts.length === 0,
|
|
754
|
+
contexts,
|
|
755
|
+
thought: sample.expectedOutput.reasoning,
|
|
756
|
+
reply: ""
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
return JSON.stringify(output);
|
|
760
|
+
}
|
|
761
|
+
function normalizeMessageHandlerJson(response) {
|
|
762
|
+
const trimmed = response.trim().replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/i, "");
|
|
763
|
+
if (!trimmed.startsWith("{")) {
|
|
764
|
+
return null;
|
|
765
|
+
}
|
|
766
|
+
try {
|
|
767
|
+
const parsed = JSON.parse(trimmed);
|
|
768
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
const record = parsed;
|
|
772
|
+
const candidate = record.messageHandler && typeof record.messageHandler === "object" && !Array.isArray(record.messageHandler) ? record.messageHandler : record;
|
|
773
|
+
const action = candidate.action;
|
|
774
|
+
if (action !== "RESPOND" && action !== "IGNORE" && action !== "STOP") {
|
|
775
|
+
return null;
|
|
776
|
+
}
|
|
777
|
+
const contexts = Array.isArray(candidate.contexts) ? candidate.contexts.filter(
|
|
778
|
+
(context) => typeof context === "string"
|
|
779
|
+
) : [];
|
|
780
|
+
return JSON.stringify({
|
|
781
|
+
messageHandler: {
|
|
782
|
+
action,
|
|
783
|
+
contexts,
|
|
784
|
+
thought: typeof candidate.thought === "string" ? candidate.thought : "",
|
|
785
|
+
reply: typeof candidate.reply === "string" ? candidate.reply : ""
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
} catch {
|
|
789
|
+
return null;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
async function exportToElizaNativeJSONL(samples, outputDir) {
|
|
793
|
+
await mkdir(outputDir, { recursive: true });
|
|
794
|
+
const combinedPath = join(outputDir, "combined_training.eliza-native.jsonl");
|
|
795
|
+
const combinedLines = samples.map((s) => JSON.stringify(toElizaNativeFormat(s, true))).join("\n");
|
|
796
|
+
await writeFile(combinedPath, `${combinedLines}
|
|
797
|
+
`);
|
|
798
|
+
const shouldRespondPath = join(
|
|
799
|
+
outputDir,
|
|
800
|
+
"should_respond_training.eliza-native.jsonl"
|
|
801
|
+
);
|
|
802
|
+
const srLines = samples.map((s) => JSON.stringify(toElizaNativeFormat(s, false))).join("\n");
|
|
803
|
+
await writeFile(shouldRespondPath, `${srLines}
|
|
804
|
+
`);
|
|
805
|
+
const contextRoutingPath = join(
|
|
806
|
+
outputDir,
|
|
807
|
+
"context_routing_training.eliza-native.jsonl"
|
|
808
|
+
);
|
|
809
|
+
const crLines = samples.filter((s) => s.expectedOutput.decision === "RESPOND").map((s) => JSON.stringify(toElizaNativeFormat(s, true))).join("\n");
|
|
810
|
+
await writeFile(contextRoutingPath, `${crLines}
|
|
811
|
+
`);
|
|
812
|
+
const rawPath = join(outputDir, "raw_samples.json");
|
|
813
|
+
await writeFile(rawPath, JSON.stringify(samples, null, 2));
|
|
814
|
+
const stats = {
|
|
815
|
+
totalSamples: samples.length,
|
|
816
|
+
byDecision: {
|
|
817
|
+
RESPOND: samples.filter((s) => s.expectedOutput.decision === "RESPOND").length,
|
|
818
|
+
IGNORE: samples.filter((s) => s.expectedOutput.decision === "IGNORE").length,
|
|
819
|
+
STOP: samples.filter((s) => s.expectedOutput.decision === "STOP").length
|
|
820
|
+
},
|
|
821
|
+
byContext: Object.fromEntries(
|
|
822
|
+
ALL_CONTEXTS.map((ctx) => [
|
|
823
|
+
ctx,
|
|
824
|
+
samples.filter((s) => s.expectedOutput.primaryContext === ctx).length
|
|
825
|
+
])
|
|
826
|
+
),
|
|
827
|
+
byPattern: Object.fromEntries(
|
|
828
|
+
[...new Set(samples.map((s) => s.metadata.pattern))].map((p) => [
|
|
829
|
+
p,
|
|
830
|
+
samples.filter((s) => s.metadata.pattern === p).length
|
|
831
|
+
])
|
|
832
|
+
),
|
|
833
|
+
uniqueAgentNames: new Set(samples.map((s) => s.agentName)).size,
|
|
834
|
+
avgTurnCount: samples.reduce((sum, s) => sum + s.metadata.turnCount, 0) / samples.length,
|
|
835
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
836
|
+
};
|
|
837
|
+
await writeFile(
|
|
838
|
+
join(outputDir, "stats.json"),
|
|
839
|
+
JSON.stringify(stats, null, 2)
|
|
840
|
+
);
|
|
841
|
+
return { shouldRespondPath, contextRoutingPath, combinedPath };
|
|
842
|
+
}
|
|
843
|
+
async function exportTrajectoriesAsTraining(trajectories, agentName, outputPath) {
|
|
844
|
+
const examples = [];
|
|
845
|
+
let skippedNonNativeRows = 0;
|
|
846
|
+
void agentName;
|
|
847
|
+
for (const trajectory of trajectories) {
|
|
848
|
+
for (const call of iterateTrajectoryLlmCalls(trajectory)) {
|
|
849
|
+
if (call.purpose === "should_respond") {
|
|
850
|
+
const response = normalizeMessageHandlerJson(call.response ?? "");
|
|
851
|
+
if (!response) {
|
|
852
|
+
skippedNonNativeRows += 1;
|
|
853
|
+
console.warn(
|
|
854
|
+
`[dataset-generator] skipped non-native should_respond row from trajectory ${trajectory.trajectoryId} call ${call.callId}; expected native messageHandler JSON`
|
|
855
|
+
);
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
const row = buildElizaNativeTrajectoryRows([trajectory]).find(
|
|
859
|
+
(candidate) => candidate.callId === call.callId
|
|
860
|
+
);
|
|
861
|
+
if (row) {
|
|
862
|
+
examples.push({
|
|
863
|
+
...row,
|
|
864
|
+
response: { ...row.response, text: response },
|
|
865
|
+
metadata: {
|
|
866
|
+
...row.metadata,
|
|
867
|
+
task_type: "should_respond",
|
|
868
|
+
source_dataset: "runtime_trajectory_boundary"
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
const content = examples.map((e) => JSON.stringify(e)).join("\n");
|
|
876
|
+
await writeFile(outputPath, `${content}
|
|
877
|
+
`);
|
|
878
|
+
if (skippedNonNativeRows > 0) {
|
|
879
|
+
console.warn(
|
|
880
|
+
`[dataset-generator] skipped ${skippedNonNativeRows} non-native should_respond rows while exporting ${outputPath}`
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
return examples.length;
|
|
884
|
+
}
|
|
885
|
+
export {
|
|
886
|
+
createAnthropicTeacher,
|
|
887
|
+
createCerebrasTeacher,
|
|
888
|
+
createOpenAITeacher,
|
|
889
|
+
exportToElizaNativeJSONL,
|
|
890
|
+
exportTrajectoriesAsTraining,
|
|
891
|
+
generateDataset,
|
|
892
|
+
generateSample,
|
|
893
|
+
toElizaNativeFormat
|
|
894
|
+
};
|
|
895
|
+
//# sourceMappingURL=dataset-generator.js.map
|