> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Decision models

> Run agent.act and agent.assert through a decision model and a small text model with @e2e-dev/decision, in place of a full LLM agent.

`@e2e-dev/decision` runs `agent.act` and `agent.assert` through a decision
model instead of an LLM agent. For each action, the decision model picks an
operation, then an element, from the goal, the recent actions, and the
newest semantic tree. It never writes free text: a small text model writes
field values. The runner still authorizes every action.

Any AI SDK decision model that answers `choice` questions with probabilities
works, such as TypeSafe Jev or OpenAI `gpt-6-luna` (including
`evaluationModel()` instances). Passing a plain string or a standard
language model fails config validation.

The same package's `decisionFilter()` runs only the tests a pull request can
affect. See [Test filters](https://e2e.com/docs/filters).

## Install and configure

Install the package, a decision model provider, and a text model provider.
Decision models need `ai` 7.0.134 or later.

<CodeGroup>
```bash npm
npm install -D @e2e-dev/decision @ai-sdk/typesafe-ai @openrouter/ai-sdk-provider
```

```bash pnpm
pnpm add -D @e2e-dev/decision @ai-sdk/typesafe-ai @openrouter/ai-sdk-provider
```

```bash bun
bun add -d @e2e-dev/decision @ai-sdk/typesafe-ai @openrouter/ai-sdk-provider
```
</CodeGroup>

Set the executor on the agents entry:

```ts title="e2e.config.ts"

export default {
  targets: [{ engine: web(), app: { url: 'http://localhost:3000' } }],
  agents: {
    default: {
      executor: decisionExecutor({
        model: typeSafeAi.decisionModel('jev-latest'),
        textModel: openrouter('inception/mercury-2.5'),
      }),
    },
  },
} satisfies E2EConfig;
```

Tests are plain `agent.act` and `agent.assert` calls:

```ts title="tests/todos.e2e.ts"

test('adds a todo', async ({ app, screen, agent }) => {
  await app.open('/todos');
  await agent.act('Add a todo named Buy coffee.');
  await expect(screen.getByTestId('todo')).toContainText('Buy coffee');
  await agent.assert('The todo list contains Buy coffee.');
});
```

<Accordion title="Use OpenAI gpt-6-luna">

Use `@ai-sdk/openai` 4.0.90 or later, which accepts the
[vision](#vision) screenshot. Set `OPENAI_API_KEY`.

<CodeGroup>
```bash npm
npm install -D @ai-sdk/openai
```

```bash pnpm
pnpm add -D @ai-sdk/openai
```

```bash bun
bun add -d @ai-sdk/openai
```
</CodeGroup>

```ts title="e2e.config.ts"

const executor = decisionExecutor({
  model: openai.decisionModel('gpt-6-luna'),
  textModel: openai('gpt-6-luna-fast'),
  vision: true,
});
```

</Accordion>

## What the model can do

Each turn offers the operations the engine supports on the elements of the
newest screen: `tap`, `type`, `typeSecret`, `submit`, `select`, `check`,
`upload`, `hover`, `secondary_tap` (a right-click), `double_tap`,
`long_press`, `drag`, `scroll_to`, `scroll_up`, `scroll_down`, and `back`.
Hover, right-click, drag, and scroll-to also reach labeled nodes that are
not controls, such as a card that opens a menu on hover, and a drag can drop
onto any of them. `tap` also reaches text fields, to open a date picker or a
suggestion list. While an on-screen
keyboard shows on an engine that can dismiss it, such as the mobile engine,
the executor also offers `dismiss_keyboard`, even when the keyboard is
missing from the tree.

Every operation that acts on an element asks for its target, even when only
one element fits it.
Every target question has a `none` option, so a provider with no fitting
target answers `none` instead of refusing. `none` blocks the step.

## How text gets typed

When the decision model picks `type`, the text model writes the value from
the goal, the params, the field's label, and the page text. The executor
types exactly that string. With no value in the goal, it types nothing and
the decision model picks again. For `upload`, the text model lists the
project-relative paths the goal or params name, and the runner authorizes
each one. Model output never becomes a selector, a URL, or a key.

Password fields never reach the text model, unless a page script hides one
from e2e. Then the text model sees its value, and `type` can fill it
([where redaction stops](https://e2e.com/docs/reference/security#where-redaction-stops)).
Only `typeSecret` fills a configured secret, from its declared handle.

The text model also answers `waitFor` and `extract`. Instead of
`textModel`, you can set `model` on the agents entry. With neither, the
executor never offers `type`, `upload`, `tap_at`, or `type_at`.

## Finishing a step

When the decision model says `done` or `failed`, the executor double-checks
on a fresh screen whether the task is actually complete (without seeing
model reasoning or secrets). Confirmed results finish the step; an
unconfirmed claim goes back to the model once before failing or blocking the
step.

## Gates

Both gates are off by default, so the executor follows the most probable
choice. Set `minProbability` or `minConfidence` to block weaker actions,
reject weaker completion checks, and fail weaker assertions as
inconclusive:

```ts title="Executor setup"
const executor = decisionExecutor({ model, minProbability: 0.9, minConfidence: 0.8 });
```

Probability is the chosen option's share of the answer distribution.
Confidence is the provider's own statistic, 0 when it reports none. OpenAI
rounds both to two decimals. Measure accuracy on your own tests before you
set a threshold.

## Vision

`vision: true` adds a masked screenshot to every observation. Assertions and
completion checks see it, so the model can judge drawn content the tree
doesn't show. The operation and target questions read the tree only.
`agent.assert(..., { vision: true })` and `vision: 'only'` work too.

The model must accept images and answer `score` questions. TypeSafe Jev
does with `@ai-sdk/typesafe-ai` 3.0.19 or later and a TypeSafe API key in
`TYPESAFE_AI_API_KEY`:

```ts title="e2e.config.ts"

const executor = decisionExecutor({
  model: typeSafeAi.decisionModel('jev-latest'),
  textModel: openrouter('inception/mercury-2.5'),
  vision: true,
});
```

`openai.decisionModel('gpt-6-luna')` takes images too. Vercel AI Gateway
rejects the screenshot for every decision model, so keep `vision` off
there.

With a text model, vision also offers `tap_at` for a control the tree
doesn't list. The text model names the control, such as "the 3 key on the
keypad", and the decision model finds it on the screenshot, then on two
zoomed crops. A point tap costs four decide calls and one text call, or one
of each to repeat a tap on the same page.

When the engine can type into whatever has focus, vision also offers
`type_at` for a drawn field. The text model names the field and the value
from the goal, the decision model finds the field on the screenshot, and
the executor taps it and types the value at the caret, after any text
already there. It costs two decide calls and one text call.

## Provider options

The executor's `providerOptions` go with every decide call, completion
checks included, and reach the decision model only. Use them for options
such as zero data retention on Vercel AI Gateway:

```ts title="Executor setup"

const executor = decisionExecutor({
  model: gateway.decisionModel('typesafe-ai/jev'),
  textModel: gateway('openai/gpt-6-luna-fast'),
  providerOptions: { gateway: { zeroDataRetention: true } },
});
```

The text model takes the agents entry's `providerOptions`, so a setting
for one model, such as a gateway fallback list, never reaches the other.

AI Gateway can rerun an uncertain decision on another model. Add the
conditional entry to `gateway.models`; it reaches every decide call, and a
triggered fallback bills both models:

```ts title="Executor setup"
const executor = decisionExecutor({
  model: gateway.decisionModel('typesafe-ai/jev'),
  textModel: gateway('openai/gpt-6-luna-fast'),
  providerOptions: {
    gateway: { models: [{ model: 'openai/gpt-6-luna-decisions', when: { confidenceBelow: 0.6 } }] },
  },
});
```

A decision model fallback keeps the gates: the executor reads the fallback
model's probabilities and confidence. A language model fallback, such as
`openai/gpt-6-luna-fast`, answers with a choice and no distribution. The
executor takes that choice with probability 1 and confidence 0, so a
`minConfidence` gate blocks every escalated answer.

## Limits

- No `navigate` tool: click links in-app, and put URLs in test code
  (`app.open`, `browser.goto`).
- No multi-select `listbox` or `scrollUntil`, and `type_at` never clears a
  drawn field first (it suits empty fields).
- The text model doesn't see screenshots, so it can't read instructions that
  only exist as drawn pixels (like a canvas prompt).
- Every decision call and text call counts toward `maxModelCalls`.
- Three consecutive actions that fail or change nothing block the step.
- Each question is capped at 255 options (TypeSafe's limit); on huge pages,
  visible elements come first so the model can scroll to reach the rest.

## Next

<CardGroup cols={2}>
  <Card title="Custom executors" icon="gears" href="/executors">
    How an executor plugs into the runner.
  </Card>
  <Card title="Models" icon="brain" href="/models">
    Use an LLM agent with tool calls instead.
  </Card>
</CardGroup>
