Skip to content

Turn

A turn: the agent’s work on a message, from TurnStarted to TurnEnded, and how it ended. AgentSession.turn succeeds with TurnSucceeded or fails with a TurnFailure, a Schema-described tagged error. The TurnEnded event carries the same values in outcome, so a runner can persist and replay them.

Since v0.3.0

The agent’s own failure: model/API error, a failed tool loop, max turns, and so on.

Signature

declare class AgentFailed

Source

Since v0.1.0

Signature

declare class AuthFailed

Source

Since v0.1.0

Signature

declare class ContextExhausted

Source

Since v0.1.0

The caller interrupted the turn.

Signature

declare class Interrupted

Source

Since v0.1.0

The agent process died (signal, OOM killer, crash) rather than ending the turn itself.

Signature

declare class ProcessKilled

Source

Since v0.1.0

The run’s spend cap was reached. estimated when the cost is computed from tokens (Codex).

Signature

declare class SpendCapReached

Source

Since v0.1.0

No events for longer than RunOptions.watchdog allows, so the turn was stopped.

Signature

declare class Stalled

Source

Since v0.1.0

Throttled or overloaded, and the provider gave up retrying. Retries in progress are Retrying events.

Signature

declare class Throttled

Source

Since v0.1.0

Every way a turn can fail: the error of AgentSession.turn, and the failed TurnEnded outcomes.

Signature

declare const TurnFailure: Schema.Union<
readonly [
typeof AgentFailed,
typeof UsageLimited,
typeof Throttled,
typeof AuthFailed,
typeof SpendCapReached,
typeof ContextExhausted,
typeof ProcessKilled,
typeof Stalled,
typeof Interrupted,
]
>

Source

Since v0.1.0

Signature

type TurnFailure = typeof TurnFailure.Type

Source

Since v0.1.0

A subscription usage limit stopped the turn.

Signature

declare class UsageLimited

Source

Since v0.1.0

Signature

declare const TurnId: Schema.brand<Schema.String, "effect-agent/TurnId">

Source

Since v0.1.0

Signature

type TurnId = typeof TurnId.Type

Source

Since v0.1.0

How a turn ended: TurnSucceeded or a TurnFailure.

Signature

declare const TurnOutcome: Schema.Union<
readonly [
Schema.TaggedStruct<
"Succeeded",
{
readonly turnId: Schema.brand<Schema.String, "effect-agent/TurnId">
readonly finalText: Schema.String
}
>,
Schema.Union<
readonly [
typeof AgentFailed,
typeof UsageLimited,
typeof Throttled,
typeof AuthFailed,
typeof SpendCapReached,
typeof ContextExhausted,
typeof ProcessKilled,
typeof Stalled,
typeof Interrupted,
]
>,
]
>

Source

Since v0.1.0

Signature

type TurnOutcome = typeof TurnOutcome.Type

Source

Since v0.1.0

The successful TurnOutcome.

Signature

declare const TurnSucceeded: Schema.TaggedStruct<
"Succeeded",
{
readonly turnId: Schema.brand<Schema.String, "effect-agent/TurnId">
readonly finalText: Schema.String
}
>

Source

Since v0.1.0

Signature

type TurnSucceeded = typeof TurnSucceeded.Type

Source

Since v0.1.0