@juspay/neurolink 9.3.0 → 9.5.0

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 (128) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +8 -8
  3. package/dist/cli/commands/config.d.ts +3 -3
  4. package/dist/cli/index.js +1 -0
  5. package/dist/index.d.ts +35 -0
  6. package/dist/index.js +17 -0
  7. package/dist/lib/agent/directTools.d.ts +5 -5
  8. package/dist/lib/index.d.ts +35 -0
  9. package/dist/lib/index.js +17 -0
  10. package/dist/lib/neurolink.d.ts +12 -1
  11. package/dist/lib/neurolink.js +265 -4
  12. package/dist/lib/server/utils/validation.d.ts +8 -8
  13. package/dist/lib/types/generateTypes.d.ts +28 -0
  14. package/dist/lib/types/index.d.ts +6 -0
  15. package/dist/lib/types/index.js +12 -0
  16. package/dist/lib/types/modelTypes.d.ts +2 -2
  17. package/dist/lib/types/streamTypes.d.ts +35 -0
  18. package/dist/lib/types/workflowTypes.d.ts +558 -0
  19. package/dist/lib/types/workflowTypes.js +32 -0
  20. package/dist/lib/workflow/LAYER-EXAMPLES.d.ts +13 -0
  21. package/dist/lib/workflow/LAYER-EXAMPLES.js +312 -0
  22. package/dist/lib/workflow/PROMPT-EXAMPLES.d.ts +117 -0
  23. package/dist/lib/workflow/PROMPT-EXAMPLES.js +246 -0
  24. package/dist/lib/workflow/config.d.ts +1569 -0
  25. package/dist/lib/workflow/config.js +399 -0
  26. package/dist/lib/workflow/core/ensembleExecutor.d.ts +56 -0
  27. package/dist/lib/workflow/core/ensembleExecutor.js +398 -0
  28. package/dist/lib/workflow/core/judgeScorer.d.ts +26 -0
  29. package/dist/lib/workflow/core/judgeScorer.js +527 -0
  30. package/dist/lib/workflow/core/responseConditioner.d.ts +22 -0
  31. package/dist/lib/workflow/core/responseConditioner.js +226 -0
  32. package/dist/lib/workflow/core/types/conditionerTypes.d.ts +7 -0
  33. package/dist/lib/workflow/core/types/conditionerTypes.js +8 -0
  34. package/dist/lib/workflow/core/types/ensembleTypes.d.ts +7 -0
  35. package/dist/lib/workflow/core/types/ensembleTypes.js +8 -0
  36. package/dist/lib/workflow/core/types/index.d.ts +7 -0
  37. package/dist/lib/workflow/core/types/index.js +8 -0
  38. package/dist/lib/workflow/core/types/judgeTypes.d.ts +7 -0
  39. package/dist/lib/workflow/core/types/judgeTypes.js +8 -0
  40. package/dist/lib/workflow/core/types/layerTypes.d.ts +7 -0
  41. package/dist/lib/workflow/core/types/layerTypes.js +8 -0
  42. package/dist/lib/workflow/core/types/registryTypes.d.ts +7 -0
  43. package/dist/lib/workflow/core/types/registryTypes.js +8 -0
  44. package/dist/lib/workflow/core/workflowRegistry.d.ts +73 -0
  45. package/dist/lib/workflow/core/workflowRegistry.js +305 -0
  46. package/dist/lib/workflow/core/workflowRunner.d.ts +115 -0
  47. package/dist/lib/workflow/core/workflowRunner.js +554 -0
  48. package/dist/lib/workflow/index.d.ts +36 -0
  49. package/dist/lib/workflow/index.js +51 -0
  50. package/dist/lib/workflow/types.d.ts +19 -0
  51. package/dist/lib/workflow/types.js +10 -0
  52. package/dist/lib/workflow/utils/types/index.d.ts +7 -0
  53. package/dist/lib/workflow/utils/types/index.js +8 -0
  54. package/dist/lib/workflow/utils/types/metricsTypes.d.ts +7 -0
  55. package/dist/lib/workflow/utils/types/metricsTypes.js +8 -0
  56. package/dist/lib/workflow/utils/types/validationTypes.d.ts +7 -0
  57. package/dist/lib/workflow/utils/types/validationTypes.js +8 -0
  58. package/dist/lib/workflow/utils/workflowMetrics.d.ts +76 -0
  59. package/dist/lib/workflow/utils/workflowMetrics.js +312 -0
  60. package/dist/lib/workflow/utils/workflowValidation.d.ts +29 -0
  61. package/dist/lib/workflow/utils/workflowValidation.js +421 -0
  62. package/dist/lib/workflow/workflows/adaptiveWorkflow.d.ts +72 -0
  63. package/dist/lib/workflow/workflows/adaptiveWorkflow.js +367 -0
  64. package/dist/lib/workflow/workflows/consensusWorkflow.d.ts +69 -0
  65. package/dist/lib/workflow/workflows/consensusWorkflow.js +193 -0
  66. package/dist/lib/workflow/workflows/fallbackWorkflow.d.ts +49 -0
  67. package/dist/lib/workflow/workflows/fallbackWorkflow.js +226 -0
  68. package/dist/lib/workflow/workflows/multiJudgeWorkflow.d.ts +70 -0
  69. package/dist/lib/workflow/workflows/multiJudgeWorkflow.js +352 -0
  70. package/dist/neurolink.d.ts +12 -1
  71. package/dist/neurolink.js +265 -4
  72. package/dist/types/generateTypes.d.ts +28 -0
  73. package/dist/types/index.d.ts +6 -0
  74. package/dist/types/index.js +12 -0
  75. package/dist/types/streamTypes.d.ts +35 -0
  76. package/dist/types/workflowTypes.d.ts +558 -0
  77. package/dist/types/workflowTypes.js +31 -0
  78. package/dist/workflow/LAYER-EXAMPLES.d.ts +13 -0
  79. package/dist/workflow/LAYER-EXAMPLES.js +311 -0
  80. package/dist/workflow/PROMPT-EXAMPLES.d.ts +117 -0
  81. package/dist/workflow/PROMPT-EXAMPLES.js +245 -0
  82. package/dist/workflow/config.d.ts +1569 -0
  83. package/dist/workflow/config.js +398 -0
  84. package/dist/workflow/core/ensembleExecutor.d.ts +56 -0
  85. package/dist/workflow/core/ensembleExecutor.js +397 -0
  86. package/dist/workflow/core/judgeScorer.d.ts +26 -0
  87. package/dist/workflow/core/judgeScorer.js +526 -0
  88. package/dist/workflow/core/responseConditioner.d.ts +22 -0
  89. package/dist/workflow/core/responseConditioner.js +225 -0
  90. package/dist/workflow/core/types/conditionerTypes.d.ts +7 -0
  91. package/dist/workflow/core/types/conditionerTypes.js +7 -0
  92. package/dist/workflow/core/types/ensembleTypes.d.ts +7 -0
  93. package/dist/workflow/core/types/ensembleTypes.js +7 -0
  94. package/dist/workflow/core/types/index.d.ts +7 -0
  95. package/dist/workflow/core/types/index.js +7 -0
  96. package/dist/workflow/core/types/judgeTypes.d.ts +7 -0
  97. package/dist/workflow/core/types/judgeTypes.js +7 -0
  98. package/dist/workflow/core/types/layerTypes.d.ts +7 -0
  99. package/dist/workflow/core/types/layerTypes.js +7 -0
  100. package/dist/workflow/core/types/registryTypes.d.ts +7 -0
  101. package/dist/workflow/core/types/registryTypes.js +7 -0
  102. package/dist/workflow/core/workflowRegistry.d.ts +73 -0
  103. package/dist/workflow/core/workflowRegistry.js +304 -0
  104. package/dist/workflow/core/workflowRunner.d.ts +115 -0
  105. package/dist/workflow/core/workflowRunner.js +553 -0
  106. package/dist/workflow/index.d.ts +36 -0
  107. package/dist/workflow/index.js +50 -0
  108. package/dist/workflow/types.d.ts +19 -0
  109. package/dist/workflow/types.js +9 -0
  110. package/dist/workflow/utils/types/index.d.ts +7 -0
  111. package/dist/workflow/utils/types/index.js +7 -0
  112. package/dist/workflow/utils/types/metricsTypes.d.ts +7 -0
  113. package/dist/workflow/utils/types/metricsTypes.js +7 -0
  114. package/dist/workflow/utils/types/validationTypes.d.ts +7 -0
  115. package/dist/workflow/utils/types/validationTypes.js +7 -0
  116. package/dist/workflow/utils/workflowMetrics.d.ts +76 -0
  117. package/dist/workflow/utils/workflowMetrics.js +311 -0
  118. package/dist/workflow/utils/workflowValidation.d.ts +29 -0
  119. package/dist/workflow/utils/workflowValidation.js +420 -0
  120. package/dist/workflow/workflows/adaptiveWorkflow.d.ts +72 -0
  121. package/dist/workflow/workflows/adaptiveWorkflow.js +366 -0
  122. package/dist/workflow/workflows/consensusWorkflow.d.ts +69 -0
  123. package/dist/workflow/workflows/consensusWorkflow.js +192 -0
  124. package/dist/workflow/workflows/fallbackWorkflow.d.ts +49 -0
  125. package/dist/workflow/workflows/fallbackWorkflow.js +225 -0
  126. package/dist/workflow/workflows/multiJudgeWorkflow.d.ts +70 -0
  127. package/dist/workflow/workflows/multiJudgeWorkflow.js +351 -0
  128. package/package.json +3 -2
@@ -0,0 +1,312 @@
1
+ /**
2
+ * LAYER-BASED EXECUTION - USAGE EXAMPLES
3
+ * ======================================
4
+ *
5
+ * Demonstrates ModelGroup-based execution with sequential and parallel strategies
6
+ */
7
+ import { AIProviderName } from "../constants/enums.js";
8
+ // ============================================================================
9
+ // EXAMPLE 1: Simple Parallel (Backward Compatible - Flat Models Array)
10
+ // ============================================================================
11
+ const simpleParallelWorkflow = {
12
+ id: "simple-parallel",
13
+ name: "Simple Parallel Workflow",
14
+ type: "ensemble",
15
+ // Traditional flat array - all execute in parallel
16
+ models: [
17
+ { provider: AIProviderName.OPENAI, model: "gpt-4o" },
18
+ { provider: AIProviderName.ANTHROPIC, model: "claude-3-5-sonnet-20241022" },
19
+ { provider: AIProviderName.GOOGLE_AI, model: "gemini-2.0-flash" },
20
+ ],
21
+ judge: {
22
+ provider: AIProviderName.OPENAI,
23
+ model: "gpt-4o",
24
+ criteria: ["accuracy", "clarity"],
25
+ outputFormat: "detailed",
26
+ includeReasoning: true,
27
+ scoreScale: { min: 0, max: 100 },
28
+ },
29
+ };
30
+ // ============================================================================
31
+ // EXAMPLE 2: Fast-then-Premium (Sequential Groups)
32
+ // ============================================================================
33
+ const fastThenPremiumWorkflow = {
34
+ id: "fast-then-premium",
35
+ name: "Fast Models First, Premium If Needed",
36
+ type: "adaptive",
37
+ // Define execution layers
38
+ modelGroups: [
39
+ {
40
+ id: "fast-tier",
41
+ name: "Fast Models",
42
+ description: "Quick, cost-effective models",
43
+ models: [
44
+ { provider: AIProviderName.OPENAI, model: "gpt-4o-mini" },
45
+ { provider: AIProviderName.GOOGLE_AI, model: "gemini-2.0-flash" },
46
+ ],
47
+ executionStrategy: "parallel", // Both run simultaneously
48
+ continueOnFailure: true, // Always proceed to next group
49
+ minSuccessful: 1, // Need at least 1 success
50
+ },
51
+ {
52
+ id: "premium-tier",
53
+ name: "Premium Models",
54
+ description: "High-quality, more expensive models",
55
+ models: [
56
+ { provider: AIProviderName.OPENAI, model: "gpt-4o" },
57
+ {
58
+ provider: AIProviderName.ANTHROPIC,
59
+ model: "claude-3-5-sonnet-20241022",
60
+ },
61
+ ],
62
+ executionStrategy: "parallel", // Both run simultaneously
63
+ continueOnFailure: true,
64
+ minSuccessful: 1,
65
+ },
66
+ ],
67
+ // When using modelGroups, flat models array is ignored
68
+ models: [{ provider: AIProviderName.OPENAI, model: "gpt-4o-mini" }], // Placeholder for backward compat
69
+ judge: {
70
+ provider: AIProviderName.OPENAI,
71
+ model: "gpt-4o",
72
+ criteria: ["quality", "cost-effectiveness"],
73
+ outputFormat: "detailed",
74
+ includeReasoning: true,
75
+ scoreScale: { min: 0, max: 100 },
76
+ },
77
+ };
78
+ // ============================================================================
79
+ // EXAMPLE 3: Fallback Chain (Sequential Models, Sequential Groups)
80
+ // ============================================================================
81
+ const fallbackChainWorkflow = {
82
+ id: "fallback-chain",
83
+ name: "Sequential Fallback Chain",
84
+ type: "chain",
85
+ modelGroups: [
86
+ {
87
+ id: "primary",
88
+ name: "Primary Model",
89
+ models: [
90
+ { provider: AIProviderName.OPENAI, model: "gpt-4o", timeout: 5000 },
91
+ ],
92
+ executionStrategy: "sequential", // Only one model
93
+ continueOnFailure: true, // Continue to fallback if fails
94
+ minSuccessful: 1,
95
+ },
96
+ {
97
+ id: "fallback-1",
98
+ name: "First Fallback",
99
+ models: [
100
+ {
101
+ provider: AIProviderName.ANTHROPIC,
102
+ model: "claude-3-5-sonnet-20241022",
103
+ timeout: 8000,
104
+ },
105
+ ],
106
+ executionStrategy: "sequential",
107
+ continueOnFailure: true,
108
+ minSuccessful: 1,
109
+ },
110
+ {
111
+ id: "fallback-2",
112
+ name: "Second Fallback",
113
+ models: [
114
+ {
115
+ provider: AIProviderName.GOOGLE_AI,
116
+ model: "gemini-2.0-flash",
117
+ timeout: 10000,
118
+ },
119
+ ],
120
+ executionStrategy: "sequential",
121
+ continueOnFailure: false, // Stop here if this fails
122
+ minSuccessful: 1,
123
+ },
124
+ ],
125
+ models: [{ provider: AIProviderName.OPENAI, model: "gpt-4o" }], // Placeholder
126
+ judge: {
127
+ provider: AIProviderName.OPENAI,
128
+ model: "gpt-4o-mini",
129
+ criteria: ["availability", "response_time"],
130
+ outputFormat: "best",
131
+ includeReasoning: true,
132
+ scoreScale: { min: 0, max: 100 },
133
+ },
134
+ };
135
+ // ============================================================================
136
+ // EXAMPLE 4: Mixed Strategy (Parallel within groups, Sequential between)
137
+ // ============================================================================
138
+ const mixedStrategyWorkflow = {
139
+ id: "mixed-strategy",
140
+ name: "Mixed Parallel and Sequential",
141
+ type: "ensemble",
142
+ modelGroups: [
143
+ {
144
+ id: "quick-validation",
145
+ name: "Quick Validation Layer",
146
+ description: "Fast models to validate prompt feasibility",
147
+ models: [
148
+ { provider: AIProviderName.OPENAI, model: "gpt-4o-mini" },
149
+ { provider: AIProviderName.GOOGLE_AI, model: "gemini-2.0-flash" },
150
+ { provider: AIProviderName.ANTHROPIC, model: "claude-3-haiku" },
151
+ ],
152
+ executionStrategy: "parallel", // All 3 run simultaneously
153
+ continueOnFailure: true,
154
+ minSuccessful: 2, // Need at least 2 successful responses
155
+ parallelism: 3, // Allow all 3 to run at once
156
+ },
157
+ {
158
+ id: "deep-analysis",
159
+ name: "Deep Analysis Layer",
160
+ description: "Sequential premium models for thorough analysis",
161
+ models: [
162
+ {
163
+ provider: AIProviderName.OPENAI,
164
+ model: "gpt-4o",
165
+ systemPrompt: "Provide deep, analytical responses with step-by-step reasoning.",
166
+ },
167
+ {
168
+ provider: AIProviderName.ANTHROPIC,
169
+ model: "claude-3-5-sonnet-20241022",
170
+ systemPrompt: "Think carefully and provide nuanced, thoughtful analysis.",
171
+ },
172
+ ],
173
+ executionStrategy: "sequential", // Run one after another
174
+ continueOnFailure: false, // Stop if this layer fails
175
+ minSuccessful: 2, // Both must succeed
176
+ timeout: 30000, // 30 second timeout for this group
177
+ },
178
+ ],
179
+ models: [{ provider: AIProviderName.OPENAI, model: "gpt-4o-mini" }], // Placeholder
180
+ judges: [
181
+ {
182
+ provider: AIProviderName.OPENAI,
183
+ model: "gpt-4o",
184
+ criteria: ["depth", "accuracy"],
185
+ outputFormat: "detailed",
186
+ includeReasoning: true,
187
+ scoreScale: { min: 0, max: 100 },
188
+ },
189
+ {
190
+ provider: AIProviderName.ANTHROPIC,
191
+ model: "claude-3-5-sonnet-20241022",
192
+ criteria: ["reasoning_quality", "clarity"],
193
+ outputFormat: "detailed",
194
+ includeReasoning: true,
195
+ scoreScale: { min: 0, max: 100 },
196
+ },
197
+ ],
198
+ };
199
+ // ============================================================================
200
+ // EXAMPLE 5: Cost-Optimized (Try cheap first, escalate if needed)
201
+ // ============================================================================
202
+ const costOptimizedWorkflow = {
203
+ id: "cost-optimized",
204
+ name: "Cost-Optimized Escalation",
205
+ type: "adaptive",
206
+ modelGroups: [
207
+ {
208
+ id: "budget-tier",
209
+ name: "Budget Models",
210
+ models: [
211
+ { provider: AIProviderName.OPENAI, model: "gpt-4o-mini", weight: 0.3 },
212
+ ],
213
+ executionStrategy: "sequential",
214
+ continueOnFailure: true, // Always try next tier
215
+ minSuccessful: 1,
216
+ },
217
+ {
218
+ id: "standard-tier",
219
+ name: "Standard Models",
220
+ models: [
221
+ {
222
+ provider: AIProviderName.GOOGLE_AI,
223
+ model: "gemini-2.0-flash",
224
+ weight: 0.5,
225
+ },
226
+ {
227
+ provider: AIProviderName.ANTHROPIC,
228
+ model: "claude-3-haiku",
229
+ weight: 0.5,
230
+ },
231
+ ],
232
+ executionStrategy: "parallel",
233
+ continueOnFailure: true,
234
+ minSuccessful: 1,
235
+ },
236
+ {
237
+ id: "premium-tier",
238
+ name: "Premium Models",
239
+ models: [
240
+ { provider: AIProviderName.OPENAI, model: "gpt-4o", weight: 1.0 },
241
+ {
242
+ provider: AIProviderName.ANTHROPIC,
243
+ model: "claude-3-5-sonnet-20241022",
244
+ weight: 1.0,
245
+ },
246
+ ],
247
+ executionStrategy: "parallel",
248
+ continueOnFailure: false,
249
+ minSuccessful: 1,
250
+ },
251
+ ],
252
+ models: [{ provider: AIProviderName.OPENAI, model: "gpt-4o-mini" }], // Placeholder
253
+ execution: {
254
+ maxCost: 0.5, // Stop if cost exceeds $0.50
255
+ costThreshold: 0.25, // Warn at $0.25
256
+ },
257
+ judge: {
258
+ provider: AIProviderName.OPENAI,
259
+ model: "gpt-4o",
260
+ criteria: ["quality", "value_for_cost"],
261
+ outputFormat: "detailed",
262
+ includeReasoning: true,
263
+ scoreScale: { min: 0, max: 100 },
264
+ },
265
+ };
266
+ // ============================================================================
267
+ // EXECUTION BEHAVIOR
268
+ // ============================================================================
269
+ /*
270
+ * Sequential Groups Execution:
271
+ * ---------------------------
272
+ * Group 1 → Wait for completion → Evaluate success → Group 2 → etc.
273
+ *
274
+ * continueOnFailure=true: Proceed to next group even if current fails
275
+ * continueOnFailure=false: Stop execution if current group fails minSuccessful check
276
+ * minSuccessful: Number of successful models required to consider group successful
277
+ *
278
+ * Within Group Execution:
279
+ * ----------------------
280
+ * executionStrategy='parallel': All models run simultaneously (respects parallelism limit)
281
+ * executionStrategy='sequential': Models run one after another
282
+ *
283
+ * Example Timeline (Fast-then-Premium):
284
+ *
285
+ * Time 0s: Start Group 1 (fast-tier)
286
+ * 0.5s: gpt-4o-mini executing (parallel)
287
+ * 0.5s: gemini-flash executing (parallel)
288
+ * 1.2s: Group 1 complete (both succeed)
289
+ * 1.2s: Check minSuccessful=1 ✓
290
+ * 1.2s: Start Group 2 (premium-tier)
291
+ * 1.7s: gpt-4o executing (parallel)
292
+ * 1.7s: claude-3.5 executing (parallel)
293
+ * 4.5s: Group 2 complete
294
+ * 4.5s: All groups complete
295
+ * 4.5s: Send all 4 responses to judge
296
+ */
297
+ // ============================================================================
298
+ // BACKWARD COMPATIBILITY
299
+ // ============================================================================
300
+ /*
301
+ * If workflow has ONLY `models` array (no modelGroups):
302
+ * - Internally converted to single ModelGroup with executionStrategy='parallel'
303
+ * - Behaves exactly like before
304
+ * - No breaking changes
305
+ *
306
+ * If workflow has `modelGroups`:
307
+ * - modelGroups takes precedence
308
+ * - models array is ignored (kept for schema validation only)
309
+ * - Layer-based execution is used
310
+ */
311
+ export { simpleParallelWorkflow, fastThenPremiumWorkflow, fallbackChainWorkflow, mixedStrategyWorkflow, costOptimizedWorkflow, };
312
+ //# sourceMappingURL=LAYER-EXAMPLES.js.map
@@ -0,0 +1,117 @@
1
+ /**
2
+ * HIERARCHICAL PROMPT SYSTEM - USAGE EXAMPLES
3
+ * ============================================
4
+ *
5
+ * Demonstrates the 3-level prompt resolution with fallback mechanism
6
+ */
7
+ declare const simpleWorkflow: {
8
+ id: string;
9
+ name: string;
10
+ type: string;
11
+ defaultSystemPrompt: string;
12
+ defaultJudgePrompt: string;
13
+ models: {
14
+ provider: string;
15
+ model: string;
16
+ }[];
17
+ judge: {
18
+ provider: string;
19
+ model: string;
20
+ criteria: string[];
21
+ outputFormat: string;
22
+ includeReasoning: boolean;
23
+ scoreScale: {
24
+ min: number;
25
+ max: number;
26
+ };
27
+ };
28
+ };
29
+ declare const mixedWorkflow: {
30
+ id: string;
31
+ name: string;
32
+ type: string;
33
+ defaultSystemPrompt: string;
34
+ defaultJudgePrompt: string;
35
+ models: ({
36
+ provider: string;
37
+ model: string;
38
+ systemPrompt?: undefined;
39
+ } | {
40
+ provider: string;
41
+ model: string;
42
+ systemPrompt: string;
43
+ })[];
44
+ judge: {
45
+ provider: string;
46
+ model: string;
47
+ criteria: string[];
48
+ outputFormat: string;
49
+ includeReasoning: boolean;
50
+ scoreScale: {
51
+ min: number;
52
+ max: number;
53
+ };
54
+ };
55
+ };
56
+ declare const advancedWorkflow: {
57
+ id: string;
58
+ name: string;
59
+ type: string;
60
+ defaultSystemPrompt: string;
61
+ defaultJudgePrompt: string;
62
+ models: {
63
+ provider: string;
64
+ model: string;
65
+ systemPrompt: string;
66
+ }[];
67
+ judge: {
68
+ provider: string;
69
+ model: string;
70
+ criteria: string[];
71
+ outputFormat: string;
72
+ customPrompt: string;
73
+ systemPrompt: string;
74
+ includeReasoning: boolean;
75
+ scoreScale: {
76
+ min: number;
77
+ max: number;
78
+ };
79
+ };
80
+ };
81
+ declare const multiJudgeWorkflow: {
82
+ id: string;
83
+ name: string;
84
+ type: string;
85
+ defaultSystemPrompt: string;
86
+ defaultJudgePrompt: string;
87
+ models: {
88
+ provider: string;
89
+ model: string;
90
+ }[];
91
+ judges: ({
92
+ provider: string;
93
+ model: string;
94
+ criteria: string[];
95
+ outputFormat: string;
96
+ customPrompt: string;
97
+ systemPrompt: string;
98
+ includeReasoning: boolean;
99
+ scoreScale: {
100
+ min: number;
101
+ max: number;
102
+ };
103
+ } | {
104
+ provider: string;
105
+ model: string;
106
+ criteria: string[];
107
+ outputFormat: string;
108
+ includeReasoning: boolean;
109
+ scoreScale: {
110
+ min: number;
111
+ max: number;
112
+ };
113
+ customPrompt?: undefined;
114
+ systemPrompt?: undefined;
115
+ })[];
116
+ };
117
+ export { simpleWorkflow, mixedWorkflow, advancedWorkflow, multiJudgeWorkflow };
@@ -0,0 +1,246 @@
1
+ /**
2
+ * HIERARCHICAL PROMPT SYSTEM - USAGE EXAMPLES
3
+ * ============================================
4
+ *
5
+ * Demonstrates the 3-level prompt resolution with fallback mechanism
6
+ */
7
+ // ============================================================================
8
+ // EXAMPLE 1: Simple - Use workflow-level defaults for all models
9
+ // ============================================================================
10
+ const simpleWorkflow = {
11
+ id: "simple-ensemble",
12
+ name: "Simple Ensemble with Workflow Defaults",
13
+ type: "ensemble",
14
+ // Workflow-level defaults (used by all models/judges)
15
+ defaultSystemPrompt: "You are a helpful assistant specialized in technical documentation.",
16
+ defaultJudgePrompt: "Evaluate responses for technical accuracy and clarity.",
17
+ models: [
18
+ { provider: "openai", model: "gpt-4o" }, // Uses workflow default
19
+ { provider: "anthropic", model: "claude-3-5-sonnet-20241022" }, // Uses workflow default
20
+ { provider: "google", model: "gemini-2.0-flash" }, // Uses workflow default
21
+ ],
22
+ judge: {
23
+ provider: "openai",
24
+ model: "gpt-4o",
25
+ criteria: ["accuracy", "clarity", "completeness"],
26
+ outputFormat: "detailed",
27
+ includeReasoning: true,
28
+ scoreScale: { min: 0, max: 100 },
29
+ // Uses workflow defaultJudgePrompt
30
+ },
31
+ };
32
+ // ============================================================================
33
+ // EXAMPLE 2: Mixed - Some models override workflow defaults
34
+ // ============================================================================
35
+ const mixedWorkflow = {
36
+ id: "mixed-ensemble",
37
+ name: "Mixed Ensemble with Overrides",
38
+ type: "ensemble",
39
+ // Workflow-level defaults
40
+ defaultSystemPrompt: "You are a helpful assistant.",
41
+ defaultJudgePrompt: "Evaluate responses objectively.",
42
+ models: [
43
+ // Model 1: Uses workflow default
44
+ {
45
+ provider: "openai",
46
+ model: "gpt-4o",
47
+ },
48
+ // Model 2: Overrides with model-specific prompt
49
+ {
50
+ provider: "anthropic",
51
+ model: "claude-3-5-sonnet-20241022",
52
+ systemPrompt: "You are Claude, an AI assistant by Anthropic. Be thoughtful and nuanced.",
53
+ },
54
+ // Model 3: Uses workflow default
55
+ {
56
+ provider: "google",
57
+ model: "gemini-2.0-flash",
58
+ },
59
+ ],
60
+ judge: {
61
+ provider: "openai",
62
+ model: "gpt-4o",
63
+ criteria: ["helpfulness", "harmlessness", "honesty"],
64
+ outputFormat: "detailed",
65
+ includeReasoning: true,
66
+ scoreScale: { min: 0, max: 100 },
67
+ // Uses workflow defaultJudgePrompt
68
+ },
69
+ };
70
+ // ============================================================================
71
+ // EXAMPLE 3: Advanced - Full customization per model and judge
72
+ // ============================================================================
73
+ const advancedWorkflow = {
74
+ id: "advanced-ensemble",
75
+ name: "Advanced Ensemble with Full Customization",
76
+ type: "ensemble",
77
+ // Workflow-level defaults (fallbacks)
78
+ defaultSystemPrompt: "You are a helpful assistant.",
79
+ defaultJudgePrompt: "Evaluate responses based on quality.",
80
+ models: [
81
+ // GPT-4: Optimized prompt for OpenAI
82
+ {
83
+ provider: "openai",
84
+ model: "gpt-4o",
85
+ systemPrompt: `You are GPT-4, a large language model by OpenAI.
86
+ - Provide clear, structured responses
87
+ - Use markdown formatting when helpful
88
+ - Be concise yet comprehensive`,
89
+ },
90
+ // Claude: Optimized prompt for Anthropic
91
+ {
92
+ provider: "anthropic",
93
+ model: "claude-3-5-sonnet-20241022",
94
+ systemPrompt: `You are Claude, created by Anthropic.
95
+ - Think step-by-step through complex problems
96
+ - Acknowledge uncertainty when appropriate
97
+ - Provide balanced, thoughtful responses`,
98
+ },
99
+ // Gemini: Optimized prompt for Google
100
+ {
101
+ provider: "google",
102
+ model: "gemini-2.0-flash",
103
+ systemPrompt: `You are Gemini, Google's advanced AI model.
104
+ - Leverage multimodal understanding
105
+ - Provide factual, grounded responses
106
+ - Use clear explanations with examples`,
107
+ },
108
+ ],
109
+ judge: {
110
+ provider: "openai",
111
+ model: "gpt-4o",
112
+ criteria: [
113
+ "Factual accuracy",
114
+ "Reasoning quality",
115
+ "Clarity of explanation",
116
+ "Practical usefulness",
117
+ ],
118
+ outputFormat: "detailed",
119
+ // Custom judge evaluation prompt
120
+ customPrompt: `You are an expert AI evaluator specializing in technical content.
121
+
122
+ Your task: Compare multiple AI responses and score them on a 0-100 scale.
123
+
124
+ Evaluation Framework:
125
+ - Factual Accuracy (30%): Correctness of information
126
+ - Reasoning Quality (30%): Logic and depth of analysis
127
+ - Clarity (20%): Easy to understand and well-structured
128
+ - Practical Usefulness (20%): Actionable and helpful
129
+
130
+ For each response:
131
+ 1. Assign a score 0-100
132
+ 2. Provide brief reasoning (max 200 chars)
133
+ 3. Rank responses from best to worst
134
+ 4. Identify the single best response
135
+
136
+ Output JSON format:
137
+ {
138
+ "scores": { "response-0": 85, "response-1": 92 },
139
+ "ranking": ["response-1", "response-0"],
140
+ "bestResponse": "response-1",
141
+ "reasoning": "Response 1 excels in depth and practical examples",
142
+ "confidenceInJudgment": 0.9
143
+ }`,
144
+ // System instructions for judge personality
145
+ systemPrompt: "You are an impartial, expert evaluator. Be objective and thorough.",
146
+ includeReasoning: true,
147
+ scoreScale: { min: 0, max: 100 },
148
+ },
149
+ };
150
+ // ============================================================================
151
+ // EXAMPLE 4: Multi-judge with different evaluation prompts
152
+ // ============================================================================
153
+ const multiJudgeWorkflow = {
154
+ id: "multi-judge-ensemble",
155
+ name: "Multi-Judge Ensemble",
156
+ type: "ensemble",
157
+ defaultSystemPrompt: "You are a helpful assistant.",
158
+ defaultJudgePrompt: "Evaluate responses for quality and accuracy.",
159
+ models: [
160
+ { provider: "openai", model: "gpt-4o" },
161
+ { provider: "anthropic", model: "claude-3-5-sonnet-20241022" },
162
+ { provider: "google", model: "gemini-2.0-flash" },
163
+ ],
164
+ judges: [
165
+ // Judge 1: Technical accuracy focus
166
+ {
167
+ provider: "openai",
168
+ model: "gpt-4o",
169
+ criteria: ["technical_accuracy", "completeness"],
170
+ outputFormat: "detailed",
171
+ customPrompt: "Evaluate responses focusing on technical accuracy and completeness. Score 0-100.",
172
+ systemPrompt: "You are a technical expert. Be rigorous in your evaluation.",
173
+ includeReasoning: true,
174
+ scoreScale: { min: 0, max: 100 },
175
+ },
176
+ // Judge 2: User experience focus
177
+ {
178
+ provider: "anthropic",
179
+ model: "claude-3-5-sonnet-20241022",
180
+ criteria: ["clarity", "helpfulness", "user_friendliness"],
181
+ outputFormat: "detailed",
182
+ customPrompt: "Evaluate responses focusing on clarity, helpfulness, and user-friendliness. Score 0-100.",
183
+ systemPrompt: "You are a UX expert. Focus on user experience quality.",
184
+ includeReasoning: true,
185
+ scoreScale: { min: 0, max: 100 },
186
+ },
187
+ // Judge 3: Overall quality (uses workflow default)
188
+ {
189
+ provider: "google",
190
+ model: "gemini-2.0-flash",
191
+ criteria: ["overall_quality"],
192
+ outputFormat: "detailed",
193
+ // Uses workflow defaultJudgePrompt
194
+ includeReasoning: true,
195
+ scoreScale: { min: 0, max: 100 },
196
+ },
197
+ ],
198
+ };
199
+ // ============================================================================
200
+ // PROMPT RESOLUTION LOGIC
201
+ // ============================================================================
202
+ /*
203
+ * For Models (ensemble execution):
204
+ * --------------------------------
205
+ * 1. Direct parameter in executeEnsemble({ systemPrompt: "..." }) [Highest priority]
206
+ * 2. ModelConfig.systemPrompt
207
+ * 3. WorkflowConfig.defaultSystemPrompt
208
+ * 4. undefined (provider uses its default)
209
+ *
210
+ * For Judges (scoring):
211
+ * ---------------------
212
+ * 1. JudgeConfig.customPrompt [Evaluation prompt body - Highest priority]
213
+ * 2. WorkflowConfig.defaultJudgePrompt
214
+ * 3. Built-in template (createJudgePrompt function)
215
+ *
216
+ * Judge System Prompt:
217
+ * -------------------
218
+ * 1. Direct parameter in scoreEnsemble({ systemPrompt: "..." }) [Highest priority]
219
+ * 2. JudgeConfig.systemPrompt
220
+ * 3. undefined (judge personality uses provider default)
221
+ */
222
+ // ============================================================================
223
+ // USAGE IN CODE
224
+ // ============================================================================
225
+ /*
226
+ // Execute with workflow defaults
227
+ await executeEnsemble({
228
+ prompt: "Explain quantum computing",
229
+ models: workflow.models,
230
+ workflowDefaults: {
231
+ systemPrompt: workflow.defaultSystemPrompt,
232
+ },
233
+ });
234
+
235
+ // Score with workflow defaults
236
+ await scoreEnsemble({
237
+ judges: workflow.judges,
238
+ responses: ensembleResponses,
239
+ originalPrompt: "Explain quantum computing",
240
+ workflowDefaults: {
241
+ judgePrompt: workflow.defaultJudgePrompt,
242
+ },
243
+ });
244
+ */
245
+ export { simpleWorkflow, mixedWorkflow, advancedWorkflow, multiJudgeWorkflow };
246
+ //# sourceMappingURL=PROMPT-EXAMPLES.js.map