Skip to content
6 min read · 1,175 words

Interface: TurnContext

The validated, strongly-typed context object threaded through every middleware step in a single agent turn.

Remarks

Constructed from a RawTurnContext by @nhtio/adk!TurnRunner.run. Middleware functions receive this object and use it to read and share state across pipeline steps.

Properties

PropertyModifierTypeDescription
abortreadonly(reason?: unknown) => voidAborts the turn's AbortController with the supplied reason. Middleware should call this when refusing the turn — the runner reads aborted between every stage and short-circuits cleanly: turnEnd still fires, no error event is emitted, and during dispatch dispatchEnd.status === 'aborted' carries the operational signal.
abortedreadonlybooleantrue when the turn's AbortController signal has fired.
abortSignalreadonlyAbortSignalThe AbortSignal from the turn's AbortController.
deleteMemoryreadonly(id: string) => void | Promise<void>Removes a memory from the persistence layer by ID.
deleteMessagereadonly(id: string) => void | Promise<void>Removes a message from the persistence layer by ID.
deleteRetrievablereadonly(id: string) => void | Promise<void>Removes a retrievable record from the persistence layer by ID.
deleteStandingInstructionreadonly(v: string | Tokenizable) => void | Promise<void>Removes a standing instruction from the persistence layer.
deleteThoughtreadonly(id: string) => void | Promise<void>Removes a thought from the persistence layer by ID.
deleteToolCallreadonly(id: string) => void | Promise<void>Removes a tool call from the persistence layer by ID.
emitMessagereadonlyEmitMessageFnEmits a message event on the runner; may be called at any point during the turn.
emitThoughtreadonlyEmitThoughtFnEmits a thought event on the runner; may be called at any point during the turn.
emitToolCallreadonlyEmitToolCallFnEmits a toolCall event on the runner; may be called at any point during the turn.
emitToolExecutionEndreadonlyEmitToolExecutionEndFnEmits a toolExecutionEnd event on the observability bus; forwarded from DispatchContext by DispatchRunner when a tool finishes executing inside a dispatch.
emitToolExecutionStartreadonlyEmitToolExecutionStartFnEmits a toolExecutionStart event on the observability bus; forwarded from DispatchContext by DispatchRunner when a tool is invoked inside a dispatch.
fetchMemoriesreadonly() => | Memory[] | Promise<Memory[]>Fetches memories relevant to this turn; delegates to the callback supplied at construction.
fetchMessagesreadonly() => | Message[] | Promise<Message[]>Fetches conversation messages relevant to this turn; delegates to the callback supplied at construction.
fetchRetrievablesreadonly() => | Retrievable[] | Promise<Retrievable[]>Fetches retrievable records relevant to this turn; delegates to the callback supplied at construction.
fetchThoughtsreadonly() => | Thought[] | Promise<Thought[]>Fetches thought traces relevant to this turn; delegates to the callback supplied at construction.
fetchToolCallsreadonly() => | ToolCall[] | Promise<ToolCall[]>Fetches tool call records relevant to this turn; delegates to the callback supplied at construction.
fetchToolsreadonly() => | Tool<SpooledArtifact>[] | Promise<Tool<SpooledArtifact>[]>Fetches tools available for this turn; delegates to the callback supplied at construction.
idreadonlystringUnique identifier for this turn, generated as a UUIDv6 at construction time.
mutateMemoryreadonly(v: Memory) => void | Promise<void>Updates an existing memory in the persistence layer.
mutateMessagereadonly(v: Message) => void | Promise<void>Updates an existing message in the persistence layer.
mutateRetrievablereadonly(v: Retrievable) => void | Promise<void>Updates an existing retrievable record in the persistence layer.
mutateStandingInstructionreadonly(v: string | Tokenizable) => void | Promise<void>Updates an existing standing instruction in the persistence layer.
mutateThoughtreadonly(v: Thought) => void | Promise<void>Updates an existing thought in the persistence layer.
mutateToolCallreadonly(v: ToolCall) => void | Promise<void>Updates an existing tool call in the persistence layer.
refreshStandingInstructionsreadonly() => | (string | Tokenizable)[] | Promise<(string | Tokenizable)[]>Refreshes and returns the standing instructions; delegates to the callback supplied at construction.
standingInstructionsreadonlySet<Tokenizable>Standing instructions applied to every turn, in insertion order.
stashreadonlyRegistryArbitrary key-value store that middleware can read and write across pipeline steps.
storeMemoryreadonly(v: Memory) => void | Promise<void>Stores a new memory in the persistence layer.
storeMessagereadonly(v: Message) => void | Promise<void>Stores a new message in the persistence layer.
storeRetrievablereadonly(v: Retrievable) => void | Promise<void>Stores a new retrievable record in the persistence layer.
storeStandingInstructionreadonly(v: string | Tokenizable) => void | Promise<void>Stores a new standing instruction in the persistence layer.
storeThoughtreadonly(v: Thought) => void | Promise<void>Stores a new thought in the persistence layer.
storeToolCallreadonly(v: ToolCall) => void | Promise<void>Stores a new tool call in the persistence layer.
systemPromptreadonlyTokenizableThe system prompt guiding the agent's behaviour for this turn.
toolsreadonlyToolRegistryTurn-scoped tool registry constructed from the runner's baseline tools; middleware may trim or extend it.
turnMemoriesreadonlySet<Memory>Memories loaded for this turn; populated by middleware after calling fetchMemories().
turnMessagesreadonlySet<Message>Conversation messages loaded for this turn; populated by middleware after calling fetchMessages().
turnRetrievablesreadonlySet<Retrievable>Retrievable records loaded for this turn; populated by middleware after calling fetchRetrievables().
turnThoughtsreadonlySet<Thought>Thought traces loaded for this turn; populated by middleware after calling fetchThoughts().
turnToolCallsreadonlySet<ToolCall>Tool call records loaded for this turn; populated by middleware after calling fetchToolCalls().
waitForreadonlyOpenGateFnOpens a turn gate and suspends until it resolves, rejects, times out, or is aborted.