@agentsmarket/pipeline-runtime 0.5.1 → 0.5.2
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/stages.js +42 -7
- package/dist/webhook.js +0 -0
- package/package.json +1 -1
package/dist/stages.js
CHANGED
|
@@ -274,7 +274,38 @@ function resolveStageProvider(deps, stage, model) {
|
|
|
274
274
|
}
|
|
275
275
|
return deps.registry.resolveWithSupports(stage.provider, model);
|
|
276
276
|
}
|
|
277
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Price one model call, tolerating a model whose price cannot be resolved.
|
|
279
|
+
*
|
|
280
|
+
* Whether a failed lookup is fatal depends on who is paying. Locally the buyer
|
|
281
|
+
* spends their own key — or runs a local model that has no price at all — so a
|
|
282
|
+
* missing price is informational and must not take the run down. On the server
|
|
283
|
+
* we pay from our own key, so an unpriced model is a real loss and stays fatal.
|
|
284
|
+
*
|
|
285
|
+
* This was not hypothetical: the resolver's static table holds exactly two
|
|
286
|
+
* model names, everything else falls through to OpenRouter, which matches on the
|
|
287
|
+
* full namespaced id. So a bare `gpt-4`, or any local model like `llama3`, threw
|
|
288
|
+
* *after* the model had answered and took the whole run down with it. All 24
|
|
289
|
+
* model references across the six canonical pipelines are `MiniMax-M3`, so no
|
|
290
|
+
* shipped pipeline ever reached it.
|
|
291
|
+
*/
|
|
292
|
+
async function priceStageCost(deps, stageId, model, usage) {
|
|
293
|
+
try {
|
|
294
|
+
return await deps.pricing.resolveCostMicroUsdc(model, usage);
|
|
295
|
+
}
|
|
296
|
+
catch (err) {
|
|
297
|
+
if (!deps.isLocal)
|
|
298
|
+
throw err;
|
|
299
|
+
deps.eventSink?.emit(makeStageWarnedEvent({
|
|
300
|
+
stageId,
|
|
301
|
+
message: `no price resolved for model '${model}' — counting this stage as $0. ` +
|
|
302
|
+
'Locally nothing is billed, so this does not change what you pay; the ' +
|
|
303
|
+
'same run against the server would be refused.',
|
|
304
|
+
}));
|
|
305
|
+
return 0;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async function invokeSkill(skill, input, previousContext, skillLabel, provider, retry, retryCtx, outputFormat, maxTokens) {
|
|
278
309
|
const t0 = Date.now();
|
|
279
310
|
const inputStr = JSON.stringify(input ?? {}, null, 2);
|
|
280
311
|
const fullMd = skill.full_md ?? '';
|
|
@@ -283,7 +314,11 @@ async function invokeSkill(skill, input, previousContext, skillLabel, provider,
|
|
|
283
314
|
const ran = await runWithRetry(() => provider.generateText(composedPrompt, {
|
|
284
315
|
system: `${skillLabel}\n${description}`,
|
|
285
316
|
complexity: 'complex',
|
|
286
|
-
|
|
317
|
+
// Same reasoning-budget trap as the direct stage paths: a skill invoked
|
|
318
|
+
// from a stage has no way to declare its own budget, so it inherited the
|
|
319
|
+
// hardcoded 4096 and a reasoning model could spend all of it thinking,
|
|
320
|
+
// returning no text while the stage went on to validate it as JSON.
|
|
321
|
+
maxTokens: Number.isFinite(maxTokens) ? maxTokens : 4096,
|
|
287
322
|
...(outputFormat ? { outputFormat } : {}),
|
|
288
323
|
}), retry, retryCtx);
|
|
289
324
|
return { result: ran.value, durationMs: Date.now() - t0, attempts: ran.attempts };
|
|
@@ -536,7 +571,7 @@ correctionHint) {
|
|
|
536
571
|
});
|
|
537
572
|
continue;
|
|
538
573
|
}
|
|
539
|
-
const { result, durationMs } = await invokeSkill(skill, resolvedInput, previousContext, label, stageProvider, stage.retry, retryCtx, stage.output_format);
|
|
574
|
+
const { result, durationMs } = await invokeSkill(skill, resolvedInput, previousContext, label, stageProvider, stage.retry, retryCtx, stage.output_format, stage.maxTokens);
|
|
540
575
|
await deps.onLlmResponse?.(`${stage.id}:${use.id}`, result.text, skillModel);
|
|
541
576
|
lastResult = result;
|
|
542
577
|
chainedInput = { input_from_previous_skill: result.text };
|
|
@@ -546,7 +581,7 @@ correctionHint) {
|
|
|
546
581
|
duration_ms: durationMs,
|
|
547
582
|
ok: true,
|
|
548
583
|
});
|
|
549
|
-
const skillCost = await deps.
|
|
584
|
+
const skillCost = await priceStageCost(deps, use.id, skillModel, result.usage);
|
|
550
585
|
totalCost += skillCost;
|
|
551
586
|
totalUsage = {
|
|
552
587
|
inputTokens: totalUsage.inputTokens + result.usage.inputTokens,
|
|
@@ -605,7 +640,7 @@ correctionHint) {
|
|
|
605
640
|
model,
|
|
606
641
|
system: resolvedSystem,
|
|
607
642
|
complexity: stage.model?.includes('M3') || stage.model?.includes('opus') ? 'complex' : 'simple',
|
|
608
|
-
maxTokens:
|
|
643
|
+
maxTokens: Number.isFinite(stage.maxTokens) ? stage.maxTokens : 4096,
|
|
609
644
|
fields: stage.fields,
|
|
610
645
|
outputFormat: stage.output_format,
|
|
611
646
|
messages: correctionHint
|
|
@@ -629,13 +664,13 @@ correctionHint) {
|
|
|
629
664
|
model,
|
|
630
665
|
system: resolvedSystem,
|
|
631
666
|
complexity: stage.model?.includes('M3') || stage.model?.includes('opus') ? 'complex' : 'simple',
|
|
632
|
-
maxTokens:
|
|
667
|
+
maxTokens: Number.isFinite(stage.maxTokens) ? stage.maxTokens : 4096,
|
|
633
668
|
fields: stage.fields,
|
|
634
669
|
outputFormat: stage.output_format,
|
|
635
670
|
});
|
|
636
671
|
})(), stage.retry, retryCtx);
|
|
637
672
|
const result = ran.value;
|
|
638
|
-
const costMicroUsdc = await deps.
|
|
673
|
+
const costMicroUsdc = await priceStageCost(deps, stage.id, model, result.usage);
|
|
639
674
|
await deps.onLlmResponse?.(stage.id, result.text, model);
|
|
640
675
|
// When output_schema is present this stage runs under
|
|
641
676
|
// runStageWithOutputValidation, which performs this check inside its retry
|
package/dist/webhook.js
CHANGED
|
File without changes
|
package/package.json
CHANGED