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
| Property | Modifier | Type | Description |
|---|---|---|---|
abort | readonly | (reason?: unknown) => void | Aborts 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. |
aborted | readonly | boolean | true when the turn's AbortController signal has fired. |
abortSignal | readonly | AbortSignal | The AbortSignal from the turn's AbortController. |
deleteMemory | readonly | (id: string) => void | Promise<void> | Removes a memory from the persistence layer by ID. |
deleteMessage | readonly | (id: string) => void | Promise<void> | Removes a message from the persistence layer by ID. |
deleteRetrievable | readonly | (id: string) => void | Promise<void> | Removes a retrievable record from the persistence layer by ID. |
deleteStandingInstruction | readonly | (v: string | Tokenizable) => void | Promise<void> | Removes a standing instruction from the persistence layer. |
deleteThought | readonly | (id: string) => void | Promise<void> | Removes a thought from the persistence layer by ID. |
deleteToolCall | readonly | (id: string) => void | Promise<void> | Removes a tool call from the persistence layer by ID. |
emitMessage | readonly | EmitMessageFn | Emits a message event on the runner; may be called at any point during the turn. |
emitThought | readonly | EmitThoughtFn | Emits a thought event on the runner; may be called at any point during the turn. |
emitToolCall | readonly | EmitToolCallFn | Emits a toolCall event on the runner; may be called at any point during the turn. |
emitToolExecutionEnd | readonly | EmitToolExecutionEndFn | Emits a toolExecutionEnd event on the observability bus; forwarded from DispatchContext by DispatchRunner when a tool finishes executing inside a dispatch. |
emitToolExecutionStart | readonly | EmitToolExecutionStartFn | Emits a toolExecutionStart event on the observability bus; forwarded from DispatchContext by DispatchRunner when a tool is invoked inside a dispatch. |
fetchMemories | readonly | () => | Memory[] | Promise<Memory[]> | Fetches memories relevant to this turn; delegates to the callback supplied at construction. |
fetchMessages | readonly | () => | Message[] | Promise<Message[]> | Fetches conversation messages relevant to this turn; delegates to the callback supplied at construction. |
fetchRetrievables | readonly | () => | Retrievable[] | Promise<Retrievable[]> | Fetches retrievable records relevant to this turn; delegates to the callback supplied at construction. |
fetchThoughts | readonly | () => | Thought[] | Promise<Thought[]> | Fetches thought traces relevant to this turn; delegates to the callback supplied at construction. |
fetchToolCalls | readonly | () => | ToolCall[] | Promise<ToolCall[]> | Fetches tool call records relevant to this turn; delegates to the callback supplied at construction. |
fetchTools | readonly | () => | Tool<SpooledArtifact>[] | Promise<Tool<SpooledArtifact>[]> | Fetches tools available for this turn; delegates to the callback supplied at construction. |
id | readonly | string | Unique identifier for this turn, generated as a UUIDv6 at construction time. |
mutateMemory | readonly | (v: Memory) => void | Promise<void> | Updates an existing memory in the persistence layer. |
mutateMessage | readonly | (v: Message) => void | Promise<void> | Updates an existing message in the persistence layer. |
mutateRetrievable | readonly | (v: Retrievable) => void | Promise<void> | Updates an existing retrievable record in the persistence layer. |
mutateStandingInstruction | readonly | (v: string | Tokenizable) => void | Promise<void> | Updates an existing standing instruction in the persistence layer. |
mutateThought | readonly | (v: Thought) => void | Promise<void> | Updates an existing thought in the persistence layer. |
mutateToolCall | readonly | (v: ToolCall) => void | Promise<void> | Updates an existing tool call in the persistence layer. |
refreshStandingInstructions | readonly | () => | (string | Tokenizable)[] | Promise<(string | Tokenizable)[]> | Refreshes and returns the standing instructions; delegates to the callback supplied at construction. |
standingInstructions | readonly | Set<Tokenizable> | Standing instructions applied to every turn, in insertion order. |
stash | readonly | Registry | Arbitrary key-value store that middleware can read and write across pipeline steps. |
storeMemory | readonly | (v: Memory) => void | Promise<void> | Stores a new memory in the persistence layer. |
storeMessage | readonly | (v: Message) => void | Promise<void> | Stores a new message in the persistence layer. |
storeRetrievable | readonly | (v: Retrievable) => void | Promise<void> | Stores a new retrievable record in the persistence layer. |
storeStandingInstruction | readonly | (v: string | Tokenizable) => void | Promise<void> | Stores a new standing instruction in the persistence layer. |
storeThought | readonly | (v: Thought) => void | Promise<void> | Stores a new thought in the persistence layer. |
storeToolCall | readonly | (v: ToolCall) => void | Promise<void> | Stores a new tool call in the persistence layer. |
systemPrompt | readonly | Tokenizable | The system prompt guiding the agent's behaviour for this turn. |
tools | readonly | ToolRegistry | Turn-scoped tool registry constructed from the runner's baseline tools; middleware may trim or extend it. |
turnMemories | readonly | Set<Memory> | Memories loaded for this turn; populated by middleware after calling fetchMemories(). |
turnMessages | readonly | Set<Message> | Conversation messages loaded for this turn; populated by middleware after calling fetchMessages(). |
turnRetrievables | readonly | Set<Retrievable> | Retrievable records loaded for this turn; populated by middleware after calling fetchRetrievables(). |
turnThoughts | readonly | Set<Thought> | Thought traces loaded for this turn; populated by middleware after calling fetchThoughts(). |
turnToolCalls | readonly | Set<ToolCall> | Tool call records loaded for this turn; populated by middleware after calling fetchToolCalls(). |
waitFor | readonly | OpenGateFn | Opens a turn gate and suspends until it resolves, rejects, times out, or is aborted. |