API Reference
Context Types Type definitions for Context, ItemLog, Item variants, and content parts in Noetic.
The execution context threaded through every step.
interface Context < TMemory = ContextMemory , TState = unknown > {
readonly id : string ;
readonly stepCount : number ;
readonly tokens : TokenUsage ;
readonly elapsed : number ;
readonly cost : number ;
readonly memory : TMemory ;
state : TState ;
readonly parent : Context | null ;
readonly depth : number ;
readonly span : Span ;
readonly threadId : string ;
readonly resourceId ?: string ;
readonly harness : AgentHarness ;
readonly fs : FsAdapter ;
readonly itemLog : ItemLog ;
readonly lastStepMeta : StepMeta | null ;
readonly lastLayerUsage ?: LastLayerUsage ;
recv < T >( channel : Channel < T >, opts ?: { timeout ?: number }) : Promise < T >;
send < T >( channel : Channel < T >, value : T ) : void ;
tryRecv < T >( channel : Channel < T >) : T | null ;
checkpoint () : Promise < void >;
complete < T >( value : T ) : void ;
readonly completed : boolean ;
readonly completionValue : unknown ;
readonly aborted : boolean ;
readonly abortReason ?: string ;
abort ( reason ?: string ) : void ;
}
Field Type Description idstringUnique execution identifier stepCountnumberNumber of steps executed so far tokensTokenUsageAccumulated token usage elapsednumberElapsed time in milliseconds costnumberAccumulated cost in USD memoryTMemoryTyped memory object. Access layer data via ctx.memory['layerId'].prop. Defaults to ContextMemory when no MemoryConfig is provided. stateTStateMutable user state parentContext | nullParent context (for spawned agents) depthnumberNesting depth (0 for root) spanSpanObservability span threadIdstringThread identifier for memory scoping resourceIdstringResource identifier for memory scoping (optional) harnessAgentHarnessReference to the owning agent harness. Access params via ctx.harness.config.params. fsFsAdapterFilesystem adapter delegated from ctx.harness.fs. Use for all filesystem operations inside steps and tools. itemLogItemLogConversation history lastStepMetaStepMeta | nullMetadata from the last executed step lastLayerUsageLastLayerUsage | undefinedPer-memory-layer breakdown of the context window from the most recent callModel. Undefined until the first LLM call completes. completedbooleanWhether complete() has been called completionValueunknownValue passed to complete() abortedbooleanWhether abort() has been called abortReasonstringReason passed to abort() (optional)
Method Signature Description recv<T>(channel, opts?) => Promise<T>Receive from a channel (blocking) send<T>(channel, value) => voidSend to a channel tryRecv<T>(channel) => T | nullNon-blocking receive checkpoint() => Promise<void>Persist current state complete<T>(value) => voidSignal completion with a value abort(reason?) => voidSignal abort
An append-only log of conversation items.
interface ItemLog {
readonly items : ReadonlyArray < Item >;
append ( item : Item ) : void ;
}
Field Type Description itemsReadonlyArray<Item>All items in the log append(item: Item) => voidAppend a new item
The Item type is a discriminated union over the type field:
type Item =
| MessageItem
| FunctionCallItem
| FunctionCallOutputItem
| ReasoningItem
| ExtensionItem ;
All items share this base:
Field Type Description idstringUnique item identifier status'in_progress' | 'completed' | 'incomplete' | 'failed'Item status
Field Type Description type'message'Discriminant role'user' | 'assistant' | 'system' | 'developer'Message author contentContentPart[]Message content parts
Field Type Description type'function_call'Discriminant callIdstringUnique call identifier namestringFunction name argumentsstringJSON-encoded arguments
Field Type Description type'function_call_output'Discriminant callIdstringMatching call identifier outputstringJSON-encoded output
Field Type Description type'reasoning'Discriminant contentContentPart[]Reasoning content summaryContentPart[]Summary of reasoning (optional) encryptedContentstringEncrypted reasoning content (optional)
Field Type Description type`${string}:${string}`Namespaced type using prefix:name convention (e.g., openrouter:web_search, noetic:analytics) dataRecord<string, unknown>Arbitrary structured data
See Items & Events for the complete reference including built-in extended items, streaming events, and the adapter flow.
type ContentPart =
| { type : 'output_text' ; text : string }
| { type : 'input_text' ; text : string }
| { type : 'refusal' ; refusal : string };
Variant Fields Description output_texttext: stringText generated by the model input_texttext: stringText from the user or system refusalrefusal: stringModel refusal message
Field Type Description inputnumberInput tokens consumed outputnumberOutput tokens generated totalnumberTotal tokens
Field Type Description toolCallsFunctionCallItem[]Tool calls made in this step (optional) usage{ inputTokens, outputTokens, cachedTokens? }Token usage (optional) costnumberStep cost in USD (optional) responseItemsReadonlyArray<Item>Items produced by this step (optional)
interface LayerUsageEntry {
readonly layerId : string ;
readonly tokenCount : number ;
readonly items : ReadonlyArray < Item >;
}
Field Type Description layerIdstringThe contributing memory layer's id tokenCountnumberSelf-reported token count from the layer's recall() output itemsReadonlyArray<Item>Items this layer contributed to the context view for the last LLM call
interface LastLayerUsage {
readonly executionId : string ;
readonly modelId : string ;
readonly layers : ReadonlyArray < LayerUsageEntry >;
readonly systemPromptTokens : number ;
readonly toolsTokens : number ;
readonly historyTokens : number ;
readonly totalUsedTokens : number ;
}
Field Type Description executionIdstringThe owning Context.id modelIdstringModel id from the step that triggered the snapshot layersReadonlyArray<LayerUsageEntry>Per-memory-layer contributions, sorted by layerId systemPromptTokensnumberEstimated tokens from step.instructions toolsTokensnumberEstimated tokens from the tool definitions sent to the model historyTokensnumberEstimated tokens for itemLog items not owned by a layer totalUsedTokensnumberSum of all four buckets
LastLayerUsage is captured by the runtime after each successful callModel and surfaced on Context.lastLayerUsage and HarnessResponse.lastLayerUsage. Use it for context-window introspection (e.g., the CLI /context command). The snapshot is overwritten on the next call; export to your observability span if you need historical retention.