feat(decision): act and assert through an AI SDK decision model
Merged
GU
2mo ago+2741+2741+0123456789012345678901234567890123456789-8-8-0123456789
Adds @e2e-dev/decision, an executor that runs agent.act and agent.assert through an AI SDK decision model instead of an LLM. The decision model picks the next action from choices the executor builds out of the latest semantic tree; a small language model writes field text only when the choice is type. The runner still authorizes, budgets, and records every dispatch.
import { decisionExecutor } from '@e2e-dev/decision';
import { typeSafeAi } from '@ai-sdk/typesafe-ai';
import { openrouter } from '@openrouter/ai-sdk-provider';
export default {
agents: {
default: {
executor: decisionExecutor({
model: typeSafeAi.evaluationModel('jev-latest'),
textModel: openrouter('inception/mercury-2.5'),
}),
},
},
} satisfies E2EConfig;
Tests stay plain natural language, with no params:
await agent.act('add two todos, Buy milk and Walk the dog, then mark Buy milk as done');
flowchart LR
O[observe tree] --> T[element table]
T --> E["one experimental_evaluate call:<br/>operation + one target question per operation"]
E -->|tap / check / select / submit / scroll / back| A[ctx.actions]
E -->|type| X[text model writes the value] --> A
E -->|done / failed| V[verdict on a fresh screen]
A --> O
V -->|confirmed| R[step verdict]
V -->|rejected| O
- One
experimental_evaluatecall per action, with the target questions fanned out in the same request. An operation with one target dispatches without a target question. Every SDK call lives inpackages/decision/src/evaluate.ts, so theexperimental_deciderename in vercel/ai#21935 is a one-file change. - Targets are element indexes from
packages/decision/src/elements.ts: role rules per operation, viewport first, 255 choices per question, page text and the change fingerprint built from the tree without node ids. Model output never becomes a selector, URL, or key. doneandfailedgo through one verdict question on a fresh screen that sees the step's action descriptions and no model reasoning. The second unconfirmed claim ends the step by the check:fails→ACTION_FAILED, anything else →blocked.- Action errors go back to the model as history, matching the built-in loop; only
STEP_BUDGET_EXHAUSTED,STEP_TIMEOUT, andCANCELLEDpropagate. Three actions with no page change block the step. minProbabilityandminConfidenceare off by default; under a gate they cover operations, targets, secrets, completion checks, and assertions.- Secrets stay declared handles: secret projections are stripped from params at any depth, password fields get only
typeSecret, and a secret name appears only in thesecretquestion's criteria. cache: 'inherit': replays record typed values, andctx.replayedPrefixseeds the history.aiis a required peer. No vendor transports, no vision, nonavigate, no new error codes. Limits are indocs/decision-models.mdx.
Benchmark
Testbed todo flow written in plain language (above), 5 --no-cache runs each on one M1 Mac. Both configurations finished every run.
| Executor | Models | Completed | Wall / run, mean (range) | Model calls / run | Tokens / run | Cost / run |
|---|---|---|---|---|---|---|
| built-in agent | gpt-6-luna | 5/5 | 17.3s (13.6–20.6) | 6 | 26.8k in (29–70% cached), 0.17k out | $0.0016 |
decisionExecutor | Jev 1.13 decides, gpt-6-luna writes field text | 5/5 | 10.8s (9.5–12.6) | 9 (7 Jev + 2 text) | 17.2k Jev + 0.4k luna in | $0.0008 |
- The decision executor took the same path on all five runs: type "Buy milk", tap Add, type "Walk the dog", tap Add, check "Buy milk",
done, confirmed by the verdict. The built-in agent also finished every run, with more latency spread. - Where the 10.8s goes: 7 Jev calls at 0.42s each (about 3s), 2 text calls at 2.3s each (about 4.7s), the rest is the browser. A faster text model is the main lever.
- Costs: Jev from the
usage.costthe gateway returned on each call ($0.042/M input, output unbilled), $0.0036 for all 35 calls. Luna at $0.10/M input, $0.01/M cached, $0.50/M output. - Jev ran through Merge's System One gateway (
api-gateway.merge.dev/v1/decisions, modeltypesafe/jev-1.13), not TypeSafe's API, since I have no TypeSafe credits. That gateway accepts structuredstatebut only string instructions and criteria, so the bench adapter below stringifies those two fields. - Luna is the text model because it was the only model reachable here that returned structured output; a smaller one such as Mercury should cut the text-call share.
- The configs are not committed (they need third-party keys).
Bench adapter and configs
// apps/testbed/e2e.bench-decision.config.ts (local only)
const flat = (value: unknown): string => (typeof value === 'string' ? value : JSON.stringify(value));
const jev = {
specificationVersion: 'v4' as const,
provider: 'typesafe',
modelId: 'typesafe/jev-1.13',
supportedQuestionTypes: ['choice' as const],
async doEvaluate({ state, questions, abortSignal }) {
const flatQuestions = Object.fromEntries(Object.entries(questions).map(([id, q]) => [id, {
type: q.type,
instructions: flat(q.instructions),
criteria: Object.fromEntries(Object.entries(q.criteria).map(([k, v]) => [k, flat(v ?? '')])),
}]));
const response = await fetch('https://api-gateway.merge.dev/v1/decisions', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.MERGE_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ model: 'typesafe/jev-1.13', state, questions: flatQuestions }),
signal: abortSignal,
});
if (!response.ok) throw new Error(`decision gateway HTTP ${response.status}`);
const body = await response.json();
const answers = {};
const confidence = {};
for (const [id, a] of Object.entries(body.answers)) {
answers[id] = { type: 'choice', choice: a.choice, probabilities: a.probabilities };
confidence[id] = a.confidence;
}
return {
answers,
rounding: { probabilityDecimals: 2 },
usage: { inputTokens: body.usage.input_tokens, outputTokens: body.usage.output_tokens },
warnings: [],
providerMetadata: { typesafe: { confidence } },
response: { modelId: body.model },
};
},
};
// agents.default: { executor: decisionExecutor({ model: jev, textModel: opencodex('gpt-6-luna') }), context }
// baseline: { model: opencodex('gpt-6-luna'), maxSteps: 40, maxModelCalls: 60, context }
node node_modules/e2e/dist/cli/bin.js run --config e2e.bench-decision.config.ts tests-bench/todo-plain.e2e.ts --workers 1 --no-cache --repeat-each 5
node node_modules/e2e/dist/cli/bin.js run --config e2e.bench-agent.config.ts tests-bench/todo-plain.e2e.ts --workers 1 --no-cache --repeat-each 5
Verified
Ran it locally: yes
- Live on a1c14b75 with Jev on the web benchmark: the control-inventory footnote scroll passes 2/2 (blocked after 3 scrolls before the fingerprint fix). infinite-scroll, virtualized-table, and sticky-chrome still block after 3 scrolls: they scroll an inner
overflow: autocontainer, and the executor only scrolls the window (see the PR conversation). - Live on 333c9c60 with Jev and luna, 3
--no-cacheruns each: workspace wizard 3/3, secret login 3/3, plain-language todo flow 3/3. On a188c6cc the wizard and the login both ended blocked with the completion check inconclusive, which the review on this PR reported. - Live, the benchmark above against the testbed app on real Chromium: 5/5 for each configuration. CLI output for the decision runs:
✓ plain-language todo flow 10.59s ai 19.6k tokens
✓ plain-language todo flow (repeat #1) 12.58s ai 19.6k tokens
✓ plain-language todo flow (repeat #2) 10.17s ai 19.6k tokens
✓ plain-language todo flow (repeat #3) 9.53s ai 19.6k tokens
✓ plain-language todo flow (repeat #4) 10.95s ai 19.6k tokens
AI 98.0k tokens · 45 model calls · typesafe/jev-1.13.0
Repeats 1 of 1 test passed all 5 runs
packages/decision/tests/cli.test.tsruns the built CLI on real Chromium with a scripted evaluation model: the todo flow in plain language, a secret login whose password never appears in a model request or artifact, a page past the 255-choice cap that still completes, and the operation and target questions fanned out in one call.- Not run: TypeSafe's own API (no credits), and the mobile workflow (no simulator and emulator here; this PR touches no mobile package).