@riotprompt/riotprompt 0.0.7 → 0.0.9
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/.kodrdriv-test-cache.json +6 -0
- package/README.md +2 -2
- package/dist/builder.d.ts +3 -15
- package/dist/builder.js +3 -0
- package/dist/builder.js.map +1 -1
- package/dist/context-manager.d.ts +135 -0
- package/dist/context-manager.js +220 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/conversation-logger.d.ts +283 -0
- package/dist/conversation-logger.js +454 -0
- package/dist/conversation-logger.js.map +1 -0
- package/dist/conversation.d.ts +271 -0
- package/dist/conversation.js +622 -0
- package/dist/conversation.js.map +1 -0
- package/dist/formatter.d.ts +27 -57
- package/dist/formatter.js +2 -2
- package/dist/formatter.js.map +1 -1
- package/dist/items/parameters.d.ts +1 -1
- package/dist/items/section.d.ts +2 -12
- package/dist/items/weighted.d.ts +3 -15
- package/dist/iteration-strategy.d.ts +231 -0
- package/dist/iteration-strategy.js +486 -0
- package/dist/iteration-strategy.js.map +1 -0
- package/dist/loader.d.ts +3 -11
- package/dist/loader.js +3 -0
- package/dist/loader.js.map +1 -1
- package/dist/message-builder.d.ts +156 -0
- package/dist/message-builder.js +254 -0
- package/dist/message-builder.js.map +1 -0
- package/dist/override.d.ts +3 -13
- package/dist/override.js +3 -0
- package/dist/override.js.map +1 -1
- package/dist/parser.d.ts +2 -8
- package/dist/recipes.d.ts +70 -268
- package/dist/recipes.js +189 -4
- package/dist/recipes.js.map +1 -1
- package/dist/reflection.d.ts +250 -0
- package/dist/reflection.js +416 -0
- package/dist/reflection.js.map +1 -0
- package/dist/riotprompt.cjs +3551 -220
- package/dist/riotprompt.cjs.map +1 -1
- package/dist/riotprompt.d.ts +18 -2
- package/dist/riotprompt.js +9 -1
- package/dist/riotprompt.js.map +1 -1
- package/dist/token-budget.d.ts +177 -0
- package/dist/token-budget.js +404 -0
- package/dist/token-budget.js.map +1 -0
- package/dist/tools.d.ts +239 -0
- package/dist/tools.js +324 -0
- package/dist/tools.js.map +1 -0
- package/package.json +35 -36
- package/.cursor/rules/focus-on-prompt.mdc +0 -5
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { wrapLogger, DEFAULT_LOGGER } from './logger.js';
|
|
2
|
+
import { MetricsCollector, ReflectionReportGenerator } from './reflection.js';
|
|
3
|
+
|
|
4
|
+
function _define_property(obj, key, value) {
|
|
5
|
+
if (key in obj) {
|
|
6
|
+
Object.defineProperty(obj, key, {
|
|
7
|
+
value: value,
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
obj[key] = value;
|
|
14
|
+
}
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
// ===== STRATEGY EXECUTOR =====
|
|
18
|
+
/**
|
|
19
|
+
* StrategyExecutor executes iteration strategies.
|
|
20
|
+
*
|
|
21
|
+
* Features:
|
|
22
|
+
* - Execute multi-phase strategies
|
|
23
|
+
* - Manage tool calls and results
|
|
24
|
+
* - Track state and metrics
|
|
25
|
+
* - Handle timeouts and errors
|
|
26
|
+
* - Provide lifecycle hooks
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const executor = new StrategyExecutor(llmClient);
|
|
31
|
+
*
|
|
32
|
+
* const result = await executor.execute(
|
|
33
|
+
* conversation,
|
|
34
|
+
* toolRegistry,
|
|
35
|
+
* strategy
|
|
36
|
+
* );
|
|
37
|
+
*
|
|
38
|
+
* console.log('Completed in', result.totalIterations, 'iterations');
|
|
39
|
+
* console.log('Used', result.toolCallsExecuted, 'tools');
|
|
40
|
+
* ```
|
|
41
|
+
*/ class StrategyExecutor {
|
|
42
|
+
/**
|
|
43
|
+
* Enable reflection generation
|
|
44
|
+
*/ withReflection(config) {
|
|
45
|
+
this.reflectionConfig = config;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Execute a strategy
|
|
50
|
+
*/ async execute(conversation, tools, strategy) {
|
|
51
|
+
var _this_reflectionConfig;
|
|
52
|
+
const startTime = Date.now();
|
|
53
|
+
// Initialize metrics collector if reflection enabled
|
|
54
|
+
if ((_this_reflectionConfig = this.reflectionConfig) === null || _this_reflectionConfig === void 0 ? void 0 : _this_reflectionConfig.enabled) {
|
|
55
|
+
this.metricsCollector = new MetricsCollector(this.logger);
|
|
56
|
+
}
|
|
57
|
+
const state = {
|
|
58
|
+
phase: 0,
|
|
59
|
+
iteration: 0,
|
|
60
|
+
toolCallsExecuted: 0,
|
|
61
|
+
startTime,
|
|
62
|
+
insights: [],
|
|
63
|
+
findings: [],
|
|
64
|
+
errors: []
|
|
65
|
+
};
|
|
66
|
+
this.logger.info('Starting strategy execution', {
|
|
67
|
+
strategy: strategy.name
|
|
68
|
+
});
|
|
69
|
+
const context = {
|
|
70
|
+
conversation,
|
|
71
|
+
tools,
|
|
72
|
+
llm: this.llm,
|
|
73
|
+
state
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
var _strategy_onStart, _this_reflectionConfig1, _strategy_onComplete;
|
|
77
|
+
// Initialize
|
|
78
|
+
await ((_strategy_onStart = strategy.onStart) === null || _strategy_onStart === void 0 ? void 0 : _strategy_onStart.call(strategy, context));
|
|
79
|
+
// Execute phases or single loop
|
|
80
|
+
const phases = strategy.phases || [
|
|
81
|
+
{
|
|
82
|
+
name: 'default',
|
|
83
|
+
maxIterations: strategy.maxIterations,
|
|
84
|
+
toolUsage: 'encouraged'
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
const phaseResults = [];
|
|
88
|
+
for (const phase of phases){
|
|
89
|
+
var _phase_skipIf, _strategy_onPhaseComplete;
|
|
90
|
+
// Check if should skip phase
|
|
91
|
+
if ((_phase_skipIf = phase.skipIf) === null || _phase_skipIf === void 0 ? void 0 : _phase_skipIf.call(phase, state)) {
|
|
92
|
+
this.logger.debug('Skipping phase', {
|
|
93
|
+
phase: phase.name
|
|
94
|
+
});
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
state.phase = phase.name;
|
|
98
|
+
state.iteration = 0;
|
|
99
|
+
this.logger.debug('Starting phase', {
|
|
100
|
+
phase: phase.name
|
|
101
|
+
});
|
|
102
|
+
const phaseResult = await this.executePhase(conversation, tools, phase, state, strategy);
|
|
103
|
+
phaseResults.push(phaseResult);
|
|
104
|
+
// Track iteration for metrics
|
|
105
|
+
if (this.metricsCollector) {
|
|
106
|
+
this.metricsCollector.incrementIteration();
|
|
107
|
+
}
|
|
108
|
+
await ((_strategy_onPhaseComplete = strategy.onPhaseComplete) === null || _strategy_onPhaseComplete === void 0 ? void 0 : _strategy_onPhaseComplete.call(strategy, phaseResult, state));
|
|
109
|
+
// Check if should continue
|
|
110
|
+
if (strategy.shouldContinue && !strategy.shouldContinue(state)) {
|
|
111
|
+
this.logger.debug('Strategy decided to stop');
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const duration = Date.now() - startTime;
|
|
116
|
+
const result = {
|
|
117
|
+
finalMessage: conversation.getLastMessage(),
|
|
118
|
+
phases: phaseResults,
|
|
119
|
+
totalIterations: state.iteration,
|
|
120
|
+
toolCallsExecuted: state.toolCallsExecuted,
|
|
121
|
+
duration,
|
|
122
|
+
success: true,
|
|
123
|
+
conversation
|
|
124
|
+
};
|
|
125
|
+
// Generate reflection if enabled
|
|
126
|
+
if (this.metricsCollector && ((_this_reflectionConfig1 = this.reflectionConfig) === null || _this_reflectionConfig1 === void 0 ? void 0 : _this_reflectionConfig1.enabled)) {
|
|
127
|
+
const metrics = this.metricsCollector.getMetrics(conversation.getMessages(), conversation.getMetadata().model);
|
|
128
|
+
const generator = new ReflectionReportGenerator(this.logger);
|
|
129
|
+
result.reflection = generator.generate(metrics, result);
|
|
130
|
+
// Save reflection if output path specified
|
|
131
|
+
if (this.reflectionConfig.outputPath && result.reflection) {
|
|
132
|
+
await this.saveReflection(result.reflection, this.reflectionConfig);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
await ((_strategy_onComplete = strategy.onComplete) === null || _strategy_onComplete === void 0 ? void 0 : _strategy_onComplete.call(strategy, result));
|
|
136
|
+
this.logger.info('Strategy execution complete', {
|
|
137
|
+
iterations: result.totalIterations,
|
|
138
|
+
toolCalls: result.toolCallsExecuted,
|
|
139
|
+
duration
|
|
140
|
+
});
|
|
141
|
+
return result;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
this.logger.error('Strategy execution failed', {
|
|
144
|
+
error
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
finalMessage: conversation.getLastMessage(),
|
|
148
|
+
phases: [],
|
|
149
|
+
totalIterations: state.iteration,
|
|
150
|
+
toolCallsExecuted: state.toolCallsExecuted,
|
|
151
|
+
duration: Date.now() - startTime,
|
|
152
|
+
success: false,
|
|
153
|
+
conversation
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Save reflection report
|
|
159
|
+
*/ async saveReflection(reflection, config) {
|
|
160
|
+
if (!config.outputPath) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const fs = await import('fs/promises');
|
|
165
|
+
const path = await import('path');
|
|
166
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
167
|
+
const filename = `reflection-${timestamp}.${config.format === 'json' ? 'json' : 'md'}`;
|
|
168
|
+
const fullPath = path.join(config.outputPath, filename);
|
|
169
|
+
// Ensure directory exists
|
|
170
|
+
await fs.mkdir(config.outputPath, {
|
|
171
|
+
recursive: true
|
|
172
|
+
});
|
|
173
|
+
// Save based on format
|
|
174
|
+
if (config.format === 'json') {
|
|
175
|
+
await fs.writeFile(fullPath, JSON.stringify(reflection, null, 2), 'utf-8');
|
|
176
|
+
} else {
|
|
177
|
+
const generator = new ReflectionReportGenerator(this.logger);
|
|
178
|
+
const markdown = generator.formatMarkdown(reflection);
|
|
179
|
+
await fs.writeFile(fullPath, markdown, 'utf-8');
|
|
180
|
+
}
|
|
181
|
+
this.logger.info('Reflection saved', {
|
|
182
|
+
path: fullPath
|
|
183
|
+
});
|
|
184
|
+
} catch (error) {
|
|
185
|
+
this.logger.error('Failed to save reflection', {
|
|
186
|
+
error
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Execute a single phase
|
|
192
|
+
*/ async executePhase(conversation, tools, phase, state, strategy) {
|
|
193
|
+
const phaseStartTools = state.toolCallsExecuted;
|
|
194
|
+
// Add phase instructions if provided
|
|
195
|
+
if (phase.instructions) {
|
|
196
|
+
conversation.asUser(phase.instructions);
|
|
197
|
+
}
|
|
198
|
+
// Iteration loop for this phase
|
|
199
|
+
for(let i = 0; i < phase.maxIterations; i++){
|
|
200
|
+
var _strategy_onIteration;
|
|
201
|
+
state.iteration++;
|
|
202
|
+
this.logger.debug('Iteration', {
|
|
203
|
+
phase: phase.name,
|
|
204
|
+
iteration: i + 1
|
|
205
|
+
});
|
|
206
|
+
// Check iteration hook
|
|
207
|
+
const action = await ((_strategy_onIteration = strategy.onIteration) === null || _strategy_onIteration === void 0 ? void 0 : _strategy_onIteration.call(strategy, i, state));
|
|
208
|
+
if (action === 'stop') {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
if (action === 'next-phase') {
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
// Get LLM response
|
|
215
|
+
const toolsToProvide = phase.toolUsage !== 'forbidden' ? tools.toOpenAIFormat() : undefined;
|
|
216
|
+
const response = await this.llm.complete(conversation.toMessages(), toolsToProvide);
|
|
217
|
+
// Handle tool calls
|
|
218
|
+
if (response.tool_calls && response.tool_calls.length > 0) {
|
|
219
|
+
if (phase.toolUsage === 'forbidden') {
|
|
220
|
+
this.logger.warn('Tool calls requested but forbidden in this phase');
|
|
221
|
+
conversation.asAssistant(response.content);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
conversation.asAssistant(response.content, response.tool_calls);
|
|
225
|
+
// Execute tools
|
|
226
|
+
for (const toolCall of response.tool_calls){
|
|
227
|
+
var _strategy_onToolCall;
|
|
228
|
+
// Check if tool is allowed in this phase
|
|
229
|
+
if (phase.allowedTools && !phase.allowedTools.includes(toolCall.function.name)) {
|
|
230
|
+
this.logger.debug('Tool not allowed in phase', {
|
|
231
|
+
tool: toolCall.function.name
|
|
232
|
+
});
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
// Check tool call hook
|
|
236
|
+
const toolAction = await ((_strategy_onToolCall = strategy.onToolCall) === null || _strategy_onToolCall === void 0 ? void 0 : _strategy_onToolCall.call(strategy, toolCall, state));
|
|
237
|
+
if (toolAction === 'skip') {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
// Execute tool
|
|
241
|
+
const toolStart = Date.now();
|
|
242
|
+
try {
|
|
243
|
+
var _strategy_onToolResult;
|
|
244
|
+
const result = await tools.execute(toolCall.function.name, JSON.parse(toolCall.function.arguments));
|
|
245
|
+
const toolDuration = Date.now() - toolStart;
|
|
246
|
+
const toolResult = {
|
|
247
|
+
callId: toolCall.id,
|
|
248
|
+
toolName: toolCall.function.name,
|
|
249
|
+
result,
|
|
250
|
+
duration: toolDuration
|
|
251
|
+
};
|
|
252
|
+
conversation.asTool(toolCall.id, result, {
|
|
253
|
+
duration: toolDuration,
|
|
254
|
+
success: true
|
|
255
|
+
});
|
|
256
|
+
state.toolCallsExecuted++;
|
|
257
|
+
// Record metrics
|
|
258
|
+
if (this.metricsCollector) {
|
|
259
|
+
this.metricsCollector.recordToolCall(toolCall.function.name, state.iteration, toolDuration, true);
|
|
260
|
+
}
|
|
261
|
+
await ((_strategy_onToolResult = strategy.onToolResult) === null || _strategy_onToolResult === void 0 ? void 0 : _strategy_onToolResult.call(strategy, toolResult, state));
|
|
262
|
+
} catch (error) {
|
|
263
|
+
var _strategy_onToolResult1;
|
|
264
|
+
this.logger.error('Tool execution failed', {
|
|
265
|
+
tool: toolCall.function.name,
|
|
266
|
+
error
|
|
267
|
+
});
|
|
268
|
+
const toolDuration = Date.now() - toolStart;
|
|
269
|
+
const toolResult = {
|
|
270
|
+
callId: toolCall.id,
|
|
271
|
+
toolName: toolCall.function.name,
|
|
272
|
+
result: null,
|
|
273
|
+
error: error,
|
|
274
|
+
duration: toolDuration
|
|
275
|
+
};
|
|
276
|
+
conversation.asTool(toolCall.id, {
|
|
277
|
+
error: error.message
|
|
278
|
+
}, {
|
|
279
|
+
success: false,
|
|
280
|
+
errorName: error.name
|
|
281
|
+
});
|
|
282
|
+
state.errors.push(error);
|
|
283
|
+
// Record metrics
|
|
284
|
+
if (this.metricsCollector) {
|
|
285
|
+
this.metricsCollector.recordToolCall(toolCall.function.name, state.iteration, toolDuration, false, error.message);
|
|
286
|
+
}
|
|
287
|
+
await ((_strategy_onToolResult1 = strategy.onToolResult) === null || _strategy_onToolResult1 === void 0 ? void 0 : _strategy_onToolResult1.call(strategy, toolResult, state));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
// No tool calls - add response and potentially end phase
|
|
292
|
+
conversation.asAssistant(response.content);
|
|
293
|
+
// Check if this phase requires tool calls
|
|
294
|
+
if (phase.toolUsage === 'required' && state.toolCallsExecuted === phaseStartTools) {
|
|
295
|
+
this.logger.warn('No tools used but required in phase');
|
|
296
|
+
// Continue to try again
|
|
297
|
+
} else if (phase.earlyExit !== false) {
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// Check phase completion conditions
|
|
302
|
+
const toolCallsInPhase = state.toolCallsExecuted - phaseStartTools;
|
|
303
|
+
if (phase.minToolCalls && toolCallsInPhase < phase.minToolCalls) {
|
|
304
|
+
continue; // Need more tool calls
|
|
305
|
+
}
|
|
306
|
+
if (phase.maxToolCalls && toolCallsInPhase >= phase.maxToolCalls) {
|
|
307
|
+
break; // Hit max tool calls for phase
|
|
308
|
+
}
|
|
309
|
+
if (phase.continueIf && !phase.continueIf(state)) {
|
|
310
|
+
break; // Condition not met
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
name: phase.name,
|
|
315
|
+
iterations: state.iteration,
|
|
316
|
+
toolCalls: state.toolCallsExecuted - phaseStartTools,
|
|
317
|
+
success: true,
|
|
318
|
+
insights: state.insights
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
constructor(llm, logger){
|
|
322
|
+
_define_property(this, "llm", void 0);
|
|
323
|
+
_define_property(this, "logger", void 0);
|
|
324
|
+
_define_property(this, "metricsCollector", void 0);
|
|
325
|
+
_define_property(this, "reflectionConfig", void 0);
|
|
326
|
+
this.llm = llm;
|
|
327
|
+
this.logger = wrapLogger(logger || DEFAULT_LOGGER, 'StrategyExecutor');
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
// ===== PRE-BUILT STRATEGIES =====
|
|
331
|
+
/**
|
|
332
|
+
* Factory for creating iteration strategies
|
|
333
|
+
*/ class IterationStrategyFactory {
|
|
334
|
+
/**
|
|
335
|
+
* Investigate then respond strategy
|
|
336
|
+
* Phase 1: Use tools to gather information
|
|
337
|
+
* Phase 2: Synthesize into final answer
|
|
338
|
+
*/ static investigateThenRespond(config = {}) {
|
|
339
|
+
const { maxInvestigationSteps = 5, requireMinimumTools = 1, finalSynthesis = true } = config;
|
|
340
|
+
return {
|
|
341
|
+
name: 'investigate-then-respond',
|
|
342
|
+
description: 'Investigate using tools, then synthesize findings',
|
|
343
|
+
maxIterations: maxInvestigationSteps + (finalSynthesis ? 1 : 0),
|
|
344
|
+
phases: [
|
|
345
|
+
{
|
|
346
|
+
name: 'investigate',
|
|
347
|
+
maxIterations: maxInvestigationSteps,
|
|
348
|
+
toolUsage: 'encouraged',
|
|
349
|
+
minToolCalls: requireMinimumTools,
|
|
350
|
+
earlyExit: false
|
|
351
|
+
},
|
|
352
|
+
...finalSynthesis ? [
|
|
353
|
+
{
|
|
354
|
+
name: 'respond',
|
|
355
|
+
maxIterations: 1,
|
|
356
|
+
toolUsage: 'forbidden',
|
|
357
|
+
instructions: 'Based on your investigation, provide a comprehensive answer.',
|
|
358
|
+
requireFinalAnswer: true
|
|
359
|
+
}
|
|
360
|
+
] : []
|
|
361
|
+
]
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Multi-pass refinement strategy
|
|
366
|
+
* Generate, critique, refine repeatedly
|
|
367
|
+
*/ static multiPassRefinement(config = {}) {
|
|
368
|
+
const { passes = 3, critiqueBetweenPasses = true } = config;
|
|
369
|
+
const phases = [];
|
|
370
|
+
for(let i = 0; i < passes; i++){
|
|
371
|
+
phases.push({
|
|
372
|
+
name: `pass-${i + 1}`,
|
|
373
|
+
maxIterations: 1,
|
|
374
|
+
toolUsage: 'optional',
|
|
375
|
+
instructions: i === 0 ? 'Generate your best response' : 'Refine your previous response based on the critique'
|
|
376
|
+
});
|
|
377
|
+
if (critiqueBetweenPasses && i < passes - 1) {
|
|
378
|
+
phases.push({
|
|
379
|
+
name: `critique-${i + 1}`,
|
|
380
|
+
maxIterations: 1,
|
|
381
|
+
toolUsage: 'forbidden',
|
|
382
|
+
instructions: 'Critique the previous response. What can be improved?'
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
name: 'multi-pass-refinement',
|
|
388
|
+
description: 'Iteratively refine response through multiple passes',
|
|
389
|
+
maxIterations: passes * 2,
|
|
390
|
+
phases
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Breadth-first investigation
|
|
395
|
+
* Explore broadly before going deep
|
|
396
|
+
*/ static breadthFirst(config = {}) {
|
|
397
|
+
const { levelsDeep = 3, toolsPerLevel = 4 } = config;
|
|
398
|
+
const phases = [];
|
|
399
|
+
for(let level = 0; level < levelsDeep; level++){
|
|
400
|
+
phases.push({
|
|
401
|
+
name: `level-${level + 1}`,
|
|
402
|
+
maxIterations: toolsPerLevel,
|
|
403
|
+
toolUsage: 'encouraged',
|
|
404
|
+
minToolCalls: 1,
|
|
405
|
+
maxToolCalls: toolsPerLevel,
|
|
406
|
+
instructions: level === 0 ? 'Get a broad overview' : `Dive deeper into areas discovered in level ${level}`
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return {
|
|
410
|
+
name: 'breadth-first',
|
|
411
|
+
description: 'Explore broadly at each level before going deeper',
|
|
412
|
+
maxIterations: levelsDeep * toolsPerLevel,
|
|
413
|
+
phases
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Depth-first investigation
|
|
418
|
+
* Deep dive immediately
|
|
419
|
+
*/ static depthFirst(config = {}) {
|
|
420
|
+
const { maxDepth = 5, backtrackOnFailure = true } = config;
|
|
421
|
+
return {
|
|
422
|
+
name: 'depth-first',
|
|
423
|
+
description: 'Deep dive investigation path',
|
|
424
|
+
maxIterations: maxDepth,
|
|
425
|
+
phases: [
|
|
426
|
+
{
|
|
427
|
+
name: 'deep-dive',
|
|
428
|
+
maxIterations: maxDepth,
|
|
429
|
+
toolUsage: 'encouraged',
|
|
430
|
+
adaptiveDepth: true
|
|
431
|
+
}
|
|
432
|
+
],
|
|
433
|
+
shouldContinue: (state)=>{
|
|
434
|
+
// Continue if making progress
|
|
435
|
+
if (backtrackOnFailure && state.errors.length > 2) {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
return true;
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Adaptive strategy
|
|
444
|
+
* Changes behavior based on progress
|
|
445
|
+
*/ static adaptive(_config = {}) {
|
|
446
|
+
return {
|
|
447
|
+
name: 'adaptive',
|
|
448
|
+
description: 'Adapts strategy based on progress',
|
|
449
|
+
maxIterations: 20,
|
|
450
|
+
onIteration: async (iteration, state)=>{
|
|
451
|
+
// Change behavior based on iteration count
|
|
452
|
+
if (iteration < 5) {
|
|
453
|
+
// Early: broad exploration
|
|
454
|
+
return 'continue';
|
|
455
|
+
} else if (iteration < 15) {
|
|
456
|
+
// Mid: focused investigation
|
|
457
|
+
return 'continue';
|
|
458
|
+
} else {
|
|
459
|
+
// Late: wrap up
|
|
460
|
+
return state.toolCallsExecuted > 0 ? 'continue' : 'stop';
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Simple iteration (basic tool-use loop)
|
|
467
|
+
*/ static simple(config = {}) {
|
|
468
|
+
const { maxIterations = 10, allowTools = true } = config;
|
|
469
|
+
return {
|
|
470
|
+
name: 'simple',
|
|
471
|
+
description: 'Simple iteration loop',
|
|
472
|
+
maxIterations,
|
|
473
|
+
phases: [
|
|
474
|
+
{
|
|
475
|
+
name: 'main',
|
|
476
|
+
maxIterations,
|
|
477
|
+
toolUsage: allowTools ? 'encouraged' : 'forbidden',
|
|
478
|
+
earlyExit: true
|
|
479
|
+
}
|
|
480
|
+
]
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export { IterationStrategyFactory, StrategyExecutor, IterationStrategyFactory as default };
|
|
486
|
+
//# sourceMappingURL=iteration-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iteration-strategy.js","sources":["../src/iteration-strategy.ts"],"sourcesContent":["import { ConversationBuilder, type ConversationMessage, type ToolCall } from \"./conversation\";\nimport { ToolRegistry, type Tool } from \"./tools\";\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\nimport { MetricsCollector, ReflectionReportGenerator, type ReflectionReport, type ReflectionConfig } from \"./reflection\";\n\n// ===== TYPE DEFINITIONS =====\n\n/**\n * Tool usage policy for a phase\n */\nexport type ToolUsagePolicy = 'required' | 'encouraged' | 'optional' | 'forbidden';\n\n/**\n * LLM client interface (generic, provider-agnostic)\n */\nexport interface LLMClient {\n complete(messages: ConversationMessage[], tools?: any[]): Promise<{\n content: string | null;\n tool_calls?: ToolCall[];\n }>;\n}\n\n/**\n * Context provided to strategy execution\n */\nexport interface StrategyContext {\n conversation: ConversationBuilder;\n tools: ToolRegistry;\n llm: LLMClient;\n state: StrategyState;\n}\n\n/**\n * Current state of strategy execution\n */\nexport interface StrategyState {\n phase: string | number;\n iteration: number;\n toolCallsExecuted: number;\n startTime: number;\n insights: Insight[];\n findings: any[];\n errors: Error[];\n [key: string]: any;\n}\n\n/**\n * Insight discovered during execution\n */\nexport interface Insight {\n source: string;\n content: string;\n confidence: number;\n relatedTo?: string[];\n}\n\n/**\n * Result of tool execution\n */\nexport interface ToolResult {\n callId: string;\n toolName: string;\n result: any;\n error?: Error;\n duration: number;\n}\n\n/**\n * Action to take after iteration\n */\nexport type IterationAction = 'continue' | 'stop' | 'next-phase';\n\n/**\n * Action to take for tool call\n */\nexport type ToolCallAction = 'execute' | 'skip' | 'defer';\n\n/**\n * Result of a phase\n */\nexport interface PhaseResult {\n name: string;\n iterations: number;\n toolCalls: number;\n success: boolean;\n insights?: Insight[];\n}\n\n/**\n * Final strategy result\n */\nexport interface StrategyResult {\n finalMessage: ConversationMessage | undefined;\n phases: PhaseResult[];\n totalIterations: number;\n toolCallsExecuted: number;\n duration: number;\n success: boolean;\n conversation: ConversationBuilder;\n reflection?: ReflectionReport;\n}\n\n/**\n * Configuration for a strategy phase\n */\nexport interface StrategyPhase {\n name: string;\n maxIterations: number;\n toolUsage: ToolUsagePolicy;\n allowedTools?: string[];\n minToolCalls?: number;\n maxToolCalls?: number;\n instructions?: string;\n earlyExit?: boolean;\n requireFinalAnswer?: boolean;\n adaptiveDepth?: boolean;\n continueIf?: (state: StrategyState) => boolean;\n skipIf?: (state: StrategyState) => boolean;\n}\n\n/**\n * Iteration strategy interface\n */\nexport interface IterationStrategy {\n name: string;\n description: string;\n maxIterations: number;\n maxToolCalls?: number;\n timeoutMs?: number;\n phases?: StrategyPhase[];\n\n // Lifecycle hooks\n onStart?: (context: StrategyContext) => Promise<void>;\n onIteration?: (iteration: number, state: StrategyState) => Promise<IterationAction>;\n onToolCall?: (toolCall: ToolCall, state: StrategyState) => Promise<ToolCallAction>;\n onToolResult?: (result: ToolResult, state: StrategyState) => Promise<void>;\n onPhaseComplete?: (phase: PhaseResult, state: StrategyState) => Promise<void>;\n onComplete?: (result: StrategyResult) => Promise<void>;\n\n // Decision logic\n shouldContinue?: (state: StrategyState) => boolean;\n shouldCallTool?: (tool: Tool, state: StrategyState) => boolean;\n selectTools?: (available: Tool[], state: StrategyState) => Tool[];\n}\n\n// ===== STRATEGY EXECUTOR =====\n\n/**\n * StrategyExecutor executes iteration strategies.\n *\n * Features:\n * - Execute multi-phase strategies\n * - Manage tool calls and results\n * - Track state and metrics\n * - Handle timeouts and errors\n * - Provide lifecycle hooks\n *\n * @example\n * ```typescript\n * const executor = new StrategyExecutor(llmClient);\n *\n * const result = await executor.execute(\n * conversation,\n * toolRegistry,\n * strategy\n * );\n *\n * console.log('Completed in', result.totalIterations, 'iterations');\n * console.log('Used', result.toolCallsExecuted, 'tools');\n * ```\n */\nexport class StrategyExecutor {\n private llm: LLMClient;\n private logger: any;\n private metricsCollector?: MetricsCollector;\n private reflectionConfig?: ReflectionConfig;\n\n constructor(llm: LLMClient, logger?: any) {\n this.llm = llm;\n this.logger = wrapLogger(logger || DEFAULT_LOGGER, 'StrategyExecutor');\n }\n\n /**\n * Enable reflection generation\n */\n withReflection(config: ReflectionConfig): this {\n this.reflectionConfig = config;\n return this;\n }\n\n /**\n * Execute a strategy\n */\n async execute(\n conversation: ConversationBuilder,\n tools: ToolRegistry,\n strategy: IterationStrategy\n ): Promise<StrategyResult> {\n const startTime = Date.now();\n\n // Initialize metrics collector if reflection enabled\n if (this.reflectionConfig?.enabled) {\n this.metricsCollector = new MetricsCollector(this.logger);\n }\n\n const state: StrategyState = {\n phase: 0,\n iteration: 0,\n toolCallsExecuted: 0,\n startTime,\n insights: [],\n findings: [],\n errors: [],\n };\n\n this.logger.info('Starting strategy execution', { strategy: strategy.name });\n\n const context: StrategyContext = { conversation, tools, llm: this.llm, state };\n\n try {\n // Initialize\n await strategy.onStart?.(context);\n\n // Execute phases or single loop\n const phases = strategy.phases || [\n {\n name: 'default',\n maxIterations: strategy.maxIterations,\n toolUsage: 'encouraged' as ToolUsagePolicy,\n }\n ];\n\n const phaseResults: PhaseResult[] = [];\n\n for (const phase of phases) {\n // Check if should skip phase\n if (phase.skipIf?.(state)) {\n this.logger.debug('Skipping phase', { phase: phase.name });\n continue;\n }\n\n state.phase = phase.name;\n state.iteration = 0;\n\n this.logger.debug('Starting phase', { phase: phase.name });\n\n const phaseResult = await this.executePhase(\n conversation,\n tools,\n phase,\n state,\n strategy\n );\n\n phaseResults.push(phaseResult);\n\n // Track iteration for metrics\n if (this.metricsCollector) {\n this.metricsCollector.incrementIteration();\n }\n\n await strategy.onPhaseComplete?.(phaseResult, state);\n\n // Check if should continue\n if (strategy.shouldContinue && !strategy.shouldContinue(state)) {\n this.logger.debug('Strategy decided to stop');\n break;\n }\n }\n\n const duration = Date.now() - startTime;\n\n const result: StrategyResult = {\n finalMessage: conversation.getLastMessage(),\n phases: phaseResults,\n totalIterations: state.iteration,\n toolCallsExecuted: state.toolCallsExecuted,\n duration,\n success: true,\n conversation,\n };\n\n // Generate reflection if enabled\n if (this.metricsCollector && this.reflectionConfig?.enabled) {\n const metrics = this.metricsCollector.getMetrics(\n conversation.getMessages(),\n conversation.getMetadata().model\n );\n\n const generator = new ReflectionReportGenerator(this.logger);\n result.reflection = generator.generate(metrics, result);\n\n // Save reflection if output path specified\n if (this.reflectionConfig.outputPath && result.reflection) {\n await this.saveReflection(result.reflection, this.reflectionConfig);\n }\n }\n\n await strategy.onComplete?.(result);\n\n this.logger.info('Strategy execution complete', {\n iterations: result.totalIterations,\n toolCalls: result.toolCallsExecuted,\n duration\n });\n\n return result;\n\n } catch (error) {\n this.logger.error('Strategy execution failed', { error });\n\n return {\n finalMessage: conversation.getLastMessage(),\n phases: [],\n totalIterations: state.iteration,\n toolCallsExecuted: state.toolCallsExecuted,\n duration: Date.now() - startTime,\n success: false,\n conversation,\n };\n }\n }\n\n /**\n * Save reflection report\n */\n private async saveReflection(\n reflection: ReflectionReport,\n config: ReflectionConfig\n ): Promise<void> {\n if (!config.outputPath) {\n return;\n }\n\n try {\n const fs = await import('fs/promises');\n const path = await import('path');\n\n const timestamp = new Date().toISOString().replace(/[:.]/g, '-');\n const filename = `reflection-${timestamp}.${config.format === 'json' ? 'json' : 'md'}`;\n const fullPath = path.join(config.outputPath, filename);\n\n // Ensure directory exists\n await fs.mkdir(config.outputPath, { recursive: true });\n\n // Save based on format\n if (config.format === 'json') {\n await fs.writeFile(fullPath, JSON.stringify(reflection, null, 2), 'utf-8');\n } else {\n const generator = new ReflectionReportGenerator(this.logger);\n const markdown = generator.formatMarkdown(reflection);\n await fs.writeFile(fullPath, markdown, 'utf-8');\n }\n\n this.logger.info('Reflection saved', { path: fullPath });\n } catch (error) {\n this.logger.error('Failed to save reflection', { error });\n }\n }\n\n /**\n * Execute a single phase\n */\n private async executePhase(\n conversation: ConversationBuilder,\n tools: ToolRegistry,\n phase: StrategyPhase,\n state: StrategyState,\n strategy: IterationStrategy\n ): Promise<PhaseResult> {\n const phaseStartTools = state.toolCallsExecuted;\n\n // Add phase instructions if provided\n if (phase.instructions) {\n conversation.asUser(phase.instructions);\n }\n\n // Iteration loop for this phase\n for (let i = 0; i < phase.maxIterations; i++) {\n state.iteration++;\n\n this.logger.debug('Iteration', { phase: phase.name, iteration: i + 1 });\n\n // Check iteration hook\n const action = await strategy.onIteration?.(i, state);\n if (action === 'stop') {\n break;\n }\n if (action === 'next-phase') {\n break;\n }\n\n // Get LLM response\n const toolsToProvide = phase.toolUsage !== 'forbidden' ? tools.toOpenAIFormat() : undefined;\n const response = await this.llm.complete(\n conversation.toMessages(),\n toolsToProvide\n );\n\n // Handle tool calls\n if (response.tool_calls && response.tool_calls.length > 0) {\n if (phase.toolUsage === 'forbidden') {\n this.logger.warn('Tool calls requested but forbidden in this phase');\n conversation.asAssistant(response.content);\n continue;\n }\n\n conversation.asAssistant(response.content, response.tool_calls);\n\n // Execute tools\n for (const toolCall of response.tool_calls) {\n // Check if tool is allowed in this phase\n if (phase.allowedTools && !phase.allowedTools.includes(toolCall.function.name)) {\n this.logger.debug('Tool not allowed in phase', { tool: toolCall.function.name });\n continue;\n }\n\n // Check tool call hook\n const toolAction = await strategy.onToolCall?.(toolCall, state);\n if (toolAction === 'skip') {\n continue;\n }\n\n // Execute tool\n const toolStart = Date.now();\n try {\n const result = await tools.execute(\n toolCall.function.name,\n JSON.parse(toolCall.function.arguments)\n );\n\n const toolDuration = Date.now() - toolStart;\n\n const toolResult: ToolResult = {\n callId: toolCall.id,\n toolName: toolCall.function.name,\n result,\n duration: toolDuration,\n };\n\n conversation.asTool(toolCall.id, result, {\n duration: toolDuration,\n success: true\n });\n\n state.toolCallsExecuted++;\n\n // Record metrics\n if (this.metricsCollector) {\n this.metricsCollector.recordToolCall(\n toolCall.function.name,\n state.iteration,\n toolDuration,\n true\n );\n }\n\n await strategy.onToolResult?.(toolResult, state);\n\n } catch (error) {\n this.logger.error('Tool execution failed', { tool: toolCall.function.name, error });\n\n const toolDuration = Date.now() - toolStart;\n\n const toolResult: ToolResult = {\n callId: toolCall.id,\n toolName: toolCall.function.name,\n result: null,\n error: error as Error,\n duration: toolDuration,\n };\n\n conversation.asTool(toolCall.id, {\n error: (error as Error).message\n }, {\n success: false,\n errorName: (error as Error).name\n });\n\n state.errors.push(error as Error);\n\n // Record metrics\n if (this.metricsCollector) {\n this.metricsCollector.recordToolCall(\n toolCall.function.name,\n state.iteration,\n toolDuration,\n false,\n (error as Error).message\n );\n }\n\n await strategy.onToolResult?.(toolResult, state);\n }\n }\n\n } else {\n // No tool calls - add response and potentially end phase\n conversation.asAssistant(response.content);\n\n // Check if this phase requires tool calls\n if (phase.toolUsage === 'required' && state.toolCallsExecuted === phaseStartTools) {\n this.logger.warn('No tools used but required in phase');\n // Continue to try again\n } else if (phase.earlyExit !== false) {\n // Exit phase early if we got a response without tools\n break;\n }\n }\n\n // Check phase completion conditions\n const toolCallsInPhase = state.toolCallsExecuted - phaseStartTools;\n\n if (phase.minToolCalls && toolCallsInPhase < phase.minToolCalls) {\n continue; // Need more tool calls\n }\n\n if (phase.maxToolCalls && toolCallsInPhase >= phase.maxToolCalls) {\n break; // Hit max tool calls for phase\n }\n\n if (phase.continueIf && !phase.continueIf(state)) {\n break; // Condition not met\n }\n }\n\n return {\n name: phase.name,\n iterations: state.iteration,\n toolCalls: state.toolCallsExecuted - phaseStartTools,\n success: true,\n insights: state.insights,\n };\n }\n}\n\n// ===== PRE-BUILT STRATEGIES =====\n\n/**\n * Factory for creating iteration strategies\n */\nexport class IterationStrategyFactory {\n /**\n * Investigate then respond strategy\n * Phase 1: Use tools to gather information\n * Phase 2: Synthesize into final answer\n */\n static investigateThenRespond(config: {\n maxInvestigationSteps?: number;\n requireMinimumTools?: number;\n finalSynthesis?: boolean;\n } = {}): IterationStrategy {\n const {\n maxInvestigationSteps = 5,\n requireMinimumTools = 1,\n finalSynthesis = true,\n } = config;\n\n return {\n name: 'investigate-then-respond',\n description: 'Investigate using tools, then synthesize findings',\n maxIterations: maxInvestigationSteps + (finalSynthesis ? 1 : 0),\n phases: [\n {\n name: 'investigate',\n maxIterations: maxInvestigationSteps,\n toolUsage: 'encouraged',\n minToolCalls: requireMinimumTools,\n earlyExit: false,\n },\n ...(finalSynthesis ? [{\n name: 'respond',\n maxIterations: 1,\n toolUsage: 'forbidden' as ToolUsagePolicy,\n instructions: 'Based on your investigation, provide a comprehensive answer.',\n requireFinalAnswer: true,\n }] : []),\n ],\n };\n }\n\n /**\n * Multi-pass refinement strategy\n * Generate, critique, refine repeatedly\n */\n static multiPassRefinement(config: {\n passes?: number;\n critiqueBetweenPasses?: boolean;\n improvementThreshold?: number;\n } = {}): IterationStrategy {\n const {\n passes = 3,\n critiqueBetweenPasses = true,\n } = config;\n\n const phases: StrategyPhase[] = [];\n\n for (let i = 0; i < passes; i++) {\n phases.push({\n name: `pass-${i + 1}`,\n maxIterations: 1,\n toolUsage: 'optional',\n instructions: i === 0\n ? 'Generate your best response'\n : 'Refine your previous response based on the critique',\n });\n\n if (critiqueBetweenPasses && i < passes - 1) {\n phases.push({\n name: `critique-${i + 1}`,\n maxIterations: 1,\n toolUsage: 'forbidden',\n instructions: 'Critique the previous response. What can be improved?',\n });\n }\n }\n\n return {\n name: 'multi-pass-refinement',\n description: 'Iteratively refine response through multiple passes',\n maxIterations: passes * 2,\n phases,\n };\n }\n\n /**\n * Breadth-first investigation\n * Explore broadly before going deep\n */\n static breadthFirst(config: {\n levelsDeep?: number;\n toolsPerLevel?: number;\n } = {}): IterationStrategy {\n const {\n levelsDeep = 3,\n toolsPerLevel = 4,\n } = config;\n\n const phases: StrategyPhase[] = [];\n\n for (let level = 0; level < levelsDeep; level++) {\n phases.push({\n name: `level-${level + 1}`,\n maxIterations: toolsPerLevel,\n toolUsage: 'encouraged',\n minToolCalls: 1,\n maxToolCalls: toolsPerLevel,\n instructions: level === 0\n ? 'Get a broad overview'\n : `Dive deeper into areas discovered in level ${level}`,\n });\n }\n\n return {\n name: 'breadth-first',\n description: 'Explore broadly at each level before going deeper',\n maxIterations: levelsDeep * toolsPerLevel,\n phases,\n };\n }\n\n /**\n * Depth-first investigation\n * Deep dive immediately\n */\n static depthFirst(config: {\n maxDepth?: number;\n backtrackOnFailure?: boolean;\n } = {}): IterationStrategy {\n const {\n maxDepth = 5,\n backtrackOnFailure = true,\n } = config;\n\n return {\n name: 'depth-first',\n description: 'Deep dive investigation path',\n maxIterations: maxDepth,\n phases: [{\n name: 'deep-dive',\n maxIterations: maxDepth,\n toolUsage: 'encouraged',\n adaptiveDepth: true,\n }],\n shouldContinue: (state) => {\n // Continue if making progress\n if (backtrackOnFailure && state.errors.length > 2) {\n return false;\n }\n return true;\n },\n };\n }\n\n /**\n * Adaptive strategy\n * Changes behavior based on progress\n */\n static adaptive(_config: {\n strategies?: IterationStrategy[];\n switchConditions?: Array<{\n when: (state: StrategyState) => boolean;\n switchTo: number;\n }>;\n } = {}): IterationStrategy {\n return {\n name: 'adaptive',\n description: 'Adapts strategy based on progress',\n maxIterations: 20,\n onIteration: async (iteration, state) => {\n // Change behavior based on iteration count\n if (iteration < 5) {\n // Early: broad exploration\n return 'continue';\n } else if (iteration < 15) {\n // Mid: focused investigation\n return 'continue';\n } else {\n // Late: wrap up\n return state.toolCallsExecuted > 0 ? 'continue' : 'stop';\n }\n },\n };\n }\n\n /**\n * Simple iteration (basic tool-use loop)\n */\n static simple(config: {\n maxIterations?: number;\n allowTools?: boolean;\n } = {}): IterationStrategy {\n const {\n maxIterations = 10,\n allowTools = true,\n } = config;\n\n return {\n name: 'simple',\n description: 'Simple iteration loop',\n maxIterations,\n phases: [{\n name: 'main',\n maxIterations,\n toolUsage: allowTools ? 'encouraged' : 'forbidden',\n earlyExit: true,\n }],\n };\n }\n}\n\nexport default IterationStrategyFactory;\n\n"],"names":["StrategyExecutor","withReflection","config","reflectionConfig","execute","conversation","tools","strategy","startTime","Date","now","enabled","metricsCollector","MetricsCollector","logger","state","phase","iteration","toolCallsExecuted","insights","findings","errors","info","name","context","llm","onStart","phases","maxIterations","toolUsage","phaseResults","skipIf","debug","phaseResult","executePhase","push","incrementIteration","onPhaseComplete","shouldContinue","duration","result","finalMessage","getLastMessage","totalIterations","success","metrics","getMetrics","getMessages","getMetadata","model","generator","ReflectionReportGenerator","reflection","generate","outputPath","saveReflection","onComplete","iterations","toolCalls","error","fs","path","timestamp","toISOString","replace","filename","format","fullPath","join","mkdir","recursive","writeFile","JSON","stringify","markdown","formatMarkdown","phaseStartTools","instructions","asUser","i","action","onIteration","toolsToProvide","toOpenAIFormat","undefined","response","complete","toMessages","tool_calls","length","warn","asAssistant","content","toolCall","allowedTools","includes","function","tool","toolAction","onToolCall","toolStart","parse","arguments","toolDuration","toolResult","callId","id","toolName","asTool","recordToolCall","onToolResult","message","errorName","earlyExit","toolCallsInPhase","minToolCalls","maxToolCalls","continueIf","wrapLogger","DEFAULT_LOGGER","IterationStrategyFactory","investigateThenRespond","maxInvestigationSteps","requireMinimumTools","finalSynthesis","description","requireFinalAnswer","multiPassRefinement","passes","critiqueBetweenPasses","breadthFirst","levelsDeep","toolsPerLevel","level","depthFirst","maxDepth","backtrackOnFailure","adaptiveDepth","adaptive","_config","simple","allowTools"],"mappings":";;;;;;;;;;;;;;;;AAiJA;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBC,IACM,MAAMA,gBAAAA,CAAAA;AAWT;;QAGAC,cAAAA,CAAeC,MAAwB,EAAQ;QAC3C,IAAI,CAACC,gBAAgB,GAAGD,MAAAA;AACxB,QAAA,OAAO,IAAI;AACf,IAAA;AAEA;;AAEC,QACD,MAAME,OAAAA,CACFC,YAAiC,EACjCC,KAAmB,EACnBC,QAA2B,EACJ;AAInB,QAAA,IAAA,sBAAA;QAHJ,MAAMC,SAAAA,GAAYC,KAAKC,GAAG,EAAA;;QAG1B,IAAA,CAAI,sBAAA,GAAA,IAAI,CAACP,gBAAgB,cAArB,sBAAA,KAAA,MAAA,GAAA,MAAA,GAAA,sBAAA,CAAuBQ,OAAO,EAAE;AAChC,YAAA,IAAI,CAACC,gBAAgB,GAAG,IAAIC,gBAAAA,CAAiB,IAAI,CAACC,MAAM,CAAA;AAC5D,QAAA;AAEA,QAAA,MAAMC,KAAAA,GAAuB;YACzBC,KAAAA,EAAO,CAAA;YACPC,SAAAA,EAAW,CAAA;YACXC,iBAAAA,EAAmB,CAAA;AACnBV,YAAAA,SAAAA;AACAW,YAAAA,QAAAA,EAAU,EAAE;AACZC,YAAAA,QAAAA,EAAU,EAAE;AACZC,YAAAA,MAAAA,EAAQ;AACZ,SAAA;AAEA,QAAA,IAAI,CAACP,MAAM,CAACQ,IAAI,CAAC,6BAAA,EAA+B;AAAEf,YAAAA,QAAAA,EAAUA,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AO,KAAA;AACX,gBAAA;gBACA,OAAO,IAAA;AACX,YAAA;AACJ,SAAA;AACJ,IAAA;AAEA;;;AAGC,QACD,OAAOiD,QAAAA,CAASC,OAAAA,GAMZ,EAAE,EAAqB;QACvB,OAAO;YACHpH,IAAAA,EAAM,UAAA;YACNsG,WAAAA,EAAa,mCAAA;YACbjG,aAAAA,EAAe,EAAA;AACfqD,YAAAA,WAAAA,EAAa,OAAOhE,SAAAA,EAAWF,KAAAA,GAAAA;;AAE3B,gBAAA,IAAIE,YAAY,CAAA,EAAG;;oBAEf,OAAO,UAAA;gBACX,CAAA,MAAO,IAAIA,YAAY,EAAA,EAAI;;oBAEvB,OAAO,UAAA;gBACX,CAAA,MAAO;;AAEH,oBAAA,OAAOF,KAAAA,CAAMG,iBAAiB,GAAG,CAAA,GAAI,UAAA,GAAa,MAAA;AACtD,gBAAA;AACJ,YAAA;AACJ,SAAA;AACJ,IAAA;AAEA;;AAEC,QACD,OAAO0H,MAAAA,CAAO1I,MAAAA,GAGV,EAAE,EAAqB;AACvB,QAAA,MAAM,EACF0B,aAAAA,GAAgB,EAAE,EAClBiH,UAAAA,GAAa,IAAI,EACpB,GAAG3I,MAAAA;QAEJ,OAAO;YACHqB,IAAAA,EAAM,QAAA;YACNsG,WAAAA,EAAa,uBAAA;AACbjG,YAAAA,aAAAA;YACAD,MAAAA,EAAQ;AAAC,gBAAA;oBACLJ,IAAAA,EAAM,MAAA;AACNK,oBAAAA,aAAAA;AACAC,oBAAAA,SAAAA,EAAWgH,aAAa,YAAA,GAAe,WAAA;oBACvC5B,SAAAA,EAAW;AACf;AAAE;AACN,SAAA;AACJ,IAAA;AACJ;;;;"}
|
package/dist/loader.d.ts
CHANGED
|
@@ -3,17 +3,9 @@ import { SectionOptions } from './items/section';
|
|
|
3
3
|
import { Section, Weighted } from './riotprompt';
|
|
4
4
|
declare const OptionsSchema: z.ZodObject<{
|
|
5
5
|
logger: z.ZodDefault<z.ZodOptional<z.ZodAny>>;
|
|
6
|
-
ignorePatterns: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString
|
|
7
|
-
parameters: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]
|
|
8
|
-
},
|
|
9
|
-
parameters: Record<string, string | number | boolean | (string | number | boolean)[]>;
|
|
10
|
-
ignorePatterns: string[];
|
|
11
|
-
logger?: any;
|
|
12
|
-
}, {
|
|
13
|
-
parameters?: Record<string, string | number | boolean | (string | number | boolean)[]> | undefined;
|
|
14
|
-
logger?: any;
|
|
15
|
-
ignorePatterns?: string[] | undefined;
|
|
16
|
-
}>;
|
|
6
|
+
ignorePatterns: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
7
|
+
parameters: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>>>;
|
|
8
|
+
}, z.core.$strip>;
|
|
17
9
|
export type Options = z.infer<typeof OptionsSchema>;
|
|
18
10
|
export type OptionsParam = Partial<Options>;
|
|
19
11
|
export interface Instance {
|
package/dist/loader.js
CHANGED
|
@@ -10,6 +10,9 @@ import './parser.js';
|
|
|
10
10
|
import './override.js';
|
|
11
11
|
import './builder.js';
|
|
12
12
|
import './recipes.js';
|
|
13
|
+
import './conversation.js';
|
|
14
|
+
import 'tiktoken';
|
|
15
|
+
import './tools.js';
|
|
13
16
|
import { create as create$1 } from './util/storage.js';
|
|
14
17
|
|
|
15
18
|
const OptionsSchema = z.object({
|