> ## 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.

# agent

> API reference for the agent fixture, with agent.act, agent.assert, agent.waitFor, and agent.extract, their budgets, action tools, and vision.

The `agent` fixture runs natural-language steps against the app: `act`
interacts with it, `assert` checks the current screen, `waitFor` waits for a
condition, and `extract` reads structured data. Each call has its own timeout
and model-call budget.

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

test('invite a teammate', async ({ agent }) => {
  await agent.act('invite {email} as an editor', { params: { email: 'ada@example.test' } });
  await agent.waitFor('the members list shows ada@example.test');
  await agent.assert('ada@example.test is listed as an editor');
});
```

The built-in agent needs a configured model. Without one, the first use of
the `agent` fixture stops the run with `MODEL_UNAVAILABLE` (exit 2).
[Custom executors](https://e2e.com/docs/executors) can run `act` and
`assert` without a model; `waitFor` and `extract` still need one unless
the executor [answers them itself](https://e2e.com/docs/executors#what-the-executor-handles).

## Reference

| Method | Returns |
| --- | --- |
| [`agent.act`](#agent-act) | `Promise<ActResult>` |
| [`agent.assert`](#agent-assert) | `Promise<void>` |
| [`agent.waitFor`](#agent-waitfor) | `Promise<void>` |
| [`agent.extract`](#agent-extract) | `Promise<InferOutput<Schema>>` |

[Types](#types) holds the signatures. [Budgets](#budgets) lists each
method's default timeout, model calls, and action steps. Every method takes
`agent`: the name of a configured agent (`agents.<name>`) that runs that one
call in place of the test's.

### agent.act

Plans and executes one bounded multi-action flow. A passing verdict resolves
with an `ActResult`. A failing or blocked one throws an
[`AgentError`](#agenterror) whose `code` and `blocked` flag say why.

```ts
await agent.act('invite {email} as an editor', { params: { email: 'ada@example.test' } });

const member = credentials.user('member');
const { summary, cache } = await agent.act('Sign in', {
  params: { username: member.username, password: member.password },
});
```

- `instruction` is 1 through 8192 UTF-8 bytes after NFC normalization.
- The [`ActResult`](#types) carries the step's `summary`, the `modelCalls`
  and `actions` it spent, and `cache`: how the [replay cache](https://e2e.com/docs/cache) took
  part. `summary` is the replay's when the cache finished the step, and
  `modelCalls` is then 0. `actions` counts grammar actions and mutating
  tool calls. `cache` is absent when caching is off for the step.
- The agent acts through the [action tools](#action-tools) and requests
  screenshots itself through the
  [pixel tools](#pixel-tools-screenshot-and-the-point-verbs).

| Option | Type | Default |
| --- | --- | --- |
| `params` | `AgentParams` | none |
| `timeout` | `number` | `config.timeout`, 120000 |
| `maxSteps` | `number` | `agents.<name>.maxSteps`, 25 |
| `maxModelCalls` | `number` | `agents.<name>.maxModelCalls`, 25 |
| `agent` | `string` | the test's agent |
| `onAction` | [`ActionHook`](#types) | none |
| `onBeforeAction` | [`BeforeActionHook`](#types) | none |

`params` values come from your code, never from the model. They are
JSON-safe, at most 64 KiB and 32 levels deep. Wrap a value that
differs on every run in [`unique()`](#unique). The model sees a `Secret` as
its name and purpose only. A `Secret` is filled only into an enabled editable
input, and a password only into a password field. `locator.fill` runs no such
check.

`onAction` runs after each action the step completes, once the screen
settles, and before the next action. That includes actions the
[replay cache](https://e2e.com/docs/cache) replays. The step waits for it, and its time counts
toward `timeout`. Use it to observe, never to drive the app. If it throws,
the step fails with a message that starts with `agent.act onAction failed`.
A check inside it never confirms the step's recording.

| Event field | Description |
| --- | --- |
| `index` | 1-based position in the step's action budget. A failed attempt uses a number too. |
| `action` | An [`ActionName`](#types), or `tool:<name>` for a mutating project tool. |
| `summary` | What the action did, secrets redacted. |
| `source` | `model` when the executor chose the action, `replay` when the cache replayed it. |

```ts
await agent.act('open settings and turn on dark mode', {
  onAction: ({ index, action }) => app.screenshot(`${index} ${action}`),
});
```

Narrow on `event.action` to read an action's details: `point` for `tapAt`
and `hoverAt`, `from` and `to` for `dragAt`. Points are in the same space as
`screen.tapAt` and `boundingBox()`, rounded and clamped to the viewport.
Replay reports the points it dispatches on the current screen. Mobile
engines have no `hoverAt` or `dragAt`.

```ts
await agent.act('move the pin to Warsaw', {
  onAction: (event) => {
    if (event.action === 'dragAt') console.log(event.from, event.to);
  },
});
```

`onBeforeAction` runs before each action, replayed ones included, with the
same `index` and `source` that action's `onAction` gets. Use it to capture the screen an
action started on. The step waits for it, and it does not wait for the screen
to settle first. If it throws, the step fails before the action runs, with a
message that starts with `agent.act onBeforeAction failed`. An action can still
fail after it, with no `onAction` call.

```ts
await agent.act('open settings and turn on dark mode', {
  onBeforeAction: ({ index }) => app.screenshot(`before ${index}`),
});
```

A failed verdict is `ACTION_FAILED` unless the executor names a more specific
code, such as `LOCATOR_NOT_FOUND` or `AUTHENTICATION_FAILED`. A blocked
verdict means the step could not reach a product verdict. It carries one of
these codes:

| Blocked on | Codes |
| --- | --- |
| credentials | `AUTH_CREDENTIAL_UNAVAILABLE`, `AUTH_CREDENTIAL_INVALID`, `SECRET_UNAVAILABLE` |
| environment | `ENVIRONMENT_UNAVAILABLE`, `APP_UNREACHABLE`, `APP_ALREADY_RUNNING` |
| seed data | `SEED_DATA_MISSING` |
| test setup | `TEST_SETUP_FAILED`, `APP_NOT_OPEN`, `POLICY_DENIED` |
| automation | `MODEL_UNAVAILABLE`, `AUTOMATION_UNSUPPORTED`, `STEP_BUDGET_EXHAUSTED`, `STEP_TIMEOUT`, `CONTEXT_OVERFLOW`, `MODEL_REFUSED` |

The runner's own stops, and the checks on the call itself:

| Throws | When |
| --- | --- |
| `STEP_BUDGET_EXHAUSTED`, `STEP_TIMEOUT` | A budget or the deadline ran out. |
| `CANCELLED` | The runner cancelled the step. |
| `STEP_NO_CONCLUSION` | The turns ran out without a conclusion. |
| `CONTEXT_OVERFLOW` | A request exceeded the model's context window. |
| `MODEL_REFUSED` | The model refused the request. |
| `MODEL_PROVIDER_FAILED` | The provider's transport failed after its retries. |
| `MODEL_OUTPUT_INVALID` | A verdict outside the grammar. |
| `REPLAY_STALE` | Under a strict cache, the step's recording no longer replays. |
| `INVALID_ARGUMENT` | A malformed instruction, oversized `params`, an unknown option, an `onAction` or `onBeforeAction` that is not a function, or a budget above the configured limit. An unknown `agent` name fails before the step opens. |
| `UNSUPPORTED_CAPABILITY` | `schema` or `vision`, which `act` does not take. |

### agent.assert

Checks one fresh observation without polling by default.

```ts
await agent.assert('the dashboard shows a trial badge');
await agent.assert('the table lists {name}', { params: { name } });
```

- The judge sees the assertion, its `params`, the current observation with
  its location, and the agent's `context`, never prior steps or `act` summaries. It answers `holds`,
  `fails`, or `inconclusive`.
- When the subject appears more than once, such as a total in a summary and
  on a pay button, every instance must agree: one that contradicts it fails.
  Name the place (`the order summary total is $42.00`) to judge only that one.
- A claim about some item, such as `a todo is marked done`, holds when one
  item matches.

| Option | Type | Default |
| --- | --- | --- |
| `explore` | `boolean` | `false` |
| `maxSteps` | `number`, requires `explore` | min(10, configured limit) |
| `maxModelCalls` | `number`, requires `explore` | min(6, configured limit) |
| `params` | `AgentParams` | none |
| `timeout` | `number` | `agents.<name>.judgmentTimeout`, 30000 |
| `screenshot` | `boolean` | `true` |
| `vision` | [`VisionMode`](#vision) | `false` |
| `agent` | `string` | the test's agent |

`screenshot` controls the redacted screenshot attached as evidence after the
judgment, passing or failing.
`vision` controls what the model is shown before it. No evidence is captured
with `screenshot: false`.

`params` follow the [`agent.act`](#agent-act) rules, and invalid ones throw
`INVALID_ARGUMENT`. A `Secret` param reaches the judge as its name, never its
value. To check that a secret's value is on screen, use a locator assertion.

| Throws | When |
| --- | --- |
| `ASSERTION_FAILED` | The judgment is false. |
| `ASSERTION_INCONCLUSIVE` | The screen did not show enough to decide. |

Both carry the explanation and, when permitted, a screenshot path. An
inconclusive judgment made from the tree alone adds a hint to its message to
pass `vision: true`, unless the engine declares no screenshot capture or an
earlier step's pixel request was degraded.

<Note>
A custom `StepExecutor` judges the assertion itself, and `assert` carries the
executor's explanation alone, with no vision hint. It honors `screenshot`,
since the runner takes that evidence after the verdict. It receives `vision`
as `step.vision` when it declares `vision: true`; otherwise `vision` is
`UNSUPPORTED_CAPABILITY`. Its budget and timeout are under
[Budgets](#budgets).
</Note>

#### Viewport exploration

With `explore: true`, `agent.assert` can scroll the current screen and combine
evidence from several viewports.

```ts
await agent.assert('Settings lists HOS Settings, Account, Language and Theme', {
  explore: true,
  maxSteps: 10,
  maxModelCalls: 6,
});
```

Exploration offers `observe`, `scroll`, `scroll_to`, and project tools declared
`mutates: false`. The built-in executor also offers `screenshot` when `vision`
is `true` or `'only'`; the default is tree-only. Other actions are rejected. The viewport stays
where exploration ends.

`maxSteps` and `maxModelCalls` may exceed their 10 and 6 defaults, up to the
selected agent's configured limits. Either one without `explore: true` throws
`INVALID_ARGUMENT`. The built-in executor uses `agents.<name>.model`, even
when `judge` is configured.

A contradiction is `ASSERTION_FAILED`; insufficient evidence within the time
or action/model budget is `ASSERTION_INCONCLUSIVE`.

Use `waitFor` for a condition that changes over time, and `explore` for content
elsewhere on the current screen.

### agent.waitFor

Polls a natural-language condition until a judgment holds.

```ts
await agent.waitFor('the upload progress reports completion', { interval: 500 }); // default: 3000
```

- It observes and judges at once, and succeeds on the first judgment that
  holds.
- After a false or inconclusive judgment it judges again only once the
  screen or its location differs from the one last judged, pixels included
  under `vision`. Under `vision: 'only'` a location change alone does not
  count.
- While the screen keeps changing (a progress counter, a clock), it judges
  at most once per `interval`.
- Judgments follow the [`agent.assert`](#agent-assert) rules: a value shown
  in more than one place holds only once every instance agrees.

| Option | Type | Default |
| --- | --- | --- |
| `params` | `AgentParams` | none |
| `timeout` | `number` | `agents.<name>.judgmentTimeout`, 30000 |
| `interval` | `number` | 3000 |
| `maxModelCalls` | `number` | `agents.<name>.maxModelCalls`, 25 |
| `vision` | [`VisionMode`](#vision) | `false` |
| `agent` | `string` | the test's agent |

`interval` is the least time between two judgments of a screen that keeps
changing, 100 through 60000 ms.
`params` work as in [`agent.assert`](#agent-assert).

| Throws | When |
| --- | --- |
| `STEP_TIMEOUT` | The deadline expired. |
| `STEP_BUDGET_EXHAUSTED` | The budget ran out. |
| `INVALID_ARGUMENT` | An out-of-range option, invalid `params`, or an option `waitFor` does not take. |

`STEP_TIMEOUT` and `STEP_BUDGET_EXHAUSTED` carry the last judgment. When that
round was inconclusive, they add the same vision hint as `agent.assert`.

### agent.extract

Reads structured output from one fresh observation, validates it against
`schema`, and returns the validated value. It performs no app actions.

```ts

const summary = await agent.extract('the workspace name and plan', {
  schema: z.object({ name: z.string(), plan: z.string() }),
});
```

- When the schema has a JSON Schema projection (zod does), the model receives
  its shape: types, fields, required fields, and allowed literals. It does
  not receive value rules such as `min`, `max`, lengths, patterns, and
  formats; your schema still checks them.
- The model can answer that the screen does not show the data. That throws
  `ASSERTION_INCONCLUSIVE` with what was missing, instead of returning a
  placeholder such as `""` or `0`. To accept absence as an answer, say so in
  the instruction and the schema (`'the phone number, or null when none is
  shown'` with `z.string().nullable()`).

| Option | Type | Default |
| --- | --- | --- |
| `schema` | `StandardSchemaV1` | required |
| `timeout` | `number` | `agents.<name>.judgmentTimeout`, 30000 |
| `vision` | [`VisionMode`](#vision) | `false` |
| `agent` | `string` | the test's agent |

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | The schema is not Standard Schema v1. |
| `ASSERTION_INCONCLUSIVE` | The screen does not show the data. |
| `MODEL_OUTPUT_INVALID` | Validation still fails after the repair round. |

## Budgets

Model calls count every model request, repair rounds included. Action steps
count committed engine actions. The remaining test timeout caps every
timeout.

| Method | Model calls | Action steps | Default timeout |
| --- | ---: | ---: | --- |
| `act` | `agents.<name>.maxModelCalls`, 25 | `agents.<name>.maxSteps`, 25 | `config.timeout`, 120000 ms |
| `waitFor` | `agents.<name>.maxModelCalls`, 25 | 0 | `agents.<name>.judgmentTimeout`, 30000 ms |
| `extract` | 2 | 0 | `agents.<name>.judgmentTimeout`, 30000 ms |
| `assert` without exploration | 2 | 0 | `agents.<name>.judgmentTimeout`, 30000 ms |
| `assert` with exploration | min(6, configured limit) | min(10, configured limit) | `agents.<name>.judgmentTimeout`, 30000 ms |

- `actionTimeout` limits engine operations, not model calls.
- Per-call budgets (`maxSteps`, `maxModelCalls`) can only lower the
  configured limits. They must be positive integers no larger than those
  limits; a larger one is `INVALID_ARGUMENT`.

Without exploration, the `assert` row describes the built-in agent. A custom
`executor` runs non-exploring assertions with the agent's `maxSteps` and
`maxModelCalls`, and `config.timeout` as the default deadline. Exploring
assertions use the capped defaults and `judgmentTimeout` with any executor.
For `vision` and `screenshot` there, see the Note under
[`agent.assert`](#agent-assert).

## Action tools

The built-in agent offers one tool per verb the target's engine declares, and
none for a verb it does not. A tool that targets a node takes its id from the
newest observation. Every tool returns what changed on screen and is
recorded for the [replay cache](https://e2e.com/docs/cache), with its node when it has one. On an engine that declares
`tapModifiers`, `tap`, `double_tap`, and `right_click` take `modifiers`
(`Shift`, `Control`, `Alt`, `Meta`, `ControlOrMeta`) to hold keys for the
click, as a Shift-click extends a selection.

| Tool | Engine action | What it does |
| --- | --- | --- |
| `tap({ target, modifiers? })` | `tap` | Taps or clicks one node: the gesture for a button, link, menu item, tab, checkbox, row, or field. |
| `double_tap({ target, modifiers? })` | `doubleTap` | Double-clicks one node, for an item that opens or enters editing on the second click. |
| `long_press({ target })` | `longPress` | Presses one node and holds, for a long-press menu or action. |
| `right_click({ target, modifiers? })` | `secondaryTap` | Right-clicks one node to open its context menu. |
| `hover({ target })` | `hover` | Moves the pointer over one node without pressing: hover menus, flyouts, tooltips, controls revealed on mouse-over. |
| `type({ target?, value, replace? })` | `fill`; without `target`, `keyboard` | Replaces the node's value; without a target, types into whatever has focus. |
| `type_secret({ target, name })` | `fill` | Fills a secret declared in the step's params. On a step that declares none, it fills nothing. |
| `press({ target?, key, times? })` | `press`; without `target`, `keyboard` | Sends one key to a node or to the focused control, up to 20 times in one call. Each press is one action; with a target, the first press addresses the node and the rest go to whatever has focus, so a repeated `Tab` walks on. |
| `select({ target, value })` | `selectOption` | Picks an option by its visible label. |
| `check({ target, checked? })` | `check` and `uncheck` | Sets a checkbox, switch, or radio to a state (`true` by default). A control already in that state is left alone, unlike a tap, which flips it. |
| `scroll({ direction, target?, times? })` | `swipe` | Scrolls the viewport or one scrollable node, up to 20 screens per call. |
| `scroll_to({ target })` or `scroll_to({ text, direction?, target? })` | `scrollIntoView`; with `text`, `swipe` | With `target` alone, brings one listed node into the viewport. With `text`, pages the list (`target`, or the viewport) in `direction` (down by default) until a node reading that text shows, for a row a long or windowed list has not rendered yet. The node's label must be the text, or hold it as whole words, so `Row 12` never stops at `Row 120`, and the node must be inside `target` when that names a list. One action however many screens, up to 800; a screen that stops moving or the cap is `LOCATOR_NOT_FOUND`. A list that appends when it reaches the end keeps being paged. Each form is offered only with its action kind. |
| `drag({ target, to })` | `dragTo` | Drags one node and drops it on another: reordering, kanban columns, drop zones. |
| `upload({ target, files })` | `setInputFiles` | Attaches files to a file input, or to a visible control that opens a native file chooser. Paths are project-relative or name a `sample:` file; see the policy below. |
| `navigate({ url })` | `session.open` | Opens a URL or an app-relative path. |
| `back()` | `session.back` | Goes back once: browser history on a page, the in-app back on a device. |
| `resize_viewport({ width, height })` | `session.resize` | Sets the viewport size in CSS pixels, 200 to 4096 per side, to check a layout at another width. The size holds until the next resize. Engines with `session.resize`, such as web. |
| `switch_tab({ tab })` | `session.switchTab` | Shows another open tab, numbered from 1 in the order the tabs opened. Engines with `session.switchTab`, such as web. |
| `close_tab({ tab })` | `session.closeTab` | Closes an open tab, numbered as `switch_tab` counts them. The last open tab stays open. Engines with `session.closeTab`, such as web. |
| `observe()` | | Looks again and reports what changed since the last screen the model received. |
| `dismiss_keyboard()` | `keyboard.dismiss` | Hides an on-screen keyboard. Device engines only. |

`upload` takes the model's path, but the runner decides:

- Each path resolves against the project root, as in
  `locator.setInputFiles`.
- A path outside the project (through a symlink too), or one that names a
  hidden file or a file under a hidden directory such as `.env`, `.git`, or
  `.e2e`, is refused with `POLICY_DENIED`.
- A path that names no regular file is `INVALID_ARGUMENT`.
- `sample:photo.png`, `sample:photo.jpg`, `sample:document.pdf`,
  `sample:notes.txt`, `sample:table.csv`, and `sample:empty.txt` name small
  files e2e ships, so the agent can try an upload when the project has no
  file to give it. The tool lists them.
- Every refusal and the final allow is a `policy` event named `upload.path`
  on the step. Nothing reaches the engine until every path passes.

On engines with a keyboard, including the browser and device engines, `type`
and `press` can omit `target` to act on the focused field. `type` then
inserts at the caret; `replace: true` clears first. The browser engine
rejects typing when no editable field has focus, inside shadow roots and
frames too.

When the engine reports text selected inside the focused field, the screen
the model reads lists it as `selection="..."` after the value. The web engine
does for an input, a textarea, and a `contenteditable` editor. A secure field
reports none, and a field whose value or text holds a registered secret has
it dropped, so selected characters of a secret never reach the model.

Mobile engines declare `hover`, `doubleTap`, `longPress`, `check`,
`uncheck`, `dragTo`, and `session.back`. So a device offers `hover`,
`double_tap`, `long_press`, `check`, `drag`, and `back`. They declare no
`secondaryTap`, `selectOption`, `scrollIntoView`, or `setInputFiles`.

A tab the app opens on the web stays in the background until `switch_tab`
shows it. While more than one tab is open, every screen header names the tab
(`tab 1 of 2`). When `close_tab` closes the tab on screen, the screen returns
to the tab that opened it, or to the tab shown most recently when that one
is closed too. Both replay
from the cache by the same tab number. A tab takes its number when its
first page loads, so when one action opens two tabs whose pages load in
another order on a later run, the two numbers swap.

## Pixel tools: screenshot and the point verbs

`act` reads the semantic tree and requests screenshots when it needs them;
the same model reads both. A screen with no listed interactive nodes, such
as a canvas, opens with a screenshot.

The built-in agent offers these tools:

| Tool | What it does |
| --- | --- |
| `screenshot()` | Returns a masked viewport screenshot and includes a fresh screenshot after every later action in the step. |
| `tap_at({ x, y })` | Taps the coordinates. On an engine that cannot, taps the listed control at the point by node id. |
| `hover_at({ x, y })` | Moves the pointer to the coordinates. On an engine that cannot, hovers the listed control at the point by node id. Needs the `hover` action or pointer kind. |
| `drag_at({ x, y, to_x, to_y })` | Drags from one point to the other, for a shape on a canvas or a pin on a map. On an engine that cannot, drags by node id when the points land on two different listed controls. Needs the `dragTo` action or pointer kind. |
| `type_at({ x, y, value, replace? })` | Replaces a listed input's value. For an unlisted input, taps to focus and types at the caret unless `replace` is set. Unlisted inputs require keyboard support. |
| `press_at({ x, y, key })` | Sends a key to the control at the point. If no control is listed, taps to focus and uses the engine's keyboard. |
| `select_at({ x, y, value })` | Selects an option by visible label in the control at the point. |

- Coordinates refer to the latest screenshot. The model must take a
  screenshot before it uses a point tool, and should prefer node ids for
  listed controls.
- `type_at`, `press_at`, and `select_at` check each point against the tree.
  A point on a listed control gets the same policy checks and
  [replay cache](https://e2e.com/docs/cache) recording as an action by id. A `tap_at` or
  `hover_at` point replays inside the node under it.
- `tap_at` needs an engine whose `actions` or `pointerActions` include `tap`,
  `hover_at` one whose include `hover`, and `drag_at` one whose include
  `dragTo`. Without the pointer kind, the point must land on a listed
  control, and the two `drag_at` points on two different listed controls.
  Otherwise the call fails with `UNSUPPORTED_CAPABILITY`.
- A bare-point tap, hover, or drag replays only on a viewport of the recorded
  size, or at the same place inside the listed node that contained it. A
  drag places each of its two points that way.
- Once screenshots are in use, the post-action wait also detects pixel
  changes, including canvas redraws.
- Screenshots have a maximum long side of 768 px.
- A step that sent pixels records `visionInput: true` and
  `metrics.pixelBytes`.

If semantic capture times out, an engine that proves masking independently
can return a fresh screenshot with an unavailable-tree warning, and `act`
continues from it. Trace replay stops, and the step cannot record a new
trace entry, even if the tree recovers later.

## Vision

`assert`, `waitFor`, and `extract` accept `vision`; `act` requests its own
screenshots through the [pixel tools](#pixel-tools-screenshot-and-the-point-verbs).
A screenshot goes to the model that asked for it, so it must accept images:
the judge (or `model`) for a judgment, `model` for `act`.

```ts
await agent.assert('no overlay covers the checkout form', { vision: 'only' }); // default: false
```

| `vision` | Evidence sent to the judge |
| --- | --- |
| `false`, the default | Semantic tree |
| `true` | Semantic tree and a masked screenshot |
| `'only'` | Masked screenshot only, no tree or location |

Use `'only'` for visual checks, such as whether an overlay covers a form or a
chart looks correct. Screenshots show the current viewport, so scroll to the
relevant content first.

The browser engine's semantic tree leaves out the content of a
[frame from another site](https://e2e.com/docs/reference/web#framelocator). To judge that
content, use `true` or `'only'`.

Pixels are withheld, and the tree is sent alone, when:

- the engine masked fewer regions than the secure fields it observed
  (`MASKING_UNPROVEN`), or
- the engine cannot capture pixels (`UNSUPPORTED_CAPABILITY`).

In `'only'` mode those cases fail with `POLICY_DENIED` instead.

With `vision: true` or `'only'`, a recoverable semantic-capture failure can
use a fresh screenshot when the engine proves masking independently. With
`vision: false`, the capture failure stops the judgment before any model
call.

If capture fails before a judgment, the report records zero model calls and
omits `observationRevision` and `explanation`. The step error describes the
capture failure. A malformed answer is a `schema` event on the step and
earns one repair round. When the repaired answer is rejected too, the step
fails with `MODEL_OUTPUT_INVALID`, and its `explanation` is the rejection.

## Types

```ts
export interface Agent {
  act(instruction: string, options?: ActOptions): Promise<ActResult>;
  waitFor(condition: string, options?: WaitForOptions): Promise<void>;
  extract<Schema extends StandardSchemaV1>(
    instruction: string,
    options: ExtractOptions<Schema>,
  ): Promise<StandardSchemaV1.InferOutput<Schema>>;
  assert(assertion: string, options?: AssertOptions): Promise<void>;
}

export interface ActOptions extends AgentOption {
  params?: AgentParams;
  timeout?: number;
  maxSteps?: number;
  maxModelCalls?: number;
  onAction?: ActionHook;
  onBeforeAction?: BeforeActionHook;
}

export type BeforeActionHook = (event: BeforeActionEvent) => void | Promise<void>;

export type ActionHook = (event: ActionEvent) => void | Promise<void>;

export interface AgentOption {
  agent?: string;
}

export interface AssertOptions extends VisionOption, AgentOption {
  explore?: boolean;
  maxSteps?: number;
  maxModelCalls?: number;
  params?: AgentParams;
  timeout?: number;
  screenshot?: boolean;
}

export interface WaitForOptions extends VisionOption, AgentOption {
  params?: AgentParams;
  timeout?: number;
  interval?: number;
  maxModelCalls?: number;
}

export interface ExtractOptions<Schema extends StandardSchemaV1> extends VisionOption, AgentOption {
  schema: Schema;
  timeout?: number;
}

export interface VisionOption {
  vision?: VisionMode;
}

export type VisionMode = boolean | 'only';

export interface ActResult {
  readonly summary: string;
  readonly cache?: StepCacheInfo;
  readonly modelCalls: number;
  readonly actions: number;
}

export type ActionName =
  | 'tap' | 'doubleTap' | 'longPress' | 'secondaryTap' | 'hover' | 'scrollTo'
  | 'type' | 'typeSecret' | 'press' | 'select' | 'check' | 'upload' | 'drag'
  | 'scroll' | 'scrollUntil' | 'navigate' | 'back' | 'resize' | 'typeText'
  | 'pressKey' | 'dismissKeyboard' | 'tapAt' | 'hoverAt' | 'dragAt'
  | 'switchTab' | 'closeTab';

export interface ActionDetails {
  readonly tapAt: { readonly point: Point };
  readonly hoverAt: { readonly point: Point };
  readonly dragAt: { readonly from: Point; readonly to: Point };
}

interface ActionEventBase {
  readonly index: number;
  readonly summary: string;
  readonly source: 'model' | 'replay';
}

export type ActionEvent = ActionEventBase &
  (
    | { readonly action: 'tapAt' | 'hoverAt'; readonly point: Point }
    | { readonly action: 'dragAt'; readonly from: Point; readonly to: Point }
    | { readonly action: Exclude<ActionName, keyof ActionDetails> | `tool:${string}` }
  );

export interface BeforeActionEvent {
  readonly index: number;
  readonly source: 'model' | 'replay';
}

export interface StepCacheInfo {
  mode: 'self-finalized' | 'agent-concluded' | 'missed';
  reason?: TraceReplayMissReason | ReplayHandOffReason;
  derived?: DerivedReason;
  notRecorded?: 'param-collision';
  replayedActions: number;
  totalActions: number;
  entry?: string;
  detail?: string;
  recordedBy?: { readonly provider: string; readonly model: string };
}

type TraceReplayMissReason = 'retry' | 'no-entry' | 'invalid-entry' | 'truncated' | 'wrong-context';
export type ReplayHandOffReason =
  | 'gap'
  | 'target-not-found'
  | 'target-ambiguous'
  | 'viewport-changed'
  | 'action-failed'
  | 'action-uncertain'
  | 'end-mismatch';
export type DerivedReason = 'pixels' | 'whole-node' | 'minted-token' | 'date';

export type AgentParams = Readonly<Record<string, AgentParam>>;

export type AgentParam =
  | JsonPrimitive
  | Secret
  | Unique
  | readonly AgentParam[]
  | { readonly [key: string]: AgentParam };
```

`StepCacheInfo` says how the replay cache took part in one agent step:

| Field | Description |
| --- | --- |
| `mode` | `self-finalized`: the full trace replayed and the step passed with zero model calls. `agent-concluded`: a replayed prefix handed the step to the executor. `missed`: the executor ran the step from the top. |
| `reason` | The miss or hand-off reason, absent on `self-finalized`. Each one is explained under [Why a step was not replayed](https://e2e.com/docs/cache#why-a-step-was-not-replayed). |
| `derived` | On a `gap` at a typed value, the rule that made the value this run's data and not the flow's. Absent for a gap at a project tool. |
| `notRecorded` | Why a passing step that ran live was not recorded. `param-collision`: a `unique()` value equals, is spelled inside, or is the encoded form of another param's value. |
| `entry` | The step's cache key, which names its entry file (`<cache.dir>/<entry>.json` in the file store). |
| `detail` | The recorded action the replay stopped at and what went wrong there, or the screen the recording started on against the one the step did. |
| `recordedBy` | The configured model when the consulted entry was recorded. Absent on older entries. |

`Unique` is what [`unique()`](#unique) returns.

## unique

Marks an `act` param whose value differs on every run. The
[replay cache](https://e2e.com/docs/cache) records a slot instead of the value, and substitutes
this run's value on replay. Mark values the flow types or looks for, not
choices that steer it: two runs whose `unique()` values differ replay the
same recording.

```ts
await agent.act('create a company named {name}', {
  params: { name: unique(`Acme ${Date.now()}`) },
});
```

```ts

export interface Unique {
  readonly value: string;
}

export function unique(value: string): Unique;
```

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | The value is not a string, is empty or only whitespace, or contains the placeholder text `{{param:`. |

## AgentError

Every failure is an `AgentError` with a closed `code`, an `explanation`, an
optional `screenshot` path, and a `blocked` flag. Check it with
`isAgentError(error)` from `e2e`, not `instanceof`. The class and
every code are in [Errors](https://e2e.com/docs/reference/errors#agenterror).
