TurnContext
Context available during the turn hook.
Extends SessionContext with turn-specific data: input messages,
output, turn ID, and the abort() method for hard-stopping.
Extends
Section titled “Extends”Extended by
Section titled “Extended by”Properties
Section titled “Properties”agent:
object
Agent definition: name, model, instructions.
instructions
Section titled “instructions”instructions:
string
model:
string
name:
string
Inherited from
Section titled “Inherited from”config
Section titled “config”config:
Record<string,unknown>
Middleware-specific configuration from the agent definition.
Inherited from
Section titled “Inherited from”history
Section titled “history”history:
Message[]
Canonical conversation history (append-only).
Inherited from
Section titled “Inherited from”input:
Message[]
Input messages for this turn.
output
Section titled “output”output:
string|null
Assistant’s final text output for this turn. null until the turn completes.
sessionId
Section titled “sessionId”sessionId:
string
Unique session identifier.
Inherited from
Section titled “Inherited from”startedAt
Section titled “startedAt”startedAt:
number
Timestamp when this turn started.
state:
Record<string,unknown>
Session state — typed fields with optional reducers, shared across all turns.
Inherited from
Section titled “Inherited from”turnId
Section titled “turnId”turnId:
string
Unique turn identifier.
turnIndex
Section titled “turnIndex”turnIndex:
number
Turn number within this session (0-based).
Methods
Section titled “Methods”abort()
Section titled “abort()”abort(
reason):never
Hard-stop the turn. Throws AbortError that unwinds the entire onion stack.
Parameters
Section titled “Parameters”reason
Section titled “reason”string
Returns
Section titled “Returns”never
Throws
Section titled “Throws”emit()
Section titled “emit()”emit(
event):void
Emit a stream event to the consumer.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”registerTool()
Section titled “registerTool()”registerTool(
tool):void
Register a tool on the agent. Call in the agent hook before next().
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void