@e2e-dev/decision 0.2.1 → 0.2.2-nightly-20261014080557
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/README.md +3 -1
- package/dist/.build.json +1 -1
- package/dist/decide.js +15 -5
- package/dist/types.d.ts +3 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,7 +4,9 @@ Run `agent.act` and `agent.assert` through a decision model instead of an
|
|
|
4
4
|
LLM. Any AI SDK decision model that answers `choice` questions with
|
|
5
5
|
probability distributions works, such as TypeSafe Jev or OpenAI `gpt-6-luna`
|
|
6
6
|
through `@ai-sdk/openai` 4.0.90 or later. A small language model writes
|
|
7
|
-
field values and upload paths. Needs `ai` 7.0.134 or later.
|
|
7
|
+
field values and upload paths. Needs `ai` 7.0.134 or later. An answer with
|
|
8
|
+
no distribution, as a gateway fallback to a language model returns, counts
|
|
9
|
+
as a committed choice with probability 1 and confidence 0.
|
|
8
10
|
|
|
9
11
|
```ts
|
|
10
12
|
import type { E2EConfig } from 'e2e';
|
package/dist/.build.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.2.
|
|
1
|
+
{"version":"0.2.2-nightly-20261014080557"}
|
package/dist/decide.js
CHANGED
|
@@ -61,16 +61,23 @@ export async function decide(ctx, model, request, providerOptions) {
|
|
|
61
61
|
}
|
|
62
62
|
return decisions;
|
|
63
63
|
}
|
|
64
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* The chosen option and its probability. An answer with no distribution,
|
|
66
|
+
* as a language model answering through a gateway fallback returns, is a
|
|
67
|
+
* committed choice: all the mass on it, and no confidence to report.
|
|
68
|
+
* Anything else without a valid distribution is MODEL_OUTPUT_INVALID.
|
|
69
|
+
*/
|
|
65
70
|
function selected(answer) {
|
|
66
|
-
if (answer === undefined ||
|
|
67
|
-
throw new AgentError('MODEL_OUTPUT_INVALID', 'The decision model returned
|
|
71
|
+
if (answer === undefined || (answer.type !== 'choice' && answer.type !== 'score')) {
|
|
72
|
+
throw new AgentError('MODEL_OUTPUT_INVALID', 'The decision model returned no choice or score answer.');
|
|
68
73
|
}
|
|
69
74
|
if (answer.type === 'score') {
|
|
70
75
|
const score = answer.score;
|
|
71
76
|
if (typeof score !== 'number' || !Number.isFinite(score)) {
|
|
72
77
|
throw new AgentError('MODEL_OUTPUT_INVALID', 'The decision model returned a score answer without a score.');
|
|
73
78
|
}
|
|
79
|
+
if (answer.probabilities === undefined)
|
|
80
|
+
return { choice: String(score), probability: 1, score };
|
|
74
81
|
let top = { choice: '', probability: -1 };
|
|
75
82
|
let nearby = 0;
|
|
76
83
|
for (const [level, probability] of Object.entries(answer.probabilities)) {
|
|
@@ -81,11 +88,14 @@ function selected(answer) {
|
|
|
81
88
|
}
|
|
82
89
|
return { choice: top.choice, probability: Math.min(1, nearby), score };
|
|
83
90
|
}
|
|
84
|
-
const
|
|
91
|
+
const choice = answer.choice ?? '';
|
|
92
|
+
if (answer.probabilities === undefined)
|
|
93
|
+
return { choice, probability: 1 };
|
|
94
|
+
const probability = answer.probabilities[choice] ?? 0;
|
|
85
95
|
if (!Number.isFinite(probability) || probability < 0 || probability > 1) {
|
|
86
96
|
throw new AgentError('MODEL_OUTPUT_INVALID', 'The decision model returned a probability outside [0, 1].');
|
|
87
97
|
}
|
|
88
|
-
return { choice
|
|
98
|
+
return { choice, probability };
|
|
89
99
|
}
|
|
90
100
|
/** Provider-reported confidence for one question, or 0 when absent. */
|
|
91
101
|
function reportedConfidence(metadata, id) {
|
package/dist/types.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ export interface DecisionExecutorOptions {
|
|
|
4
4
|
/**
|
|
5
5
|
* An AI SDK decision model that answers `choice` questions with a
|
|
6
6
|
* probability distribution, e.g. `typeSafeAi.decisionModel('jev-latest')`.
|
|
7
|
-
* Evaluation models (`evaluationModel()`) work too.
|
|
8
|
-
*
|
|
7
|
+
* Evaluation models (`evaluationModel()`) work too. An answer without
|
|
8
|
+
* `probabilities`, as a language model reached through a gateway fallback
|
|
9
|
+
* returns, counts as a committed choice: probability 1, confidence 0.
|
|
9
10
|
*/
|
|
10
11
|
readonly model: Exclude<Experimental_DecisionModel, string>;
|
|
11
12
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e2e-dev/decision",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2-nightly-20261014080557",
|
|
4
4
|
"description": "Decision-model executors for e2e",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"ai": "^7.0.134",
|
|
33
|
-
"e2e": "
|
|
33
|
+
"e2e": "0.21.0-nightly-20261014080557"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@ai-sdk/openai": "4.0.90",
|
|
37
37
|
"@ai-sdk/typesafe-ai": "3.0.16",
|
|
38
|
-
"@e2e-dev/web": "0.14.
|
|
38
|
+
"@e2e-dev/web": "0.14.1-nightly-20261014080557",
|
|
39
39
|
"@types/node": "26.6.2",
|
|
40
40
|
"@types/pngjs": "6.0.5",
|
|
41
41
|
"ai": "7.0.134",
|
|
42
42
|
"ajv": "8.20.0",
|
|
43
43
|
"ajv-formats": "3.0.1",
|
|
44
|
-
"e2e": "0.
|
|
44
|
+
"e2e": "0.21.0-nightly-20261014080557",
|
|
45
45
|
"typescript": "7.0.2",
|
|
46
46
|
"vitest": "5.0.1"
|
|
47
47
|
},
|