@bastani/atomic 0.9.22 → 0.9.23
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/CHANGELOG.md +16 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +12 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +14 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +51 -12
- package/dist/builtin/workflows/src/index.js +32 -7
- package/dist/core/execution-model-router.js +1 -1
- package/dist/core/execution-model-router.js.map +1 -1
- package/dist/core/model-routing-candidates.d.ts +5 -4
- package/dist/core/model-routing-candidates.d.ts.map +1 -1
- package/dist/core/model-routing-candidates.js +73 -47
- package/dist/core/model-routing-candidates.js.map +1 -1
- package/dist/core/model-routing-evals.d.ts +2 -0
- package/dist/core/model-routing-evals.d.ts.map +1 -1
- package/dist/core/model-routing-evals.js +9 -3
- package/dist/core/model-routing-evals.js.map +1 -1
- package/docs/models/model-selection.md +1 -1
- package/docs/workflows/operations.md +1 -1
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.9.23] - 2026-09-27
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Long sessions no longer leak one open file per bash command. A finished command now releases its output file, an output file with no output is deleted, and output files left behind by Atomic processes that have exited are removed. On macOS, where a child process cannot receive a file descriptor numbered 10240 or higher, the leak eventually made every bash call and spawn fail with `Bad file descriptor`; if a spawn still fails that way, the error now names the cause ([#3313](https://github.com/bastani-inc/atomic/issues/3313)).
|
|
10
|
+
- Resuming a run that failed in a `ctx.tool` call now works when the call ran in parallel with other tools. Siblings that were cancelled or also threw when the run failed are run again on resume, in any order, instead of failing with `replay topology mismatch` or `unfinished or missing completed tool checkpoint`. A resume rejected by changed code no longer runs the failed tool or makes the run unresumable, including after Atomic restarts ([#3314](https://github.com/bastani-inc/atomic/issues/3314)).
|
|
11
|
+
- `model: "auto"` routing no longer ignores benchmark results when fewer than four models are available. Each model's results are now ranked against every model in the evals catalog rather than only the models you can route to, so with just two or three models (for example Opus and Haiku) the stronger model is no longer outranked on price alone, and a model scores the same however many models are enabled.
|
|
12
|
+
|
|
13
|
+
## [0.9.23-alpha.1] - 2026-09-27
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Long sessions no longer leak one open file per bash command. A finished command now releases its output file, an output file with no output is deleted, and output files left behind by Atomic processes that have exited are removed. On macOS, where a child process cannot receive a file descriptor numbered 10240 or higher, the leak eventually made every bash call and spawn fail with `Bad file descriptor`; if a spawn still fails that way, the error now names the cause ([#3313](https://github.com/bastani-inc/atomic/issues/3313)).
|
|
18
|
+
- Resuming a run that failed in a `ctx.tool` call now works when the call ran in parallel with other tools. Siblings that were cancelled or also threw when the run failed are run again on resume, in any order, instead of failing with `replay topology mismatch` or `unfinished or missing completed tool checkpoint`. A resume rejected by changed code no longer runs the failed tool or makes the run unresumable, including after Atomic restarts ([#3314](https://github.com/bastani-inc/atomic/issues/3314)).
|
|
19
|
+
- `model: "auto"` routing no longer ignores benchmark results when fewer than four models are available. Each model's results are now ranked against every model in the evals catalog rather than only the models you can route to, so with just two or three models (for example Opus and Haiku) the stronger model is no longer outranked on price alone, and a model scores the same however many models are enabled.
|
|
20
|
+
|
|
5
21
|
## [0.9.22] - 2026-09-26
|
|
6
22
|
|
|
7
23
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bastani/intercom",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.23",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Atomic extension providing a private coordination channel between parent and child agent sessions. Fork of: https://github.com/nicobailon/pi-intercom",
|
|
6
6
|
"contributors": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bastani/mcp",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.23",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Atomic extension that adapts MCP (Model Context Protocol) servers into the coding agent. Fork of: https://github.com/nicobailon/pi-mcp-adapter",
|
|
6
6
|
"contributors": [
|
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.9.23] - 2026-09-27
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `model: "auto"` routing no longer ignores benchmark results when fewer than four models are available. Each model's results are now ranked against every model in the evals catalog rather than only the models you can route to, so with just two or three models (for example Opus and Haiku) the stronger model is no longer outranked on price alone, and a model scores the same however many models are enabled.
|
|
10
|
+
|
|
11
|
+
## [0.9.23-alpha.1] - 2026-09-27
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- `model: "auto"` routing no longer ignores benchmark results when fewer than four models are available. Each model's results are now ranked against every model in the evals catalog rather than only the models you can route to, so with just two or three models (for example Opus and Haiku) the stronger model is no longer outranked on price alone, and a model scores the same however many models are enabled.
|
|
16
|
+
|
|
5
17
|
## [0.9.21] - 2026-09-26
|
|
6
18
|
|
|
7
19
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bastani/web-access",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.23",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Atomic extension for web search, URL fetching, GitHub repo cloning, PDF/video extraction. Fork of: https://github.com/nicobailon/pi-web-access",
|
|
6
6
|
"contributors": [
|
|
@@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.9.23] - 2026-09-27
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Resuming a run that failed in a `ctx.tool` call now works when the call ran in parallel with other tools. Siblings that were cancelled or also threw when the run failed are run again on resume, in any order, instead of failing with `replay topology mismatch` or `unfinished or missing completed tool checkpoint`. A resume rejected by changed code no longer runs the failed tool or makes the run unresumable, including after Atomic restarts ([#3314](https://github.com/bastani-inc/atomic/issues/3314)).
|
|
14
|
+
- `model: "auto"` routing no longer ignores benchmark results when fewer than four models are available. Each model's results are now ranked against every model in the evals catalog rather than only the models you can route to, so with just two or three models (for example Opus and Haiku) the stronger model is no longer outranked on price alone, and a model scores the same however many models are enabled.
|
|
15
|
+
|
|
16
|
+
## [0.9.23-alpha.1] - 2026-09-27
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Resuming a run that failed in a `ctx.tool` call now works when the call ran in parallel with other tools. Siblings that were cancelled or also threw when the run failed are run again on resume, in any order, instead of failing with `replay topology mismatch` or `unfinished or missing completed tool checkpoint`. A resume rejected by changed code no longer runs the failed tool or makes the run unresumable, including after Atomic restarts ([#3314](https://github.com/bastani-inc/atomic/issues/3314)).
|
|
21
|
+
- `model: "auto"` routing no longer ignores benchmark results when fewer than four models are available. Each model's results are now ranked against every model in the evals catalog rather than only the models you can route to, so with just two or three models (for example Opus and Haiku) the stronger model is no longer outranked on price alone, and a model scores the same however many models are enabled.
|
|
22
|
+
|
|
9
23
|
## [0.9.21] - 2026-09-26
|
|
10
24
|
|
|
11
25
|
### Changed
|
|
@@ -90749,7 +90749,7 @@ async function executeLiveToolInvocation(live) {
|
|
|
90749
90749
|
const cancellation = timeoutFailure ? undefined : invocationCancellation(input, toolSignal);
|
|
90750
90750
|
if (cancellation !== undefined) {
|
|
90751
90751
|
control.noteCancelled();
|
|
90752
|
-
if (returnFailure || isWorkflowToolAbortError(cancellation) && cancellation.scope === "node") {
|
|
90752
|
+
if (returnFailure || isWorkflowToolAbortError(cancellation) && cancellation.scope === "node" || input.runFailing?.() === true) {
|
|
90753
90753
|
await recordCancelledToolInspection(live, startedAt, cancellation, attempts);
|
|
90754
90754
|
}
|
|
90755
90755
|
const endedAt = Date.now();
|
|
@@ -106534,14 +106534,23 @@ function resolveToolResumeFrontier(source, backend) {
|
|
|
106534
106534
|
if (stage.status !== "completed" || !checkpoints.some((checkpoint) => checkpoint.kind === "stage" && checkpoint.replayKey === stage.replayKey && (checkpoint.output !== undefined || ["input", "confirm", "select", "editor", "custom"].includes(stage.name) && stage.replayKey?.startsWith(`prompt:${stage.name}:`) === true && checkpoint.name === stage.name && checkpoint.topology?.stageId === stage.id && checkpoint.topology.status === "completed" && checkpoint.topology.run?.runId === source.id)))
|
|
106535
106535
|
return fail(`unfinished or missing completed stage checkpoint ${stage.id}`);
|
|
106536
106536
|
}
|
|
106537
|
+
const retryToolNodes = [];
|
|
106537
106538
|
for (const tool of tools) {
|
|
106538
106539
|
if (tool.id === frontier.id)
|
|
106539
106540
|
continue;
|
|
106540
106541
|
const checkpoint = backend.getToolCheckpoint(source.id, tool.argsHash);
|
|
106541
|
-
if (checkpoint
|
|
106542
|
-
|
|
106542
|
+
if (checkpoint !== undefined && checkpoint.topology?.nodeId === tool.id)
|
|
106543
|
+
continue;
|
|
106544
|
+
if (checkpoint === undefined && isRetryableSibling(tool)) {
|
|
106545
|
+
retryToolNodes.push(tool);
|
|
106546
|
+
continue;
|
|
106547
|
+
}
|
|
106548
|
+
return fail(`unfinished or missing completed tool checkpoint ${tool.id} (${tool.name}, ${tool.status})`);
|
|
106543
106549
|
}
|
|
106544
|
-
return { ok: true, toolNodeId: frontier.id };
|
|
106550
|
+
return { ok: true, toolNodeId: frontier.id, retryToolNodes };
|
|
106551
|
+
}
|
|
106552
|
+
function isRetryableSibling(tool) {
|
|
106553
|
+
return (tool.status === "cancelled" || tool.status === "failed") && tool.id === `tool:${tool.argsHash}` && Number.isInteger(tool.ordinal) && tool.ordinal >= 1 && tool.topologyState !== "unavailable";
|
|
106545
106554
|
}
|
|
106546
106555
|
|
|
106547
106556
|
// dist/builtin/workflows/src/durable/resume-runtime.ts
|
|
@@ -106686,7 +106695,11 @@ async function resumeDurableWorkflowClaimed(workflowId, deps, catalog) {
|
|
|
106686
106695
|
reason: "startup_failed",
|
|
106687
106696
|
message: frontier?.message ?? `insufficient_state: missing tool frontier in run ${handle.workflowId}`
|
|
106688
106697
|
};
|
|
106689
|
-
toolContinuation = {
|
|
106698
|
+
toolContinuation = {
|
|
106699
|
+
source,
|
|
106700
|
+
resumeFromToolNodeId: frontier.toolNodeId,
|
|
106701
|
+
retryToolNodes: frontier.retryToolNodes
|
|
106702
|
+
};
|
|
106690
106703
|
}
|
|
106691
106704
|
deps.signal?.throwIfAborted();
|
|
106692
106705
|
const sourceFailure = {
|
|
@@ -107655,7 +107668,7 @@ function returnedRecoverableBlockedMetadata(error) {
|
|
|
107655
107668
|
// dist/builtin/workflows/src/engine/run-terminal-failure.ts
|
|
107656
107669
|
function finalizeTerminalFailure(input) {
|
|
107657
107670
|
const { runId, runSnapshot, store, persistence, metadata, onRunEnd } = input;
|
|
107658
|
-
const failedToolNode = metadata.failedToolNodeId === undefined ? undefined : runSnapshot.toolNodes?.find((node) => node.id === metadata.failedToolNodeId);
|
|
107671
|
+
const failedToolNode = metadata.failedToolNodeId === undefined ? undefined : runSnapshot.toolNodes?.find((node) => node.id === metadata.failedToolNodeId) ?? (input.failedToolNode?.id === metadata.failedToolNodeId ? input.failedToolNode : undefined);
|
|
107659
107672
|
const recorded = store.recordRunEnd(runId, "failed", undefined, metadata.errorMessage, metadata);
|
|
107660
107673
|
appendRunEndWhenRecorded(persistence, recorded, {
|
|
107661
107674
|
runId,
|
|
@@ -107854,6 +107867,8 @@ function createToolNodeLifecycle(input) {
|
|
|
107854
107867
|
const ownsCurrentRun = () => store.runs().some((candidate) => candidate === run);
|
|
107855
107868
|
const replayedToolNodeIds = new Set;
|
|
107856
107869
|
let pendingFrontier = input.resumeToolNode;
|
|
107870
|
+
const pendingRetries = new Map((input.retryToolNodes ?? []).map((node) => [node.id, node]));
|
|
107871
|
+
let frontierMismatch;
|
|
107857
107872
|
return {
|
|
107858
107873
|
assertFrontierConsumed: () => {
|
|
107859
107874
|
if (pendingFrontier !== undefined) {
|
|
@@ -107861,12 +107876,18 @@ function createToolNodeLifecycle(input) {
|
|
|
107861
107876
|
}
|
|
107862
107877
|
},
|
|
107863
107878
|
onNodeStart: (node) => {
|
|
107879
|
+
if (node.replayed !== true && frontierMismatch !== undefined)
|
|
107880
|
+
throw frontierMismatch;
|
|
107864
107881
|
const frontier = node.replayed === true ? undefined : pendingFrontier;
|
|
107865
|
-
|
|
107866
|
-
|
|
107882
|
+
const reachesFrontier = frontier !== undefined && sameToolIdentity(node, frontier);
|
|
107883
|
+
const retry = frontier === undefined || reachesFrontier ? undefined : pendingRetries.get(node.id);
|
|
107884
|
+
if (frontier !== undefined && !reachesFrontier && (retry === undefined || !sameToolIdentity(node, retry))) {
|
|
107885
|
+
frontierMismatch = new Error(`${REPLAY_TOPOLOGY_MISMATCH_MESSAGE} for unfinished tool ${frontier.id}`);
|
|
107886
|
+
throw frontierMismatch;
|
|
107867
107887
|
}
|
|
107888
|
+
const expected = reachesFrontier ? frontier : retry;
|
|
107868
107889
|
const inferredParents = tracker.onSpawn(node.id, node.name);
|
|
107869
|
-
const sourceParents =
|
|
107890
|
+
const sourceParents = expected?.parentIds ?? (node.replayed === true && node.topologyState !== "unavailable" ? node.parentIds : undefined);
|
|
107870
107891
|
const restored = sourceParents?.map((sourceId) => sourceToContinuationNodeIds.get(sourceId));
|
|
107871
107892
|
const translated = restored?.every((id) => id !== undefined) ? restored : undefined;
|
|
107872
107893
|
if (run.resumedFromRunId !== undefined && sourceParents !== undefined && translated === undefined) {
|
|
@@ -107883,8 +107904,10 @@ function createToolNodeLifecycle(input) {
|
|
|
107883
107904
|
replayedToolNodeIds.add(node.id);
|
|
107884
107905
|
if (ownsCurrentRun())
|
|
107885
107906
|
store.recordToolNodeStart(run.id, node);
|
|
107886
|
-
if (
|
|
107907
|
+
if (reachesFrontier)
|
|
107887
107908
|
pendingFrontier = undefined;
|
|
107909
|
+
if (retry !== undefined)
|
|
107910
|
+
pendingRetries.delete(retry.id);
|
|
107888
107911
|
},
|
|
107889
107912
|
onNodeRunning: (nodeId, startedAt) => {
|
|
107890
107913
|
if (ownsCurrentRun())
|
|
@@ -107900,6 +107923,17 @@ function createToolNodeLifecycle(input) {
|
|
|
107900
107923
|
runTopology: durableRunTopology(run)
|
|
107901
107924
|
};
|
|
107902
107925
|
}
|
|
107926
|
+
function unconsumedToolFrontier(continuation, errorMessage) {
|
|
107927
|
+
const frontierId = continuation?.resumeFromToolNodeId;
|
|
107928
|
+
if (frontierId === undefined)
|
|
107929
|
+
return;
|
|
107930
|
+
if (!errorMessage.includes(`${REPLAY_TOPOLOGY_MISMATCH_MESSAGE} for unfinished tool ${frontierId}`))
|
|
107931
|
+
return;
|
|
107932
|
+
return continuation?.source.toolNodes?.find((node) => node.id === frontierId);
|
|
107933
|
+
}
|
|
107934
|
+
function sameToolIdentity(node, expected) {
|
|
107935
|
+
return node.id === expected.id && node.argsHash === expected.argsHash && node.ordinal === expected.ordinal;
|
|
107936
|
+
}
|
|
107903
107937
|
function isReplayedContinuationNode(store, run, replayedToolNodeIds, nodeId) {
|
|
107904
107938
|
if (replayedToolNodeIds.has(nodeId))
|
|
107905
107939
|
return true;
|
|
@@ -107938,6 +107972,7 @@ function createTrackedToolPrimitive(input) {
|
|
|
107938
107972
|
throw new Error("atomic-workflows: workflow cancelled");
|
|
107939
107973
|
},
|
|
107940
107974
|
signal: input.controller.signal,
|
|
107975
|
+
runFailing: () => input.terminalEvents.winner()?.kind === "failure",
|
|
107941
107976
|
trackExecution: admittedTools.track,
|
|
107942
107977
|
registerNodeControl: (registration) => {
|
|
107943
107978
|
registration.controller.signal.addEventListener("abort", () => {
|
|
@@ -113645,6 +113680,7 @@ async function run(def, inputs, opts = {}) {
|
|
|
113645
113680
|
run: runSnapshot,
|
|
113646
113681
|
sourceToContinuationNodeIds,
|
|
113647
113682
|
resumeToolNode: opts.continuation?.source.toolNodes?.find((node) => node.id === opts.continuation?.resumeFromToolNodeId),
|
|
113683
|
+
retryToolNodes: opts.continuation?.retryToolNodes,
|
|
113648
113684
|
toolControls,
|
|
113649
113685
|
toolAdmission,
|
|
113650
113686
|
budget
|
|
@@ -114140,7 +114176,8 @@ async function run(def, inputs, opts = {}) {
|
|
|
114140
114176
|
stages: runSnapshot.stages,
|
|
114141
114177
|
classifyFailure: classifyExecutorFailure
|
|
114142
114178
|
}), runSnapshot.stages.length));
|
|
114143
|
-
const
|
|
114179
|
+
const rejectedToolFrontier = unconsumedToolFrontier(opts.continuation, selectedMetadata.errorMessage);
|
|
114180
|
+
const failedToolNodeId = rejectedToolFrontier?.id ?? (selectedMetadata.failedStageId === undefined && selectedMetadata.failureDisposition !== "terminal_killed" ? catchTerminalEvent?.kind === "failure" && Object.is(catchTerminalEvent.error, err) ? catchTerminalEvent.nodeId ?? observedAdmittedToolFailure?.nodeId : observedAdmittedToolFailure?.nodeId : undefined);
|
|
114144
114181
|
const metadata = failedToolNodeId === undefined ? selectedMetadata : { ...selectedMetadata, failedToolNodeId };
|
|
114145
114182
|
if (metadata.failureDisposition === "terminal_killed") {
|
|
114146
114183
|
for (const failedStageId of metadata.failedStageIds)
|
|
@@ -114166,6 +114203,7 @@ async function run(def, inputs, opts = {}) {
|
|
|
114166
114203
|
store: activeStore,
|
|
114167
114204
|
persistence: opts.persistence,
|
|
114168
114205
|
metadata,
|
|
114206
|
+
...rejectedToolFrontier === undefined ? {} : { failedToolNode: rejectedToolFrontier },
|
|
114169
114207
|
onRunEnd: opts.onRunEnd
|
|
114170
114208
|
});
|
|
114171
114209
|
if (durableAdmissionFailure !== undefined && Object.is(durableAdmissionFailure.error, err))
|
|
@@ -115433,7 +115471,8 @@ function createExtensionRuntime(opts = {}) {
|
|
|
115433
115471
|
continuation: {
|
|
115434
115472
|
source,
|
|
115435
115473
|
...resolvedStage.stageId === undefined ? {} : { resumeFromStageId: resolvedStage.stageId },
|
|
115436
|
-
...resolvedStage.toolNodeId === undefined ? {} : { resumeFromToolNodeId: resolvedStage.toolNodeId }
|
|
115474
|
+
...resolvedStage.toolNodeId === undefined ? {} : { resumeFromToolNodeId: resolvedStage.toolNodeId },
|
|
115475
|
+
...resolvedStage.retryToolNodes === undefined ? {} : { retryToolNodes: resolvedStage.retryToolNodes }
|
|
115437
115476
|
}
|
|
115438
115477
|
}
|
|
115439
115478
|
}, [resumableEntryFromHandle(handle)]);
|
|
@@ -36810,7 +36810,7 @@ async function executeLiveToolInvocation(live) {
|
|
|
36810
36810
|
const cancellation = timeoutFailure ? undefined : invocationCancellation(input, toolSignal);
|
|
36811
36811
|
if (cancellation !== undefined) {
|
|
36812
36812
|
control.noteCancelled();
|
|
36813
|
-
if (returnFailure || isWorkflowToolAbortError(cancellation) && cancellation.scope === "node") {
|
|
36813
|
+
if (returnFailure || isWorkflowToolAbortError(cancellation) && cancellation.scope === "node" || input.runFailing?.() === true) {
|
|
36814
36814
|
await recordCancelledToolInspection(live, startedAt, cancellation, attempts);
|
|
36815
36815
|
}
|
|
36816
36816
|
const endedAt = Date.now();
|
|
@@ -49115,7 +49115,7 @@ function createRunTerminalEventArbiter(runId) {
|
|
|
49115
49115
|
// dist/builtin/workflows/src/engine/run-terminal-failure.ts
|
|
49116
49116
|
function finalizeTerminalFailure(input) {
|
|
49117
49117
|
const { runId, runSnapshot, store, persistence, metadata, onRunEnd } = input;
|
|
49118
|
-
const failedToolNode = metadata.failedToolNodeId === undefined ? undefined : runSnapshot.toolNodes?.find((node) => node.id === metadata.failedToolNodeId);
|
|
49118
|
+
const failedToolNode = metadata.failedToolNodeId === undefined ? undefined : runSnapshot.toolNodes?.find((node) => node.id === metadata.failedToolNodeId) ?? (input.failedToolNode?.id === metadata.failedToolNodeId ? input.failedToolNode : undefined);
|
|
49119
49119
|
const recorded = store.recordRunEnd(runId, "failed", undefined, metadata.errorMessage, metadata);
|
|
49120
49120
|
appendRunEndWhenRecorded(persistence, recorded, {
|
|
49121
49121
|
runId,
|
|
@@ -49396,6 +49396,8 @@ function createToolNodeLifecycle(input) {
|
|
|
49396
49396
|
const ownsCurrentRun = () => store.runs().some((candidate) => candidate === run);
|
|
49397
49397
|
const replayedToolNodeIds = new Set;
|
|
49398
49398
|
let pendingFrontier = input.resumeToolNode;
|
|
49399
|
+
const pendingRetries = new Map((input.retryToolNodes ?? []).map((node) => [node.id, node]));
|
|
49400
|
+
let frontierMismatch;
|
|
49399
49401
|
return {
|
|
49400
49402
|
assertFrontierConsumed: () => {
|
|
49401
49403
|
if (pendingFrontier !== undefined) {
|
|
@@ -49403,12 +49405,18 @@ function createToolNodeLifecycle(input) {
|
|
|
49403
49405
|
}
|
|
49404
49406
|
},
|
|
49405
49407
|
onNodeStart: (node) => {
|
|
49408
|
+
if (node.replayed !== true && frontierMismatch !== undefined)
|
|
49409
|
+
throw frontierMismatch;
|
|
49406
49410
|
const frontier = node.replayed === true ? undefined : pendingFrontier;
|
|
49407
|
-
|
|
49408
|
-
|
|
49411
|
+
const reachesFrontier = frontier !== undefined && sameToolIdentity(node, frontier);
|
|
49412
|
+
const retry = frontier === undefined || reachesFrontier ? undefined : pendingRetries.get(node.id);
|
|
49413
|
+
if (frontier !== undefined && !reachesFrontier && (retry === undefined || !sameToolIdentity(node, retry))) {
|
|
49414
|
+
frontierMismatch = new Error(`${REPLAY_TOPOLOGY_MISMATCH_MESSAGE} for unfinished tool ${frontier.id}`);
|
|
49415
|
+
throw frontierMismatch;
|
|
49409
49416
|
}
|
|
49417
|
+
const expected = reachesFrontier ? frontier : retry;
|
|
49410
49418
|
const inferredParents = tracker.onSpawn(node.id, node.name);
|
|
49411
|
-
const sourceParents =
|
|
49419
|
+
const sourceParents = expected?.parentIds ?? (node.replayed === true && node.topologyState !== "unavailable" ? node.parentIds : undefined);
|
|
49412
49420
|
const restored = sourceParents?.map((sourceId) => sourceToContinuationNodeIds.get(sourceId));
|
|
49413
49421
|
const translated = restored?.every((id) => id !== undefined) ? restored : undefined;
|
|
49414
49422
|
if (run.resumedFromRunId !== undefined && sourceParents !== undefined && translated === undefined) {
|
|
@@ -49425,8 +49433,10 @@ function createToolNodeLifecycle(input) {
|
|
|
49425
49433
|
replayedToolNodeIds.add(node.id);
|
|
49426
49434
|
if (ownsCurrentRun())
|
|
49427
49435
|
store.recordToolNodeStart(run.id, node);
|
|
49428
|
-
if (
|
|
49436
|
+
if (reachesFrontier)
|
|
49429
49437
|
pendingFrontier = undefined;
|
|
49438
|
+
if (retry !== undefined)
|
|
49439
|
+
pendingRetries.delete(retry.id);
|
|
49430
49440
|
},
|
|
49431
49441
|
onNodeRunning: (nodeId, startedAt) => {
|
|
49432
49442
|
if (ownsCurrentRun())
|
|
@@ -49442,6 +49452,17 @@ function createToolNodeLifecycle(input) {
|
|
|
49442
49452
|
runTopology: durableRunTopology(run)
|
|
49443
49453
|
};
|
|
49444
49454
|
}
|
|
49455
|
+
function unconsumedToolFrontier(continuation, errorMessage) {
|
|
49456
|
+
const frontierId = continuation?.resumeFromToolNodeId;
|
|
49457
|
+
if (frontierId === undefined)
|
|
49458
|
+
return;
|
|
49459
|
+
if (!errorMessage.includes(`${REPLAY_TOPOLOGY_MISMATCH_MESSAGE} for unfinished tool ${frontierId}`))
|
|
49460
|
+
return;
|
|
49461
|
+
return continuation?.source.toolNodes?.find((node) => node.id === frontierId);
|
|
49462
|
+
}
|
|
49463
|
+
function sameToolIdentity(node, expected) {
|
|
49464
|
+
return node.id === expected.id && node.argsHash === expected.argsHash && node.ordinal === expected.ordinal;
|
|
49465
|
+
}
|
|
49445
49466
|
function isReplayedContinuationNode(store, run, replayedToolNodeIds, nodeId) {
|
|
49446
49467
|
if (replayedToolNodeIds.has(nodeId))
|
|
49447
49468
|
return true;
|
|
@@ -49480,6 +49501,7 @@ function createTrackedToolPrimitive(input) {
|
|
|
49480
49501
|
throw new Error("atomic-workflows: workflow cancelled");
|
|
49481
49502
|
},
|
|
49482
49503
|
signal: input.controller.signal,
|
|
49504
|
+
runFailing: () => input.terminalEvents.winner()?.kind === "failure",
|
|
49483
49505
|
trackExecution: admittedTools.track,
|
|
49484
49506
|
registerNodeControl: (registration) => {
|
|
49485
49507
|
registration.controller.signal.addEventListener("abort", () => {
|
|
@@ -55310,6 +55332,7 @@ async function run(def, inputs, opts = {}) {
|
|
|
55310
55332
|
run: runSnapshot,
|
|
55311
55333
|
sourceToContinuationNodeIds,
|
|
55312
55334
|
resumeToolNode: opts.continuation?.source.toolNodes?.find((node) => node.id === opts.continuation?.resumeFromToolNodeId),
|
|
55335
|
+
retryToolNodes: opts.continuation?.retryToolNodes,
|
|
55313
55336
|
toolControls,
|
|
55314
55337
|
toolAdmission,
|
|
55315
55338
|
budget
|
|
@@ -55805,7 +55828,8 @@ async function run(def, inputs, opts = {}) {
|
|
|
55805
55828
|
stages: runSnapshot.stages,
|
|
55806
55829
|
classifyFailure: classifyExecutorFailure
|
|
55807
55830
|
}), runSnapshot.stages.length));
|
|
55808
|
-
const
|
|
55831
|
+
const rejectedToolFrontier = unconsumedToolFrontier(opts.continuation, selectedMetadata.errorMessage);
|
|
55832
|
+
const failedToolNodeId = rejectedToolFrontier?.id ?? (selectedMetadata.failedStageId === undefined && selectedMetadata.failureDisposition !== "terminal_killed" ? catchTerminalEvent?.kind === "failure" && Object.is(catchTerminalEvent.error, err) ? catchTerminalEvent.nodeId ?? observedAdmittedToolFailure?.nodeId : observedAdmittedToolFailure?.nodeId : undefined);
|
|
55809
55833
|
const metadata = failedToolNodeId === undefined ? selectedMetadata : { ...selectedMetadata, failedToolNodeId };
|
|
55810
55834
|
if (metadata.failureDisposition === "terminal_killed") {
|
|
55811
55835
|
for (const failedStageId of metadata.failedStageIds)
|
|
@@ -55831,6 +55855,7 @@ async function run(def, inputs, opts = {}) {
|
|
|
55831
55855
|
store: activeStore,
|
|
55832
55856
|
persistence: opts.persistence,
|
|
55833
55857
|
metadata,
|
|
55858
|
+
...rejectedToolFrontier === undefined ? {} : { failedToolNode: rejectedToolFrontier },
|
|
55834
55859
|
onRunEnd: opts.onRunEnd
|
|
55835
55860
|
});
|
|
55836
55861
|
if (durableAdmissionFailure !== undefined && Object.is(durableAdmissionFailure.error, err))
|
|
@@ -237,7 +237,7 @@ export async function routeExecutionModel(input) {
|
|
|
237
237
|
...(model.fastRoute ? { fastRouteOf: `${model.provider}/${model.fastRoute.baseModelId}` } : {}),
|
|
238
238
|
});
|
|
239
239
|
// A caller that lists models (`allowedModels`) chooses the contenders itself,
|
|
240
|
-
// but
|
|
240
|
+
// but price and recency still compare them with every model the user could route to.
|
|
241
241
|
const callerListed = constraints.some((constraint) => (constraint.allowedModels?.length ?? 0) > 0);
|
|
242
242
|
const reference = callerListed
|
|
243
243
|
? ctx.modelRegistry
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-model-router.js","sourceRoot":"","sources":["../../src/core/execution-model-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAEN,0BAA0B,EAC1B,0BAA0B,EAC1B,WAAW,GAEX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAEN,cAAc,EACd,WAAW,EAEX,cAAc,GACd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,YAAY,EAGZ,qBAAqB,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,u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IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAC7G;QACD,aAAa;QACb,WAAW;KACX,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n\ttype Api,\n\tcontainsKnownEnvCredential,\n\tgetSupportedThinkingLevels,\n\tisModelType,\n\ttype Model,\n} from \"@bastani/pi-ai\";\nimport { Type } from \"typebox\";\nimport { getDocsPath } from \"../config.js\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport { ROUTING_REQUEST_BYTES } from \"./model-routing-bytes.js\";\nimport {\n\ttype CandidateModel,\n\tdescribeOption,\n\tdistinctTop,\n\ttype RankedCandidate,\n\trankCandidates,\n} from \"./model-routing-candidates.js\";\nimport {\n\teligiblePair,\n\ttype ModelConstraints,\n\ttype ModelRouterOutput,\n\tparseModelConstraints,\n} from \"./model-routing-constraints.js\";\nimport { reportModelRoutingDebug } from \"./model-routing-debug.js\";\nimport { parseEvalsCatalog } from \"./model-routing-evals.js\";\nimport {\n\teffortForDifficulty,\n\tmissingNeedsQuestions,\n\tparseTaskNeeds,\n\ttype ResolvedTaskNeeds,\n\tresolveTaskNeeds,\n\ttype TaskNeeds,\n} from \"./model-routing-needs.js\";\nimport type { ModelRoutingSettings } from \"./settings-types.ts\";\nimport { resolveRouterModel, routeModel } from \"./structured-output/index.js\";\n\nexport interface ModelRoutingContext {\n\treadonly modelRegistry: Pick<\n\t\tModelRegistry,\n\t\t\"getAll\" | \"getAvailable\" | \"streamSimple\" | \"containsConfiguredCredential\"\n\t> &\n\t\tPartial<Pick<ModelRegistry, \"getProviderAuthStatus\" | \"getProviderAuth\" | \"getClassifierModel\" | \"classify\">>;\n\treadonly model?: Model<Api>;\n\tgetRouterModel(): string;\n\t/** Provider filters from settings.json `modelRouting`; absent means every provider is a candidate. */\n\tgetModelRouting?(): ModelRoutingSettings;\n}\nexport interface ModelRoute {\n\treadonly routerSelection: ModelRouterOutput;\n\treadonly modelOverride: string;\n\treadonly fallbackModels?: readonly string[];\n\tassertCurrent(): void;\n\tallowsModel(model: Model<Api>, effort?: string): boolean;\n}\n\n/**\n * Total auto-routing inference failure: Jev and the chat structured-output\n * fallback both failed before any model was selected (#3206). Validation,\n * eligibility, and credential-screening errors are never marked.\n */\nexport class AutoRoutingInferenceError extends Error {\n\t/**\n\t * Route pinned to the current chat model, present only when that model is\n\t * available and satisfies every routing constraint. Consumers may degrade\n\t * to it; when it is absent the failure stays fatal.\n\t */\n\treadonly currentModelRoute?: ModelRoute;\n\n\tconstructor(message: string, currentModelRoute?: ModelRoute) {\n\t\tsuper(message);\n\t\tthis.name = \"AutoRoutingInferenceError\";\n\t\tif (currentModelRoute !== undefined) this.currentModelRoute = currentModelRoute;\n\t}\n}\n\n/** Degraded routes keep a balanced effort when the constraints leave a choice. */\nconst CURRENT_MODEL_EFFORT_PREFERENCE: readonly (string | null)[] = [\n\tnull,\n\t\"medium\",\n\t\"high\",\n\t\"low\",\n\t\"xhigh\",\n\t\"minimal\",\n\t\"max\",\n\t\"off\",\n];\n/** Most options the router compares when it builds the shortlist itself. */\nconst SHORTLIST_SIZE = 6;\n/** Conservative bytes per token when checking that a task fits a reader's context window. */\nconst BYTES_PER_TOKEN = 3;\n/** Room in the reader's window for the questions, instructions and its answer. */\nconst READER_OVERHEAD_TOKENS = 4_000;\n/** Jev accepts at most this many options in one Choice question. */\nconst MAX_CHOICE_OPTIONS = 255;\n\n/** A task that must hold this much in context prefers models whose window is at least this large. */\nconst LONG_CONTEXT_TOKENS = 400_000;\n\nconst NEEDS_INSTRUCTIONS =\n\t\"Read `task`, which `agent` will perform, and answer each field: what kind of work it is, how hard it is, how costly a mistake would be, whether it needs screenshots or images, whether it must hold a very large amount of material in context, and whether speed matters more than extra reasoning. Each field's description lists its options. Judge the task as written; `caller_says` lists answers the caller already gave.\";\nconst CHOICE_INSTRUCTIONS =\n\t\"Pick the model that should do the task `agent` will perform. The task's needs are in `needs`; the task itself is not shown. Each option lists the model's release date, price tier and prices, whether it reads images, and its results for this kind of work and overall; standings compare it with every eligible model. For demanding or high-stakes tasks prefer the best-proven model; for easy, low-stakes tasks prefer an adequate cheaper one. Prefer newer models over older ones with similar results. Missing results are unknown, not weak.\";\n\nconst EVALS_BUDGET_ERROR =\n\t\"Auto routing requires a nonempty evals.md document. Repair the Atomic installation or select a concrete execution model.\";\n\nasync function readModelSelectionEvals(signal?: AbortSignal): Promise<string> {\n\ttry {\n\t\tconst evals = await readFile(join(getDocsPath(), \"models\", \"evals.md\"), { encoding: \"utf8\", signal });\n\t\tif (!evals.trim()) throw new Error(EVALS_BUDGET_ERROR);\n\t\treturn evals;\n\t} catch (error) {\n\t\tsignal?.throwIfAborted();\n\t\tif (error instanceof Error && error.message === EVALS_BUDGET_ERROR) throw error;\n\t\tthrow new Error(EVALS_BUDGET_ERROR);\n\t}\n}\n\nexport async function routeExecutionModel(input: {\n\tctx: ModelRoutingContext;\n\ttask: string;\n\tagent: { name: string; description: string };\n\tconstraints?: readonly ModelConstraints[];\n\tsignal?: AbortSignal;\n\t/** Restore a recorded decision without another inference call. */\n\tselection?: ModelRouterOutput;\n\t/** What the caller already knows about the task; routing asks the router only for the rest. */\n\ttaskNeeds?: TaskNeeds;\n\t/**\n\t * True when this call's own constraints set a provider list because the user\n\t * asked. Only then are the settings.json provider lists replaced; provider\n\t * lists from agent definitions or inherited workflow constraints restrict\n\t * candidates on top of the settings and never lift a user's exclusion.\n\t */\n\toverrideProviderSettings?: boolean;\n}): Promise<ModelRoute> {\n\tconst { ctx, signal } = input;\n\tsignal?.throwIfAborted();\n\tconst constraints = structuredClone((input.constraints ?? []).map((c) => parseModelConstraints(c)!));\n\tconst statedNeeds = parseTaskNeeds(input.taskNeeds);\n\t// settings.json provider lists are defaults that only the call itself may\n\t// replace; every constraint's own provider lists are enforced by eligiblePair.\n\tconst { allowedProviders = [], excludedProviders = [] } = input.overrideProviderSettings\n\t\t? {}\n\t\t: (ctx.getModelRouting?.() ?? {});\n\tconst providerPermitted = (provider: string) =>\n\t\t(allowedProviders.length === 0 || allowedProviders.includes(provider)) && !excludedProviders.includes(provider);\n\tconst catalog = () =>\n\t\tctx.modelRegistry\n\t\t\t.getAvailable()\n\t\t\t.filter((model) => isModelType(model, \"chat\") && providerPermitted(model.provider))\n\t\t\t.map((model) => ({\n\t\t\t\tmodel,\n\t\t\t\tpairs: (model.reasoning ? getSupportedThinkingLevels(model) : [null])\n\t\t\t\t\t.map((effort) => ({ model: `${model.provider}/${model.id}`, effort }))\n\t\t\t\t\t.filter((pair) => eligiblePair(model, pair, constraints)),\n\t\t\t}))\n\t\t\t.filter((entry) => entry.pairs.length > 0);\n\tconst available = catalog();\n\tconst pairs = available.flatMap((entry) => entry.pairs);\n\tif (!pairs.length)\n\t\tthrow new Error(\n\t\t\tallowedProviders.length || excludedProviders.length\n\t\t\t\t? \"Auto routing has no eligible model/effort pairs. Check configured providers, modelConstraints, and the modelRouting allowedProviders/excludedProviders settings.\"\n\t\t\t\t: \"Auto routing has no eligible model/effort pairs. Check configured providers and modelConstraints.\",\n\t\t);\n\tlet selection = input.selection;\n\tif (selection === undefined) {\n\t\tconst settings = { getRouterModel: () => ctx.getRouterModel() };\n\t\tconst router = resolveRouterModel({ settings, currentModel: ctx.model, modelRegistry: ctx.modelRegistry });\n\t\tif (!input.task.trim()) throw new Error(\"Auto routing requires task instructions.\");\n\t\tconst stated = statedNeeds;\n\t\tconst agent = { name: input.agent.name, description: input.agent.description };\n\t\t// Screen the task before any model reads it.\n\t\tconst serialized = JSON.stringify({ task: input.task, agent, stated, constraints });\n\t\tlet configuredCredential: boolean;\n\t\ttry {\n\t\t\tconfiguredCredential = await ctx.modelRegistry.containsConfiguredCredential(serialized);\n\t\t} catch {\n\t\t\tthrow new Error(\"Auto routing could not screen configured credentials. No inference was performed.\");\n\t\t}\n\t\tif (\n\t\t\tcontainsKnownEnvCredential(serialized) ||\n\t\t\tconfiguredCredential ||\n\t\t\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}|-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|\\b(?:sk|ghp|github_pat)[-_][A-Za-z0-9_-]{16,}/i.test(\n\t\t\t\tserialized,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(\"Auto routing context contains credential material. Remove secrets before retrying.\");\n\t\tconst task = input.task;\n\t\t// Degrade only to a current chat model that is available and eligible under\n\t\t// the same constraints, restored through the normal selection path (#3206).\n\t\tconst currentModelRoute = async (): Promise<ModelRoute | undefined> => {\n\t\t\tconst current = ctx.model;\n\t\t\tconst entry = available.find(\n\t\t\t\t(candidate) => candidate.model.provider === current?.provider && candidate.model.id === current?.id,\n\t\t\t);\n\t\t\tconst pair = CURRENT_MODEL_EFFORT_PREFERENCE.map((effort) =>\n\t\t\t\tentry?.pairs.find((candidate) => candidate.effort === effort),\n\t\t\t).find((candidate) => candidate !== undefined);\n\t\t\tif (pair === undefined) return undefined;\n\t\t\treturn routeExecutionModel({ ...input, selection: { model: pair.model, effort: pair.effort } });\n\t\t};\n\t\t// Any failure before a model is chosen is a total inference failure: the\n\t\t// router and its chat structured-output fallback both failed (#3206).\n\t\tconst infer = async <T>(decide: () => Promise<T>): Promise<T> => {\n\t\t\ttry {\n\t\t\t\treturn await decide();\n\t\t\t} catch (error) {\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\tthrow new AutoRoutingInferenceError(\n\t\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\t\tawait currentModelRoute().catch(() => undefined),\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t\t// Where code cannot pick a model either, the current chat model takes over\n\t\t// the same way.\n\t\tconst fallBackToCurrentModel = async (message: string): Promise<never> => {\n\t\t\tthrow new AutoRoutingInferenceError(message, await currentModelRoute().catch(() => undefined));\n\t\t};\n\t\tconst catalogEvals = await readModelSelectionEvals(signal)\n\t\t\t.then(parseEvalsCatalog)\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\treturn fallBackToCurrentModel(error instanceof Error ? error.message : String(error));\n\t\t\t});\n\n\t\t// Step 1: a chat model reads the task and answers only what the caller did\n\t\t// not state. A classifier router such as Jev never receives the task.\n\t\tconst questions = missingNeedsQuestions(stated);\n\t\tlet answers: Record<string, string> = {};\n\t\tif (questions.length) {\n\t\t\tconst current = ctx.model;\n\t\t\tconst preferred =\n\t\t\t\trouter.kind === \"chat\"\n\t\t\t\t\t? router.model\n\t\t\t\t\t: current && current.id !== \"auto\" && isModelType(current, \"chat\")\n\t\t\t\t\t\t? current\n\t\t\t\t\t\t: undefined;\n\t\t\t// The reader gets the complete task. When the task is larger than the\n\t\t\t// preferred reader's window, the cheapest eligible model that holds it\n\t\t\t// reads instead; eligible models are the ones allowed to receive the task.\n\t\t\tconst taskTokens = Math.ceil(Buffer.byteLength(task, \"utf8\") / BYTES_PER_TOKEN) + READER_OVERHEAD_TOKENS;\n\t\t\tconst holdsTask = (model: Model<Api>) => model.contextWindow >= taskTokens;\n\t\t\tconst readerModel =\n\t\t\t\tpreferred && holdsTask(preferred)\n\t\t\t\t\t? preferred\n\t\t\t\t\t: (available\n\t\t\t\t\t\t\t.map((entry) => entry.model)\n\t\t\t\t\t\t\t.filter(holdsTask)\n\t\t\t\t\t\t\t.sort(\n\t\t\t\t\t\t\t\t(a, b) =>\n\t\t\t\t\t\t\t\t\ta.cost.input - b.cost.input ||\n\t\t\t\t\t\t\t\t\t`${a.provider}/${a.id}`.localeCompare(`${b.provider}/${b.id}`),\n\t\t\t\t\t\t\t)[0] ?? preferred);\n\t\t\tconst reader = readerModel ? `${readerModel.provider}/${readerModel.id}` : undefined;\n\t\t\tif (reader === undefined)\n\t\t\t\tawait fallBackToCurrentModel(\n\t\t\t\t\t\"Auto routing needs a chat model to read the task. Select a chat model or state every taskNeeds field.\",\n\t\t\t\t);\n\t\t\tconst schema = Type.Object(\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tquestions.map((question) => [\n\t\t\t\t\t\tquestion.id,\n\t\t\t\t\t\tType.String({\n\t\t\t\t\t\t\tenum: Object.keys(question.criteria),\n\t\t\t\t\t\t\tdescription: `${question.instructions} ${Object.entries(question.criteria)\n\t\t\t\t\t\t\t\t.map(([key, meaning]) => `${key}: ${meaning}`)\n\t\t\t\t\t\t\t\t.join(\"; \")}.`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t\t{ additionalProperties: false },\n\t\t\t);\n\t\t\tconst callerSays = stated\n\t\t\t\t? {\n\t\t\t\t\t\t...(stated.work ? { work: stated.work } : {}),\n\t\t\t\t\t\t...(stated.difficulty ? { difficulty: stated.difficulty } : {}),\n\t\t\t\t\t\t...(stated.mistakeCost ? { mistake_cost: stated.mistakeCost } : {}),\n\t\t\t\t\t\t...(stated.needsImages !== undefined ? { needs_images: stated.needsImages ? \"yes\" : \"no\" } : {}),\n\t\t\t\t\t\t...(stated.longContext !== undefined ? { long_context: stated.longContext ? \"yes\" : \"no\" } : {}),\n\t\t\t\t\t\t...(stated.latencySensitive !== undefined\n\t\t\t\t\t\t\t? { latency_sensitive: stated.latencySensitive ? \"yes\" : \"no\" }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\t\tconst result = await infer(() =>\n\t\t\t\trouteModel(\n\t\t\t\t\t{\n\t\t\t\t\t\tsettings: { getRouterModel: () => reader! },\n\t\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\t\tcurrentModel: ctx.model,\n\t\t\t\t\t\tstate: {\n\t\t\t\t\t\t\ttask,\n\t\t\t\t\t\t\tagent,\n\t\t\t\t\t\t\t...(callerSays && Object.keys(callerSays).length ? { caller_says: callerSays } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinstructions: NEEDS_INSTRUCTIONS,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\t// Unused: the reader always resolves to a chat model.\n\t\t\t\t\t\tclassifier: {\n\t\t\t\t\t\t\tquestions: Object.fromEntries(\n\t\t\t\t\t\t\t\tquestions.map((question) => [\n\t\t\t\t\t\t\t\t\tquestion.id,\n\t\t\t\t\t\t\t\t\t{ instructions: question.instructions, criteria: question.criteria },\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tdecode: (choices) =>\n\t\t\t\t\t\t\t\tObject.fromEntries(questions.map((question) => [question.id, choices[question.id]!])),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t},\n\t\t\t\t\t(value) => questions.every((question) => Object.hasOwn(question.criteria, String(value[question.id]))),\n\t\t\t\t),\n\t\t\t);\n\t\t\tanswers = result.value;\n\t\t}\n\t\tconst needs: ResolvedTaskNeeds = resolveTaskNeeds(stated, answers);\n\n\t\t// Step 2: narrow in code. A task that needs images only goes to models that read them.\n\t\tconst seeing = needs.needsImages ? available.filter((entry) => entry.model.input.includes(\"image\")) : available;\n\t\tif (seeing.length === 0)\n\t\t\tawait fallBackToCurrentModel(\n\t\t\t\t\"Auto routing: this task needs a model that can read images, and no eligible model can. Allow an image-capable model or select a concrete execution model.\",\n\t\t\t);\n\t\t// A large context window is preferred, not required: context size is a matter of degree.\n\t\tconst roomy = needs.longContext\n\t\t\t? seeing.filter((entry) => entry.model.contextWindow >= LONG_CONTEXT_TOKENS)\n\t\t\t: seeing;\n\t\tconst usable = roomy.length ? roomy : seeing;\n\t\tconst pairsFor = new Map(usable.map((entry) => [`${entry.model.provider}/${entry.model.id}`, entry.pairs]));\n\t\tconst toCandidate = (model: Model<Api>): CandidateModel => ({\n\t\t\tmodel: `${model.provider}/${model.id}`,\n\t\t\tname: model.name,\n\t\t\tcost: model.cost,\n\t\t\tinput: model.input,\n\t\t\t...(model.fastRoute ? { fastRouteOf: `${model.provider}/${model.fastRoute.baseModelId}` } : {}),\n\t\t});\n\t\t// A caller that lists models (`allowedModels`) chooses the contenders itself,\n\t\t// but standings still compare them with every model the user could route to.\n\t\tconst callerListed = constraints.some((constraint) => (constraint.allowedModels?.length ?? 0) > 0);\n\t\tconst reference = callerListed\n\t\t\t? ctx.modelRegistry\n\t\t\t\t\t.getAvailable()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(model) =>\n\t\t\t\t\t\t\tisModelType(model, \"chat\") &&\n\t\t\t\t\t\t\tproviderPermitted(model.provider) &&\n\t\t\t\t\t\t\t(!needs.needsImages || model.input.includes(\"image\")),\n\t\t\t\t\t)\n\t\t\t: usable.map((entry) => entry.model);\n\t\tconst standings = rankCandidates(catalogEvals, reference.map(toCandidate), needs);\n\t\tconst ranked = standings.filter((candidate) => pairsFor.has(candidate.model));\n\t\tconst choiceState = {\n\t\t\tagent,\n\t\t\tneeds: {\n\t\t\t\twork: needs.work,\n\t\t\t\tdifficulty: needs.difficulty,\n\t\t\t\tmistake_cost: needs.mistakeCost,\n\t\t\t\tneeds_images: needs.needsImages,\n\t\t\t\tlong_context: needs.longContext,\n\t\t\t\tlatency_sensitive: needs.latencySensitive,\n\t\t\t},\n\t\t};\n\t\tconst describeAll = (options: readonly RankedCandidate[]) =>\n\t\t\tObject.fromEntries(options.map((option, index) => [`m${index}`, describeOption(option, needs, standings)]));\n\t\tconst fitsOneChoice = (options: readonly RankedCandidate[]) =>\n\t\t\toptions.length <= MAX_CHOICE_OPTIONS &&\n\t\t\tBuffer.byteLength(\n\t\t\t\tJSON.stringify({ state: choiceState, instructions: CHOICE_INSTRUCTIONS, criteria: describeAll(options) }),\n\t\t\t\t\"utf8\",\n\t\t\t) <= ROUTING_REQUEST_BYTES;\n\t\t// A caller's list is offered whole when it fits one choice request; otherwise\n\t\t// duplicate routes of one model share a slot, and a list that still does not\n\t\t// fit falls back rather than silently dropping a contender.\n\t\tconst callerChoices = !callerListed || fitsOneChoice(ranked) ? ranked : distinctTop(ranked, ranked.length);\n\t\tif (callerListed && !fitsOneChoice(callerChoices))\n\t\t\tawait fallBackToCurrentModel(\n\t\t\t\t`Auto routing cannot compare ${callerChoices.length} different models from modelConstraints.allowedModels in one routing request. List fewer models.`,\n\t\t\t);\n\t\tconst shortlist = callerListed ? callerChoices : distinctTop(ranked, SHORTLIST_SIZE);\n\n\t\t// Step 3: the router picks one option; each carries its own evidence.\n\t\tlet chosen = shortlist[0]!;\n\t\tif (shortlist.length > 1) {\n\t\t\tconst keys = shortlist.map((_, index) => `m${index}`);\n\t\t\tconst schema = Type.Object(\n\t\t\t\t{ modelId: Type.String({ enum: shortlist.map((option) => option.model) }) },\n\t\t\t\t{ additionalProperties: false },\n\t\t\t);\n\t\t\tconst result = await infer(() =>\n\t\t\t\trouteModel(\n\t\t\t\t\t{\n\t\t\t\t\t\tsettings,\n\t\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\t\tcurrentModel: ctx.model,\n\t\t\t\t\t\tstate: {\n\t\t\t\t\t\t\t...choiceState,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinstructions: CHOICE_INSTRUCTIONS,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tclassifier: {\n\t\t\t\t\t\t\tquestions: {\n\t\t\t\t\t\t\t\tmodel: {\n\t\t\t\t\t\t\t\t\tinstructions: \"Which model should do this task?\",\n\t\t\t\t\t\t\t\t\tcriteria: describeAll(shortlist),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdecode: (choices) => {\n\t\t\t\t\t\t\t\tconst option = shortlist[keys.indexOf(choices.model ?? \"\")];\n\t\t\t\t\t\t\t\tif (!option) throw new Error(\"Invalid execution model Choice.\");\n\t\t\t\t\t\t\t\treturn { modelId: option.model };\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t},\n\t\t\t\t\t(value) => shortlist.some((option) => option.model === value.modelId),\n\t\t\t\t),\n\t\t\t);\n\t\t\tchosen = shortlist.find((option) => option.model === result.value.modelId)!;\n\t\t}\n\n\t\t// Step 4: effort from difficulty; fallbacks are the next distinct models in code's ranking.\n\t\tconst effortOf = (model: string) =>\n\t\t\teffortForDifficulty(\n\t\t\t\t(pairsFor.get(model) ?? []).map((pair) => pair.effort),\n\t\t\t\tneeds.difficulty,\n\t\t\t\tneeds.latencySensitive,\n\t\t\t);\n\t\tconst fallbackModels = distinctTop(\n\t\t\tranked.filter((candidate) => candidate.baseKey !== chosen.baseKey),\n\t\t\t2,\n\t\t);\n\t\treportModelRoutingDebug(\n\t\t\t`Auto routing: ${needs.work}, ${needs.difficulty}, mistake cost ${needs.mistakeCost}, images ${needs.needsImages ? \"yes\" : \"no\"}, long context ${needs.longContext ? \"yes\" : \"no\"}, latency ${needs.latencySensitive ? \"sensitive\" : \"tolerant\"}; chose ${chosen.model} from ${shortlist.map((option) => option.model).join(\", \")}.`,\n\t\t);\n\t\tselection = {\n\t\t\tmodel: chosen.model,\n\t\t\teffort: effortOf(chosen.model),\n\t\t\t...(fallbackModels.length\n\t\t\t\t? {\n\t\t\t\t\t\tfallbacks: fallbackModels.map((candidate) => ({\n\t\t\t\t\t\t\tmodel: candidate.model,\n\t\t\t\t\t\t\teffort: effortOf(candidate.model),\n\t\t\t\t\t\t})),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t};\n\t}\n\tconst fallbacks = selection.fallbacks?.map((pair) => Object.freeze({ model: pair.model, effort: pair.effort }));\n\tif (\n\t\tfallbacks &&\n\t\t(fallbacks.length > 2 ||\n\t\t\tnew Set([selection.model, ...fallbacks.map((pair) => pair.model)]).size !== fallbacks.length + 1)\n\t)\n\t\tthrow new Error(\"Invalid ranked auto selection: expected up to three distinct models.\");\n\tconst routerSelection = Object.freeze({\n\t\tmodel: selection.model,\n\t\teffort: selection.effort,\n\t\t...(fallbacks?.length ? { fallbacks: Object.freeze(fallbacks) } : {}),\n\t});\n\tconst hasPair = (pair: ModelRouterOutput) =>\n\t\tcatalog().some((entry) => entry.pairs.some((p) => p.model === pair.model && p.effort === pair.effort));\n\tconst allowsModel = (model: Model<Api>, effort?: string): boolean => {\n\t\tconst levels = model.reasoning ? getSupportedThinkingLevels(model) : [null];\n\t\treturn levels.some((level) => {\n\t\t\tif (model.reasoning && effort !== undefined && level !== effort) return false;\n\t\t\tconst pair = { model: `${model.provider}/${model.id}`, effort: level };\n\t\t\treturn eligiblePair(model, pair, constraints) && hasPair(pair);\n\t\t});\n\t};\n\tconst assertCurrent = () => {\n\t\tsignal?.throwIfAborted();\n\t\tif (![routerSelection, ...(routerSelection.fallbacks ?? [])].every(hasPair))\n\t\t\tthrow new Error(\"Auto selection is no longer eligible. Retry explicitly with the current catalog.\");\n\t};\n\tassertCurrent();\n\treturn {\n\t\trouterSelection,\n\t\tmodelOverride: routerSelection.model + (routerSelection.effort === null ? \"\" : `:${routerSelection.effort}`),\n\t\tfallbackModels: Object.freeze(\n\t\t\t(routerSelection.fallbacks ?? []).map((pair) => pair.model + (pair.effort === null ? \"\" : `:${pair.effort}`)),\n\t\t),\n\t\tassertCurrent,\n\t\tallowsModel,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"execution-model-router.js","sourceRoot":"","sources":["../../src/core/execution-model-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAEN,0BAA0B,EAC1B,0BAA0B,EAC1B,WAAW,GAEX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAEN,cAAc,EACd,WAAW,EAEX,cAAc,GACd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,YAAY,EAGZ,qBAAqB,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,E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AAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAC7G;QACD,aAAa;QACb,WAAW;KACX,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n\ttype Api,\n\tcontainsKnownEnvCredential,\n\tgetSupportedThinkingLevels,\n\tisModelType,\n\ttype Model,\n} from \"@bastani/pi-ai\";\nimport { Type } from \"typebox\";\nimport { getDocsPath } from \"../config.js\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport { ROUTING_REQUEST_BYTES } from \"./model-routing-bytes.js\";\nimport {\n\ttype CandidateModel,\n\tdescribeOption,\n\tdistinctTop,\n\ttype RankedCandidate,\n\trankCandidates,\n} from \"./model-routing-candidates.js\";\nimport {\n\teligiblePair,\n\ttype ModelConstraints,\n\ttype ModelRouterOutput,\n\tparseModelConstraints,\n} from \"./model-routing-constraints.js\";\nimport { reportModelRoutingDebug } from \"./model-routing-debug.js\";\nimport { parseEvalsCatalog } from \"./model-routing-evals.js\";\nimport {\n\teffortForDifficulty,\n\tmissingNeedsQuestions,\n\tparseTaskNeeds,\n\ttype ResolvedTaskNeeds,\n\tresolveTaskNeeds,\n\ttype TaskNeeds,\n} from \"./model-routing-needs.js\";\nimport type { ModelRoutingSettings } from \"./settings-types.ts\";\nimport { resolveRouterModel, routeModel } from \"./structured-output/index.js\";\n\nexport interface ModelRoutingContext {\n\treadonly modelRegistry: Pick<\n\t\tModelRegistry,\n\t\t\"getAll\" | \"getAvailable\" | \"streamSimple\" | \"containsConfiguredCredential\"\n\t> &\n\t\tPartial<Pick<ModelRegistry, \"getProviderAuthStatus\" | \"getProviderAuth\" | \"getClassifierModel\" | \"classify\">>;\n\treadonly model?: Model<Api>;\n\tgetRouterModel(): string;\n\t/** Provider filters from settings.json `modelRouting`; absent means every provider is a candidate. */\n\tgetModelRouting?(): ModelRoutingSettings;\n}\nexport interface ModelRoute {\n\treadonly routerSelection: ModelRouterOutput;\n\treadonly modelOverride: string;\n\treadonly fallbackModels?: readonly string[];\n\tassertCurrent(): void;\n\tallowsModel(model: Model<Api>, effort?: string): boolean;\n}\n\n/**\n * Total auto-routing inference failure: Jev and the chat structured-output\n * fallback both failed before any model was selected (#3206). Validation,\n * eligibility, and credential-screening errors are never marked.\n */\nexport class AutoRoutingInferenceError extends Error {\n\t/**\n\t * Route pinned to the current chat model, present only when that model is\n\t * available and satisfies every routing constraint. Consumers may degrade\n\t * to it; when it is absent the failure stays fatal.\n\t */\n\treadonly currentModelRoute?: ModelRoute;\n\n\tconstructor(message: string, currentModelRoute?: ModelRoute) {\n\t\tsuper(message);\n\t\tthis.name = \"AutoRoutingInferenceError\";\n\t\tif (currentModelRoute !== undefined) this.currentModelRoute = currentModelRoute;\n\t}\n}\n\n/** Degraded routes keep a balanced effort when the constraints leave a choice. */\nconst CURRENT_MODEL_EFFORT_PREFERENCE: readonly (string | null)[] = [\n\tnull,\n\t\"medium\",\n\t\"high\",\n\t\"low\",\n\t\"xhigh\",\n\t\"minimal\",\n\t\"max\",\n\t\"off\",\n];\n/** Most options the router compares when it builds the shortlist itself. */\nconst SHORTLIST_SIZE = 6;\n/** Conservative bytes per token when checking that a task fits a reader's context window. */\nconst BYTES_PER_TOKEN = 3;\n/** Room in the reader's window for the questions, instructions and its answer. */\nconst READER_OVERHEAD_TOKENS = 4_000;\n/** Jev accepts at most this many options in one Choice question. */\nconst MAX_CHOICE_OPTIONS = 255;\n\n/** A task that must hold this much in context prefers models whose window is at least this large. */\nconst LONG_CONTEXT_TOKENS = 400_000;\n\nconst NEEDS_INSTRUCTIONS =\n\t\"Read `task`, which `agent` will perform, and answer each field: what kind of work it is, how hard it is, how costly a mistake would be, whether it needs screenshots or images, whether it must hold a very large amount of material in context, and whether speed matters more than extra reasoning. Each field's description lists its options. Judge the task as written; `caller_says` lists answers the caller already gave.\";\nconst CHOICE_INSTRUCTIONS =\n\t\"Pick the model that should do the task `agent` will perform. The task's needs are in `needs`; the task itself is not shown. Each option lists the model's release date, price tier and prices, whether it reads images, and its results for this kind of work and overall; standings compare it with every eligible model. For demanding or high-stakes tasks prefer the best-proven model; for easy, low-stakes tasks prefer an adequate cheaper one. Prefer newer models over older ones with similar results. Missing results are unknown, not weak.\";\n\nconst EVALS_BUDGET_ERROR =\n\t\"Auto routing requires a nonempty evals.md document. Repair the Atomic installation or select a concrete execution model.\";\n\nasync function readModelSelectionEvals(signal?: AbortSignal): Promise<string> {\n\ttry {\n\t\tconst evals = await readFile(join(getDocsPath(), \"models\", \"evals.md\"), { encoding: \"utf8\", signal });\n\t\tif (!evals.trim()) throw new Error(EVALS_BUDGET_ERROR);\n\t\treturn evals;\n\t} catch (error) {\n\t\tsignal?.throwIfAborted();\n\t\tif (error instanceof Error && error.message === EVALS_BUDGET_ERROR) throw error;\n\t\tthrow new Error(EVALS_BUDGET_ERROR);\n\t}\n}\n\nexport async function routeExecutionModel(input: {\n\tctx: ModelRoutingContext;\n\ttask: string;\n\tagent: { name: string; description: string };\n\tconstraints?: readonly ModelConstraints[];\n\tsignal?: AbortSignal;\n\t/** Restore a recorded decision without another inference call. */\n\tselection?: ModelRouterOutput;\n\t/** What the caller already knows about the task; routing asks the router only for the rest. */\n\ttaskNeeds?: TaskNeeds;\n\t/**\n\t * True when this call's own constraints set a provider list because the user\n\t * asked. Only then are the settings.json provider lists replaced; provider\n\t * lists from agent definitions or inherited workflow constraints restrict\n\t * candidates on top of the settings and never lift a user's exclusion.\n\t */\n\toverrideProviderSettings?: boolean;\n}): Promise<ModelRoute> {\n\tconst { ctx, signal } = input;\n\tsignal?.throwIfAborted();\n\tconst constraints = structuredClone((input.constraints ?? []).map((c) => parseModelConstraints(c)!));\n\tconst statedNeeds = parseTaskNeeds(input.taskNeeds);\n\t// settings.json provider lists are defaults that only the call itself may\n\t// replace; every constraint's own provider lists are enforced by eligiblePair.\n\tconst { allowedProviders = [], excludedProviders = [] } = input.overrideProviderSettings\n\t\t? {}\n\t\t: (ctx.getModelRouting?.() ?? {});\n\tconst providerPermitted = (provider: string) =>\n\t\t(allowedProviders.length === 0 || allowedProviders.includes(provider)) && !excludedProviders.includes(provider);\n\tconst catalog = () =>\n\t\tctx.modelRegistry\n\t\t\t.getAvailable()\n\t\t\t.filter((model) => isModelType(model, \"chat\") && providerPermitted(model.provider))\n\t\t\t.map((model) => ({\n\t\t\t\tmodel,\n\t\t\t\tpairs: (model.reasoning ? getSupportedThinkingLevels(model) : [null])\n\t\t\t\t\t.map((effort) => ({ model: `${model.provider}/${model.id}`, effort }))\n\t\t\t\t\t.filter((pair) => eligiblePair(model, pair, constraints)),\n\t\t\t}))\n\t\t\t.filter((entry) => entry.pairs.length > 0);\n\tconst available = catalog();\n\tconst pairs = available.flatMap((entry) => entry.pairs);\n\tif (!pairs.length)\n\t\tthrow new Error(\n\t\t\tallowedProviders.length || excludedProviders.length\n\t\t\t\t? \"Auto routing has no eligible model/effort pairs. Check configured providers, modelConstraints, and the modelRouting allowedProviders/excludedProviders settings.\"\n\t\t\t\t: \"Auto routing has no eligible model/effort pairs. Check configured providers and modelConstraints.\",\n\t\t);\n\tlet selection = input.selection;\n\tif (selection === undefined) {\n\t\tconst settings = { getRouterModel: () => ctx.getRouterModel() };\n\t\tconst router = resolveRouterModel({ settings, currentModel: ctx.model, modelRegistry: ctx.modelRegistry });\n\t\tif (!input.task.trim()) throw new Error(\"Auto routing requires task instructions.\");\n\t\tconst stated = statedNeeds;\n\t\tconst agent = { name: input.agent.name, description: input.agent.description };\n\t\t// Screen the task before any model reads it.\n\t\tconst serialized = JSON.stringify({ task: input.task, agent, stated, constraints });\n\t\tlet configuredCredential: boolean;\n\t\ttry {\n\t\t\tconfiguredCredential = await ctx.modelRegistry.containsConfiguredCredential(serialized);\n\t\t} catch {\n\t\t\tthrow new Error(\"Auto routing could not screen configured credentials. No inference was performed.\");\n\t\t}\n\t\tif (\n\t\t\tcontainsKnownEnvCredential(serialized) ||\n\t\t\tconfiguredCredential ||\n\t\t\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}|-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|\\b(?:sk|ghp|github_pat)[-_][A-Za-z0-9_-]{16,}/i.test(\n\t\t\t\tserialized,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(\"Auto routing context contains credential material. Remove secrets before retrying.\");\n\t\tconst task = input.task;\n\t\t// Degrade only to a current chat model that is available and eligible under\n\t\t// the same constraints, restored through the normal selection path (#3206).\n\t\tconst currentModelRoute = async (): Promise<ModelRoute | undefined> => {\n\t\t\tconst current = ctx.model;\n\t\t\tconst entry = available.find(\n\t\t\t\t(candidate) => candidate.model.provider === current?.provider && candidate.model.id === current?.id,\n\t\t\t);\n\t\t\tconst pair = CURRENT_MODEL_EFFORT_PREFERENCE.map((effort) =>\n\t\t\t\tentry?.pairs.find((candidate) => candidate.effort === effort),\n\t\t\t).find((candidate) => candidate !== undefined);\n\t\t\tif (pair === undefined) return undefined;\n\t\t\treturn routeExecutionModel({ ...input, selection: { model: pair.model, effort: pair.effort } });\n\t\t};\n\t\t// Any failure before a model is chosen is a total inference failure: the\n\t\t// router and its chat structured-output fallback both failed (#3206).\n\t\tconst infer = async <T>(decide: () => Promise<T>): Promise<T> => {\n\t\t\ttry {\n\t\t\t\treturn await decide();\n\t\t\t} catch (error) {\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\tthrow new AutoRoutingInferenceError(\n\t\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\t\tawait currentModelRoute().catch(() => undefined),\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t\t// Where code cannot pick a model either, the current chat model takes over\n\t\t// the same way.\n\t\tconst fallBackToCurrentModel = async (message: string): Promise<never> => {\n\t\t\tthrow new AutoRoutingInferenceError(message, await currentModelRoute().catch(() => undefined));\n\t\t};\n\t\tconst catalogEvals = await readModelSelectionEvals(signal)\n\t\t\t.then(parseEvalsCatalog)\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\treturn fallBackToCurrentModel(error instanceof Error ? error.message : String(error));\n\t\t\t});\n\n\t\t// Step 1: a chat model reads the task and answers only what the caller did\n\t\t// not state. A classifier router such as Jev never receives the task.\n\t\tconst questions = missingNeedsQuestions(stated);\n\t\tlet answers: Record<string, string> = {};\n\t\tif (questions.length) {\n\t\t\tconst current = ctx.model;\n\t\t\tconst preferred =\n\t\t\t\trouter.kind === \"chat\"\n\t\t\t\t\t? router.model\n\t\t\t\t\t: current && current.id !== \"auto\" && isModelType(current, \"chat\")\n\t\t\t\t\t\t? current\n\t\t\t\t\t\t: undefined;\n\t\t\t// The reader gets the complete task. When the task is larger than the\n\t\t\t// preferred reader's window, the cheapest eligible model that holds it\n\t\t\t// reads instead; eligible models are the ones allowed to receive the task.\n\t\t\tconst taskTokens = Math.ceil(Buffer.byteLength(task, \"utf8\") / BYTES_PER_TOKEN) + READER_OVERHEAD_TOKENS;\n\t\t\tconst holdsTask = (model: Model<Api>) => model.contextWindow >= taskTokens;\n\t\t\tconst readerModel =\n\t\t\t\tpreferred && holdsTask(preferred)\n\t\t\t\t\t? preferred\n\t\t\t\t\t: (available\n\t\t\t\t\t\t\t.map((entry) => entry.model)\n\t\t\t\t\t\t\t.filter(holdsTask)\n\t\t\t\t\t\t\t.sort(\n\t\t\t\t\t\t\t\t(a, b) =>\n\t\t\t\t\t\t\t\t\ta.cost.input - b.cost.input ||\n\t\t\t\t\t\t\t\t\t`${a.provider}/${a.id}`.localeCompare(`${b.provider}/${b.id}`),\n\t\t\t\t\t\t\t)[0] ?? preferred);\n\t\t\tconst reader = readerModel ? `${readerModel.provider}/${readerModel.id}` : undefined;\n\t\t\tif (reader === undefined)\n\t\t\t\tawait fallBackToCurrentModel(\n\t\t\t\t\t\"Auto routing needs a chat model to read the task. Select a chat model or state every taskNeeds field.\",\n\t\t\t\t);\n\t\t\tconst schema = Type.Object(\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tquestions.map((question) => [\n\t\t\t\t\t\tquestion.id,\n\t\t\t\t\t\tType.String({\n\t\t\t\t\t\t\tenum: Object.keys(question.criteria),\n\t\t\t\t\t\t\tdescription: `${question.instructions} ${Object.entries(question.criteria)\n\t\t\t\t\t\t\t\t.map(([key, meaning]) => `${key}: ${meaning}`)\n\t\t\t\t\t\t\t\t.join(\"; \")}.`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t\t{ additionalProperties: false },\n\t\t\t);\n\t\t\tconst callerSays = stated\n\t\t\t\t? {\n\t\t\t\t\t\t...(stated.work ? { work: stated.work } : {}),\n\t\t\t\t\t\t...(stated.difficulty ? { difficulty: stated.difficulty } : {}),\n\t\t\t\t\t\t...(stated.mistakeCost ? { mistake_cost: stated.mistakeCost } : {}),\n\t\t\t\t\t\t...(stated.needsImages !== undefined ? { needs_images: stated.needsImages ? \"yes\" : \"no\" } : {}),\n\t\t\t\t\t\t...(stated.longContext !== undefined ? { long_context: stated.longContext ? \"yes\" : \"no\" } : {}),\n\t\t\t\t\t\t...(stated.latencySensitive !== undefined\n\t\t\t\t\t\t\t? { latency_sensitive: stated.latencySensitive ? \"yes\" : \"no\" }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\t\tconst result = await infer(() =>\n\t\t\t\trouteModel(\n\t\t\t\t\t{\n\t\t\t\t\t\tsettings: { getRouterModel: () => reader! },\n\t\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\t\tcurrentModel: ctx.model,\n\t\t\t\t\t\tstate: {\n\t\t\t\t\t\t\ttask,\n\t\t\t\t\t\t\tagent,\n\t\t\t\t\t\t\t...(callerSays && Object.keys(callerSays).length ? { caller_says: callerSays } : {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinstructions: NEEDS_INSTRUCTIONS,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\t// Unused: the reader always resolves to a chat model.\n\t\t\t\t\t\tclassifier: {\n\t\t\t\t\t\t\tquestions: Object.fromEntries(\n\t\t\t\t\t\t\t\tquestions.map((question) => [\n\t\t\t\t\t\t\t\t\tquestion.id,\n\t\t\t\t\t\t\t\t\t{ instructions: question.instructions, criteria: question.criteria },\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tdecode: (choices) =>\n\t\t\t\t\t\t\t\tObject.fromEntries(questions.map((question) => [question.id, choices[question.id]!])),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t},\n\t\t\t\t\t(value) => questions.every((question) => Object.hasOwn(question.criteria, String(value[question.id]))),\n\t\t\t\t),\n\t\t\t);\n\t\t\tanswers = result.value;\n\t\t}\n\t\tconst needs: ResolvedTaskNeeds = resolveTaskNeeds(stated, answers);\n\n\t\t// Step 2: narrow in code. A task that needs images only goes to models that read them.\n\t\tconst seeing = needs.needsImages ? available.filter((entry) => entry.model.input.includes(\"image\")) : available;\n\t\tif (seeing.length === 0)\n\t\t\tawait fallBackToCurrentModel(\n\t\t\t\t\"Auto routing: this task needs a model that can read images, and no eligible model can. Allow an image-capable model or select a concrete execution model.\",\n\t\t\t);\n\t\t// A large context window is preferred, not required: context size is a matter of degree.\n\t\tconst roomy = needs.longContext\n\t\t\t? seeing.filter((entry) => entry.model.contextWindow >= LONG_CONTEXT_TOKENS)\n\t\t\t: seeing;\n\t\tconst usable = roomy.length ? roomy : seeing;\n\t\tconst pairsFor = new Map(usable.map((entry) => [`${entry.model.provider}/${entry.model.id}`, entry.pairs]));\n\t\tconst toCandidate = (model: Model<Api>): CandidateModel => ({\n\t\t\tmodel: `${model.provider}/${model.id}`,\n\t\t\tname: model.name,\n\t\t\tcost: model.cost,\n\t\t\tinput: model.input,\n\t\t\t...(model.fastRoute ? { fastRouteOf: `${model.provider}/${model.fastRoute.baseModelId}` } : {}),\n\t\t});\n\t\t// A caller that lists models (`allowedModels`) chooses the contenders itself,\n\t\t// but price and recency still compare them with every model the user could route to.\n\t\tconst callerListed = constraints.some((constraint) => (constraint.allowedModels?.length ?? 0) > 0);\n\t\tconst reference = callerListed\n\t\t\t? ctx.modelRegistry\n\t\t\t\t\t.getAvailable()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(model) =>\n\t\t\t\t\t\t\tisModelType(model, \"chat\") &&\n\t\t\t\t\t\t\tproviderPermitted(model.provider) &&\n\t\t\t\t\t\t\t(!needs.needsImages || model.input.includes(\"image\")),\n\t\t\t\t\t)\n\t\t\t: usable.map((entry) => entry.model);\n\t\tconst standings = rankCandidates(catalogEvals, reference.map(toCandidate), needs);\n\t\tconst ranked = standings.filter((candidate) => pairsFor.has(candidate.model));\n\t\tconst choiceState = {\n\t\t\tagent,\n\t\t\tneeds: {\n\t\t\t\twork: needs.work,\n\t\t\t\tdifficulty: needs.difficulty,\n\t\t\t\tmistake_cost: needs.mistakeCost,\n\t\t\t\tneeds_images: needs.needsImages,\n\t\t\t\tlong_context: needs.longContext,\n\t\t\t\tlatency_sensitive: needs.latencySensitive,\n\t\t\t},\n\t\t};\n\t\tconst describeAll = (options: readonly RankedCandidate[]) =>\n\t\t\tObject.fromEntries(options.map((option, index) => [`m${index}`, describeOption(option, needs, standings)]));\n\t\tconst fitsOneChoice = (options: readonly RankedCandidate[]) =>\n\t\t\toptions.length <= MAX_CHOICE_OPTIONS &&\n\t\t\tBuffer.byteLength(\n\t\t\t\tJSON.stringify({ state: choiceState, instructions: CHOICE_INSTRUCTIONS, criteria: describeAll(options) }),\n\t\t\t\t\"utf8\",\n\t\t\t) <= ROUTING_REQUEST_BYTES;\n\t\t// A caller's list is offered whole when it fits one choice request; otherwise\n\t\t// duplicate routes of one model share a slot, and a list that still does not\n\t\t// fit falls back rather than silently dropping a contender.\n\t\tconst callerChoices = !callerListed || fitsOneChoice(ranked) ? ranked : distinctTop(ranked, ranked.length);\n\t\tif (callerListed && !fitsOneChoice(callerChoices))\n\t\t\tawait fallBackToCurrentModel(\n\t\t\t\t`Auto routing cannot compare ${callerChoices.length} different models from modelConstraints.allowedModels in one routing request. List fewer models.`,\n\t\t\t);\n\t\tconst shortlist = callerListed ? callerChoices : distinctTop(ranked, SHORTLIST_SIZE);\n\n\t\t// Step 3: the router picks one option; each carries its own evidence.\n\t\tlet chosen = shortlist[0]!;\n\t\tif (shortlist.length > 1) {\n\t\t\tconst keys = shortlist.map((_, index) => `m${index}`);\n\t\t\tconst schema = Type.Object(\n\t\t\t\t{ modelId: Type.String({ enum: shortlist.map((option) => option.model) }) },\n\t\t\t\t{ additionalProperties: false },\n\t\t\t);\n\t\t\tconst result = await infer(() =>\n\t\t\t\trouteModel(\n\t\t\t\t\t{\n\t\t\t\t\t\tsettings,\n\t\t\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t\t\tcurrentModel: ctx.model,\n\t\t\t\t\t\tstate: {\n\t\t\t\t\t\t\t...choiceState,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinstructions: CHOICE_INSTRUCTIONS,\n\t\t\t\t\t\tschema,\n\t\t\t\t\t\tclassifier: {\n\t\t\t\t\t\t\tquestions: {\n\t\t\t\t\t\t\t\tmodel: {\n\t\t\t\t\t\t\t\t\tinstructions: \"Which model should do this task?\",\n\t\t\t\t\t\t\t\t\tcriteria: describeAll(shortlist),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tdecode: (choices) => {\n\t\t\t\t\t\t\t\tconst option = shortlist[keys.indexOf(choices.model ?? \"\")];\n\t\t\t\t\t\t\t\tif (!option) throw new Error(\"Invalid execution model Choice.\");\n\t\t\t\t\t\t\t\treturn { modelId: option.model };\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t},\n\t\t\t\t\t(value) => shortlist.some((option) => option.model === value.modelId),\n\t\t\t\t),\n\t\t\t);\n\t\t\tchosen = shortlist.find((option) => option.model === result.value.modelId)!;\n\t\t}\n\n\t\t// Step 4: effort from difficulty; fallbacks are the next distinct models in code's ranking.\n\t\tconst effortOf = (model: string) =>\n\t\t\teffortForDifficulty(\n\t\t\t\t(pairsFor.get(model) ?? []).map((pair) => pair.effort),\n\t\t\t\tneeds.difficulty,\n\t\t\t\tneeds.latencySensitive,\n\t\t\t);\n\t\tconst fallbackModels = distinctTop(\n\t\t\tranked.filter((candidate) => candidate.baseKey !== chosen.baseKey),\n\t\t\t2,\n\t\t);\n\t\treportModelRoutingDebug(\n\t\t\t`Auto routing: ${needs.work}, ${needs.difficulty}, mistake cost ${needs.mistakeCost}, images ${needs.needsImages ? \"yes\" : \"no\"}, long context ${needs.longContext ? \"yes\" : \"no\"}, latency ${needs.latencySensitive ? \"sensitive\" : \"tolerant\"}; chose ${chosen.model} from ${shortlist.map((option) => option.model).join(\", \")}.`,\n\t\t);\n\t\tselection = {\n\t\t\tmodel: chosen.model,\n\t\t\teffort: effortOf(chosen.model),\n\t\t\t...(fallbackModels.length\n\t\t\t\t? {\n\t\t\t\t\t\tfallbacks: fallbackModels.map((candidate) => ({\n\t\t\t\t\t\t\tmodel: candidate.model,\n\t\t\t\t\t\t\teffort: effortOf(candidate.model),\n\t\t\t\t\t\t})),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t};\n\t}\n\tconst fallbacks = selection.fallbacks?.map((pair) => Object.freeze({ model: pair.model, effort: pair.effort }));\n\tif (\n\t\tfallbacks &&\n\t\t(fallbacks.length > 2 ||\n\t\t\tnew Set([selection.model, ...fallbacks.map((pair) => pair.model)]).size !== fallbacks.length + 1)\n\t)\n\t\tthrow new Error(\"Invalid ranked auto selection: expected up to three distinct models.\");\n\tconst routerSelection = Object.freeze({\n\t\tmodel: selection.model,\n\t\teffort: selection.effort,\n\t\t...(fallbacks?.length ? { fallbacks: Object.freeze(fallbacks) } : {}),\n\t});\n\tconst hasPair = (pair: ModelRouterOutput) =>\n\t\tcatalog().some((entry) => entry.pairs.some((p) => p.model === pair.model && p.effort === pair.effort));\n\tconst allowsModel = (model: Model<Api>, effort?: string): boolean => {\n\t\tconst levels = model.reasoning ? getSupportedThinkingLevels(model) : [null];\n\t\treturn levels.some((level) => {\n\t\t\tif (model.reasoning && effort !== undefined && level !== effort) return false;\n\t\t\tconst pair = { model: `${model.provider}/${model.id}`, effort: level };\n\t\t\treturn eligiblePair(model, pair, constraints) && hasPair(pair);\n\t\t});\n\t};\n\tconst assertCurrent = () => {\n\t\tsignal?.throwIfAborted();\n\t\tif (![routerSelection, ...(routerSelection.fallbacks ?? [])].every(hasPair))\n\t\t\tthrow new Error(\"Auto selection is no longer eligible. Retry explicitly with the current catalog.\");\n\t};\n\tassertCurrent();\n\treturn {\n\t\trouterSelection,\n\t\tmodelOverride: routerSelection.model + (routerSelection.effort === null ? \"\" : `:${routerSelection.effort}`),\n\t\tfallbackModels: Object.freeze(\n\t\t\t(routerSelection.fallbacks ?? []).map((pair) => pair.model + (pair.effort === null ? \"\" : `:${pair.effort}`)),\n\t\t),\n\t\tassertCurrent,\n\t\tallowsModel,\n\t};\n}\n"]}
|
|
@@ -26,9 +26,10 @@ export interface RankedCandidate extends CandidateModel {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Rank every eligible model for the task in code. Quality is the model's
|
|
29
|
-
* standing
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* standing among every benchmarked model in the catalog on the benchmarks for
|
|
30
|
+
* this kind of work (overall intelligence when it has none), so it does not
|
|
31
|
+
* depend on which other models are eligible. It is weighed against price by how
|
|
32
|
+
* demanding the task is, with a small preference for newer releases.
|
|
32
33
|
*/
|
|
33
34
|
export declare function rankCandidates(catalog: EvalsCatalog, candidates: readonly CandidateModel[], needs: ResolvedTaskNeeds): RankedCandidate[];
|
|
34
35
|
/** The best `size` candidates with at most one per base model. */
|
|
@@ -36,7 +37,7 @@ export declare function distinctTop(ranked: readonly RankedCandidate[], size: nu
|
|
|
36
37
|
/**
|
|
37
38
|
* One shortlisted option described with its own evidence, so the router compares
|
|
38
39
|
* options directly: release date, price tier, image input, and results for this
|
|
39
|
-
* kind of work and overall, with standings
|
|
40
|
+
* kind of work and overall, with standings among catalog models measured on the same benchmark by the same source.
|
|
40
41
|
*/
|
|
41
42
|
export declare function describeOption(option: RankedCandidate, needs: ResolvedTaskNeeds, eligible: readonly RankedCandidate[]): string;
|
|
42
43
|
//# sourceMappingURL=model-routing-candidates.d.ts.map
|