API Reference

Context Types

Type definitions for Context, ItemLog, Item variants, and content parts in Noetic.

Context

The execution context threaded through every step.

interface Context<TState = unknown> {
  readonly id: string;
  readonly stepCount: number;
  readonly tokens: TokenUsage;
  readonly elapsed: number;
  readonly cost: number;
  state: TState;
  readonly parent: Context | null;
  readonly depth: number;
  readonly span: Span;
  readonly threadId: string;
  readonly resourceId?: string;
  readonly itemLog: ItemLog;
  readonly lastStepMeta: StepMeta | null;
  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;
}
FieldTypeDescription
idstringUnique execution identifier
stepCountnumberNumber of steps executed so far
tokensTokenUsageAccumulated token usage
elapsednumberElapsed time in milliseconds
costnumberAccumulated cost in USD
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)
itemLogItemLogConversation history
lastStepMetaStepMeta | nullMetadata from the last executed step
completedbooleanWhether complete() has been called
completionValueunknownValue passed to complete()
abortedbooleanWhether abort() has been called
abortReasonstringReason passed to abort() (optional)

Context Methods

MethodSignatureDescription
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

ItemLog

An append-only log of conversation items.

interface ItemLog {
  readonly items: ReadonlyArray<Item>;
  append(item: Item): void;
}
FieldTypeDescription
itemsReadonlyArray<Item>All items in the log
append(item: Item) => voidAppend a new item

Item

The Item type is a discriminated union over the type field:

type Item =
  | MessageItem
  | FunctionCallItem
  | FunctionCallOutputItem
  | ReasoningItem
  | ExtensionItem;

ItemBase

All items share this base:

FieldTypeDescription
idstringUnique item identifier
status'in_progress' | 'completed' | 'incomplete' | 'failed'Item status

MessageItem

FieldTypeDescription
type'message'Discriminant
role'user' | 'assistant' | 'system' | 'developer'Message author
contentContentPart[]Message content parts

FunctionCallItem

FieldTypeDescription
type'function_call'Discriminant
call_idstringUnique call identifier
namestringFunction name
argumentsstringJSON-encoded arguments

FunctionCallOutputItem

FieldTypeDescription
type'function_call_output'Discriminant
call_idstringMatching call identifier
outputstringJSON-encoded output

ReasoningItem

FieldTypeDescription
type'reasoning'Discriminant
contentContentPart[]Reasoning content
summaryContentPart[]Summary of reasoning (optional)
encrypted_contentstringEncrypted reasoning content (optional)

ExtensionItem

FieldTypeDescription
type`x-${string}`Custom type prefixed with x-
dataRecord<string, unknown>Arbitrary data

ContentPart

type ContentPart =
  | { type: 'output_text'; text: string }
  | { type: 'input_text'; text: string }
  | { type: 'refusal'; refusal: string };
VariantFieldsDescription
output_texttext: stringText generated by the model
input_texttext: stringText from the user or system
refusalrefusal: stringModel refusal message

TokenUsage

FieldTypeDescription
inputnumberInput tokens consumed
outputnumberOutput tokens generated
totalnumberTotal tokens

StepMeta

FieldTypeDescription
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)

On this page