# StageContext
Source: https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/stagecontext/
Documentation revision: 89a8f5e9d10cedcf0b30376d7846113f06f26120
SDK manifests in this build: @maelstrom-co/react@0.2.1, @maelstrom-co/client@0.2.1, @maelstrom-co/connectors@0.2.1, @maelstrom-co/protocol@0.2.1, @maelstrom-co/engine@0.2.1
These docs follow this source revision. Manifest versions do not prove release compatibility; verify the installed package exports before using an API.

Defined in: [packages/engine/src/lib/planner/stage.ts:77](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/planner/stage.ts#L77)

Request-scoped services the Engine gives every stage of a [Planner](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/planner/).

## Properties

### enumSnapshot?

> `readonly` `optional` **enumSnapshot?**: [`ActionParameterEnumSnapshot`](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/actionparameterenumsnapshot/)

Defined in: [packages/engine/src/lib/planner/stage.ts:106](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/planner/stage.ts#L106)

The Action parameter enum values [StageContext.validate](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/stagecontext/#validate) checks actions against, captured once from the Vessel catalog in [StageContext.origin](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/stagecontext/#origin). A stage that renders enum values for that same catalog (for example into a prompt) should read them from here, so it shows exactly the literals validation accepts even for values whose serialization is not stable across calls. The Engine always sets it; combinators that derive a context must forward it unchanged.

* * *

### instrument

> `readonly` **instrument**: [`Instrument`](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/instrument/)

Defined in: [packages/engine/src/lib/planner/stage.ts:92](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/planner/stage.ts#L92)

The Engine’s telemetry seam. [pipeline](https://docs.maelstrom-ai.co/dev/reference/engine/functions/pipeline/) wraps every stage with it; a stage reports what happens inside it (for example a model call) with `instrument.event`. The Engine always sets it, to a no-op when none is configured; combinators that derive a context must forward it unchanged.

* * *

### logger

> `readonly` **logger**: [`Logger`](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/logger/)

Defined in: [packages/engine/src/lib/planner/stage.ts:85](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/planner/stage.ts#L85)

The Engine’s logger. Log through it so stage logs share the Engine’s sink and redaction.

* * *

### origin

> `readonly` **origin**: [`PlanningInput`](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/planninginput/)

Defined in: [packages/engine/src/lib/planner/stage.ts:94](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/planner/stage.ts#L94)

The untouched input the Engine passed to the first stage.

* * *

### signal?

> `readonly` `optional` **signal?**: `AbortSignal`

Defined in: [packages/engine/src/lib/planner/stage.ts:83](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/planner/stage.ts#L83)

Cancels in-flight work for the request. Every stage must honour it so that cancelled requests, and later concurrent combinators, stop spending on work nobody will use.

* * *

### validate

> `readonly` **validate**: {(`candidate`): `Result`<[`ValidatedCandidate`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/validatedcandidate/), [`EngineError`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/engineerror/)\>; (`candidate`): `Result`<[`ValidatedReplylessCandidate`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/validatedreplylesscandidate/), [`EngineError`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/engineerror/)\>; }

Defined in: [packages/engine/src/lib/planner/stage.ts:96](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/engine/src/lib/planner/stage.ts#L96)

Heals and validates a candidate against the request in [StageContext.origin](https://docs.maelstrom-ai.co/dev/reference/engine/interfaces/stagecontext/#origin).

#### Call Signature

> (`candidate`): `Result`<[`ValidatedCandidate`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/validatedcandidate/), [`EngineError`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/engineerror/)\>

##### Parameters

###### candidate

[`PlannerCandidate`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/plannercandidate/)

##### Returns

`Result`<[`ValidatedCandidate`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/validatedcandidate/), [`EngineError`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/engineerror/)\>

#### Call Signature

> (`candidate`): `Result`<[`ValidatedReplylessCandidate`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/validatedreplylesscandidate/), [`EngineError`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/engineerror/)\>

##### Parameters

###### candidate

[`ReplylessCandidate`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/replylesscandidate/)

##### Returns

`Result`<[`ValidatedReplylessCandidate`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/validatedreplylesscandidate/), [`EngineError`](https://docs.maelstrom-ai.co/dev/reference/engine/type-aliases/engineerror/)\>
