Skip to content
7 min read · 1,395 words

Interface: TurnContext ​

Defined in: src/lib/contracts/turn_runner_context.ts:340

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 ​

PropertyModifierTypeDescriptionDefined in
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.src/lib/contracts/turn_runner_context.ts:777
abortedreadonlybooleantrue when the turn's AbortController signal has fired.src/lib/contracts/turn_runner_context.ts:768
abortSignalreadonlyAbortSignalThe AbortSignal from the turn's AbortController.src/lib/contracts/turn_runner_context.ts:770
deleteMemoryreadonly(id: string) => void | Promise<void>Removes a memory from the persistence layer by ID.src/lib/contracts/turn_runner_context.ts:819
deleteMessagereadonly(id: string) => void | Promise<void>Removes a message from the persistence layer by ID.src/lib/contracts/turn_runner_context.ts:833
deleteRetrievablereadonly(id: string) => void | Promise<void>Removes a retrievable record from the persistence layer by ID.src/lib/contracts/turn_runner_context.ts:827
deleteStandingInstructionreadonly(v: string | Tokenizable) => void | Promise<void>Removes a standing instruction from the persistence layer.src/lib/contracts/turn_runner_context.ts:813
deleteThoughtreadonly(id: string) => void | Promise<void>Removes a thought from the persistence layer by ID.src/lib/contracts/turn_runner_context.ts:839
deleteToolCallreadonly(id: string) => void | Promise<void>Removes a tool call from the persistence layer by ID.src/lib/contracts/turn_runner_context.ts:845
emitMessagereadonlyEmitMessageFnEmits a message event on the runner; may be called at any point during the turn.src/lib/contracts/turn_runner_context.ts:870
emitThoughtreadonlyEmitThoughtFnEmits a thought event on the runner; may be called at any point during the turn.src/lib/contracts/turn_runner_context.ts:872
emitToolCallreadonlyEmitToolCallFnEmits a toolCall event on the runner; may be called at any point during the turn.src/lib/contracts/turn_runner_context.ts:874
emitToolExecutionEndreadonlyEmitToolExecutionEndFnEmits a toolExecutionEnd event on the observability bus; forwarded from DispatchContext by DispatchRunner when a tool finishes executing inside a dispatch.src/lib/contracts/turn_runner_context.ts:878
emitToolExecutionStartreadonlyEmitToolExecutionStartFnEmits a toolExecutionStart event on the observability bus; forwarded from DispatchContext by DispatchRunner when a tool is invoked inside a dispatch.src/lib/contracts/turn_runner_context.ts:876
fetchMemoriesreadonly() => | Memory[] | Promise<Memory[]>Fetches memories relevant to this turn; delegates to the callback supplied at construction.src/lib/contracts/turn_runner_context.ts:795
fetchMessagesreadonly() => | Message[] | Promise<Message[]>Fetches conversation messages relevant to this turn; delegates to the callback supplied at construction.src/lib/contracts/turn_runner_context.ts:797
fetchRetrievablesreadonly() => | Retrievable[] | Promise<Retrievable[]>Fetches retrievable records relevant to this turn; delegates to the callback supplied at construction.src/lib/contracts/turn_runner_context.ts:821
fetchThoughtsreadonly() => | Thought[] | Promise<Thought[]>Fetches thought traces relevant to this turn; delegates to the callback supplied at construction.src/lib/contracts/turn_runner_context.ts:799
fetchToolCallsreadonly() => | ToolCall[] | Promise<ToolCall[]>Fetches tool call records relevant to this turn; delegates to the callback supplied at construction.src/lib/contracts/turn_runner_context.ts:801
fetchToolsreadonly() => | Tool<SpooledArtifact>[] | Promise<Tool<SpooledArtifact>[]>Fetches tools available for this turn; delegates to the callback supplied at construction.src/lib/contracts/turn_runner_context.ts:803
idreadonlystringUnique identifier for this turn, generated as a UUIDv6 at construction time.src/lib/contracts/turn_runner_context.ts:766
mutateMemoryreadonly(v: Memory) => void | Promise<void>Updates an existing memory in the persistence layer.src/lib/contracts/turn_runner_context.ts:817
mutateMessagereadonly(v: Message) => void | Promise<void>Updates an existing message in the persistence layer.src/lib/contracts/turn_runner_context.ts:831
mutateRetrievablereadonly(v: Retrievable) => Promise<Retrievable>Updates an existing retrievable record in the persistence layer.src/lib/contracts/turn_runner_context.ts:825
mutateStandingInstructionreadonly(v: string | Tokenizable) => void | Promise<void>Updates an existing standing instruction in the persistence layer.src/lib/contracts/turn_runner_context.ts:811
mutateThoughtreadonly(v: Thought) => void | Promise<void>Updates an existing thought in the persistence layer.src/lib/contracts/turn_runner_context.ts:837
mutateToolCallreadonly(v: ToolCall) => void | Promise<void>Updates an existing tool call in the persistence layer.src/lib/contracts/turn_runner_context.ts:843
refreshStandingInstructionsreadonly() => | (string | Tokenizable)[] | Promise<(string | Tokenizable)[]>Refreshes and returns the standing instructions; delegates to the callback supplied at construction.src/lib/contracts/turn_runner_context.ts:805
replaceToolCallGroupreadonly(ids: readonly string[], replacements: readonly ToolCall[]) => Promise<void>Replaces a complete colliding tool-call group when storage supports it.src/lib/contracts/turn_runner_context.ts:847
standingInstructionsreadonlySet<Tokenizable>Standing instructions applied to every turn, in insertion order.src/lib/contracts/turn_runner_context.ts:783
stashreadonlyRegistryArbitrary key-value store that middleware can read and write across pipeline steps.src/lib/contracts/turn_runner_context.ts:779
storeMediaBytesreadonly(id: string, bytes: ConduitBytes) => | MediaReader | Promise<MediaReader>Persists tool-generated media bytes into consumer storage and returns a @nhtio/adk!MediaReader. Low-level conduit — returns a value, touches no turn state; build a @nhtio/adk!Media from the reader and persist the owning primitive separately.src/lib/contracts/turn_runner_context.ts:856
storeMemoryreadonly(v: Memory) => void | Promise<void>Stores a new memory in the persistence layer.src/lib/contracts/turn_runner_context.ts:815
storeMessagereadonly(v: Message) => void | Promise<void>Stores a new message in the persistence layer.src/lib/contracts/turn_runner_context.ts:829
storeRetrievablereadonly(v: Retrievable) => Promise<Retrievable>Stores a new retrievable record in the persistence layer.src/lib/contracts/turn_runner_context.ts:823
storeRetrievableBytesreadonly(id: string, bytes: ConduitBytes) => | SpoolReader | Promise<SpoolReader>Persists extracted retrievable text bytes into consumer storage and returns a @nhtio/adk!SpoolReader. Wrap it in a @nhtio/adk!SpooledArtifact for Retrievable.content and persist the record via TurnContext.storeRetrievable separately.src/lib/contracts/turn_runner_context.ts:865
storeStandingInstructionreadonly(v: string | Tokenizable) => void | Promise<void>Stores a new standing instruction in the persistence layer.src/lib/contracts/turn_runner_context.ts:809
storeThoughtreadonly(v: Thought) => void | Promise<void>Stores a new thought in the persistence layer.src/lib/contracts/turn_runner_context.ts:835
storeToolCallreadonly(v: ToolCall) => void | Promise<void>Stores a new tool call in the persistence layer.src/lib/contracts/turn_runner_context.ts:841
systemPromptreadonlyTokenizableThe system prompt guiding the agent's behaviour for this turn.src/lib/contracts/turn_runner_context.ts:781
toolsreadonlyToolRegistryTurn-scoped tool registry constructed from the runner's baseline tools; middleware may trim or extend it.src/lib/contracts/turn_runner_context.ts:882
turnMemoriesreadonlySet<Memory>Memories loaded for this turn; populated by middleware after calling fetchMemories().src/lib/contracts/turn_runner_context.ts:785
turnMessagesreadonlySet<Message>Conversation messages loaded for this turn; populated by middleware after calling fetchMessages().src/lib/contracts/turn_runner_context.ts:789
turnRetrievablesreadonlySet<Retrievable>Retrievable records loaded for this turn; populated by middleware after calling fetchRetrievables().src/lib/contracts/turn_runner_context.ts:787
turnThoughtsreadonlySet<Thought>Thought traces loaded for this turn; populated by middleware after calling fetchThoughts().src/lib/contracts/turn_runner_context.ts:791
turnToolCallsreadonlySet<ToolCall>Tool call records loaded for this turn; populated by middleware after calling fetchToolCalls().src/lib/contracts/turn_runner_context.ts:793
waitForreadonlyOpenGateFnOpens a turn gate and suspends until it resolves, rejects, times out, or is aborted.src/lib/contracts/turn_runner_context.ts:880